Преглед на файлове

将 UploadChannel 中的 processFile 字段名字修改为 seturl, 表示通过该 channel 上传文件的返回值中是否包含已上传文件的 url

reghao преди 2 години
родител
ревизия
b5dc1cd5a7

+ 3 - 3
oss-console/src/main/java/cn/reghao/oss/console/app/controller/page/UploadChannelController.java

@@ -42,10 +42,10 @@ public class UploadChannelController {
         return WebResult.success();
     }
 
-    @ApiOperation(value = "修改通道是否处理上传文件")
-    @PostMapping(value = "/update/processfile", produces = MediaType.APPLICATION_JSON_VALUE)
+    @ApiOperation(value = "修改通道是否返回 url")
+    @PostMapping(value = "/update/seturl", produces = MediaType.APPLICATION_JSON_VALUE)
     public String updateChannelProcess(@Validated ChannelProcessDto channelProcessDto) {
-        uploadChannelService.updateProcessFile(channelProcessDto);
+        uploadChannelService.updateSeturl(channelProcessDto);
         return WebResult.success();
     }
 }

+ 1 - 1
oss-console/src/main/java/cn/reghao/oss/console/app/model/dto/ChannelProcessDto.java

@@ -17,5 +17,5 @@ public class ChannelProcessDto {
     @NotNull
     private Integer id;
     @NotNull
-    private Boolean processFile;
+    private Boolean seturl;
 }

+ 2 - 2
oss-console/src/main/java/cn/reghao/oss/console/app/model/po/UploadChannel.java

@@ -24,7 +24,7 @@ public class UploadChannel extends BaseEntity {
     private String prefix;
     private Long maxSize;
     private Integer fileType;
-    private Boolean processFile;
+    private Boolean seturl;
     private Integer scope;
     private Integer nodeId;
     private Integer createBy;
@@ -35,7 +35,7 @@ public class UploadChannel extends BaseEntity {
         this.prefix = uploadChannelDto.getChannelPrefix();
         this.maxSize = uploadChannelDto.getMaxSize();
         this.fileType = uploadChannelDto.getFileType();
-        this.processFile = false;
+        this.seturl = false;
         this.scope = uploadChannelDto.getScope();
         this.nodeId = uploadChannelDto.getNodeId();
         this.createBy = createBy;

+ 2 - 2
oss-console/src/main/java/cn/reghao/oss/console/app/model/vo/UploadChannelVo.java

@@ -17,7 +17,7 @@ public class UploadChannelVo {
     private String prefix;
     private String maxSize;
     private String fileType;
-    private boolean processFile;
+    private boolean seturl;
     private String scope;
     private String bindDomain;
 
@@ -28,7 +28,7 @@ public class UploadChannelVo {
         this.prefix = uploadChannel.getPrefix();
         this.maxSize = maxSize;
         this.fileType = ObjectType.getDescByCode(uploadChannel.getFileType());
-        this.processFile = uploadChannel.getProcessFile();
+        this.seturl = uploadChannel.getSeturl();
         this.scope = ObjectScope.getByCode(uploadChannel.getScope()).name();
         this.bindDomain = bindDomain;
     }

+ 9 - 9
oss-console/src/main/java/cn/reghao/oss/console/app/service/UploadChannelService.java

@@ -68,9 +68,9 @@ public class UploadChannelService {
         String name = uploadChannel.getName();
         long maxSize = uploadChannel.getMaxSize();
         int fileType = uploadChannel.getFileType();
-        boolean processFile = uploadChannel.getProcessFile();
+        boolean seturl = uploadChannel.getSeturl();
         int scope = uploadChannel.getScope();
-        ObjectChannel channel = new ObjectChannel(channelId, name, channelPrefix, maxSize, fileType, processFile, scope, domain, createBy);
+        ObjectChannel channel = new ObjectChannel(channelId, name, channelPrefix, maxSize, fileType, seturl, scope, domain, createBy);
 
         String host = storeNode.getNodeAddr();
         int port = storeNode.getRpcPort();
@@ -99,14 +99,14 @@ public class UploadChannelService {
         }
     }
 
-    public void updateProcessFile(ChannelProcessDto channelProcessDto) {
+    public void updateSeturl(ChannelProcessDto channelProcessDto) {
         int id = channelProcessDto.getId();
         UploadChannel uploadChannel = uploadChannelRepository.findById(id).orElse(null);
         if (uploadChannel != null) {
-            boolean processFile = channelProcessDto.getProcessFile();
-            boolean current = uploadChannel.getProcessFile();
-            if (processFile != current) {
-                uploadChannel.setProcessFile(processFile);
+            boolean seturl = channelProcessDto.getSeturl();
+            boolean current = uploadChannel.getSeturl();
+            if (seturl != current) {
+                uploadChannel.setSeturl(seturl);
                 uploadChannelRepository.save(uploadChannel);
 
             }
@@ -151,11 +151,11 @@ public class UploadChannelService {
         String channelPrefix = uploadChannel.getPrefix();
         long maxSize = uploadChannel.getMaxSize();
         int fileType = uploadChannel.getFileType();
-        boolean processFile = uploadChannel.getProcessFile();
+        boolean seturl = uploadChannel.getSeturl();
         int scope = uploadChannel.getScope();
         String domain = storeNodeService.getById(uploadChannel.getNodeId()).getDomain();
         int createBy = uploadChannel.getCreateBy();
-        return new ObjectChannel(channelId, name, channelPrefix, maxSize, fileType, processFile, scope, domain, createBy);
+        return new ObjectChannel(channelId, name, channelPrefix, maxSize, fileType, seturl, scope, domain, createBy);
     }
 
     public StoreNode getStoreNodeByChannelId(int channelId) throws Exception {

+ 2 - 2
oss-console/src/main/resources/templates/channel/edit1.html

@@ -4,7 +4,7 @@
 
 <body>
 <div class="layui-form timo-compile">
-    <form th:action="@{/api/store/channel/update/processfile}">
+    <form th:action="@{/api/store/channel/update/seturl}">
         <input class="layui-input" type="hidden" name="id" th:value="${id}" readonly>
         <table class="layui-table timo-detail-table">
             <tbody>
@@ -15,7 +15,7 @@
                 <td>
                     <div class="layui-form-item">
                         <div class="layui-input-inline">
-                            <select name="processFile">
+                            <select name="seturl">
                                 <option th:each="item : ${list}" th:value="${item.key}">[[${item.value}]]</option>
                             </select>
                         </div>

+ 2 - 2
oss-console/src/main/resources/templates/channel/index.html

@@ -42,7 +42,7 @@
                     <th class="sortable" data-field="appId">前缀</th>
                     <th class="sortable" data-field="repoBranch">最大文件</th>
                     <th class="sortable" data-field="repoBranch">文件类型</th>
-                    <th class="sortable" data-field="repoBranch">处理文件</th>
+                    <th class="sortable" data-field="repoBranch">是否返回 URL</th>
                     <th class="sortable" data-field="repoBranch">可见范围</th>
                     <th class="sortable" data-field="appName">绑定域名</th>
                     <th>操作</th>
@@ -55,7 +55,7 @@
                     <td th:text="${item.prefix}">前缀</td>
                     <td th:text="${item.maxSize}">最大文件</td>
                     <td th:text="${item.fileType}">文件类型</td>
-                    <td th:text="${item.processFile}">文件类型</td>
+                    <td th:text="${item.seturl}">文件类型</td>
                     <td>
                         <a class="open-popup" data-title="修改 channel 可见范围" th:attr="data-url=@{'/store/channel/edit/'+${item.id}}"
                            data-size="640,480" href="#" th:text="${item.scope}"></a>

+ 7 - 1
oss-store/src/main/java/cn/reghao/oss/store/controller/ObjectUploadController.java

@@ -111,7 +111,13 @@ public class ObjectUploadController {
         ObjectResult objectResult = putObjectService.putObject(objectProp, contentId, savedFile, filename, sha256sum1);
         String objectId = objectResult.getObjectId();
         String objectUrl = objectNameService.getObjectUrl(objectResult.getObjectName());
-        UploadFileRet uploadFileRet = new UploadFileRet(objectId, objectUrl);
+        UploadFileRet uploadFileRet;
+        if (objectChannel.getSeturl()) {
+            uploadFileRet = new UploadFileRet(objectId, objectUrl);
+        } else {
+            uploadFileRet = new UploadFileRet(objectId);
+        }
+
         return ResponseEntity.status(HttpStatus.OK).body(WebResult.success(uploadFileRet));
     }
 

+ 1 - 17
oss-store/src/main/java/cn/reghao/oss/store/db/repository/ImageRepository.java

@@ -76,22 +76,6 @@ public class ImageRepository {
     }
 
     public ImageUrlDto getImageUrl(String imageFileId) {
-        List<ImageFile> list = imageFileMapper.findByImageFileId(imageFileId);
-        if (list.isEmpty()) {
-            return null;
-        }
-
-        ImageUrlDto imageUrlDto = new ImageUrlDto(imageFileId);
-        ImageFile original = list.get(0);
-        imageUrlDto.setOriginalUrl(original.getUrl());
-
-        ObjectChannel objectChannel = storeChannelService.getChannelByUrl(1, original.getUrl());
-        if (objectChannel != null && objectChannel.getProcessFile()) {
-            imageUrlDto.setThumbnailUrl(list.get(1).getUrl());
-        } else {
-            imageUrlDto.setThumbnailUrl(original.getUrl());
-        }
-
-        return imageUrlDto;
+        return null;
     }
 }

+ 0 - 53
oss-store/src/main/java/cn/reghao/oss/store/task/FileProcessor.java

@@ -17,58 +17,5 @@ import org.springframework.stereotype.Service;
  * @date 2023-05-22 18:11:03
  */
 @Slf4j
-@Service
 public class FileProcessor {
-    private final ImageFileProcessor imageFileProcessor;
-    private final VideoFileProcessor videoFileProcessor;
-    private final AudioFileProcessor audioFileProcessor;
-    private final DiskFileProcessor diskFileProcessor;
-    private final ImageRepository imageRepository;
-
-    public FileProcessor(ImageFileProcessor imageFileProcessor, VideoFileProcessor videoFileProcessor,
-                         AudioFileProcessor audioFileProcessor, DiskFileProcessor diskFileProcessor,
-                         ImageRepository imageRepository) {
-        this.imageFileProcessor = imageFileProcessor;
-        this.videoFileProcessor = videoFileProcessor;
-        this.audioFileProcessor = audioFileProcessor;
-        this.diskFileProcessor = diskFileProcessor;
-        this.imageRepository = imageRepository;
-    }
-
-    public UploadFileRet process(ObjectResult objectResult, ObjectChannel channel) throws Exception {
-        String objectName = objectResult.getObjectName();
-        UploadFileRet uploadFileRet = null;
-        int fileType = channel.getFileType();
-        int channelId = channel.getChannelId();
-        boolean processFile = channel.getProcessFile();
-        ObjectType objectType = ObjectType.getByCode(fileType);
-        switch (objectType) {
-            case Image:
-                uploadFileRet = imageFileProcessor.processImage(objectResult, processFile);
-                if (!processFile) {
-                    setUrl(uploadFileRet);
-                }
-                break;
-            case Video:
-                uploadFileRet = videoFileProcessor.process(objectResult);
-                break;
-            case Audio:
-                uploadFileRet = audioFileProcessor.process(objectResult);
-                break;
-            case Text:
-            case Other:
-                uploadFileRet = diskFileProcessor.process(objectResult);
-                break;
-            default:
-                log.info("{} 类型的 {} 文件暂时无法处理", objectType.name(), objectName);
-        }
-
-        return uploadFileRet;
-    }
-
-    private void setUrl(UploadFileRet uploadFileRet) {
-        String uploadId = uploadFileRet.getUploadId();
-        String url = imageRepository.getImageUrl(uploadId).getOriginalUrl();
-        uploadFileRet.setUrl(url);
-    }
 }

+ 5 - 5
oss-store/src/main/java/cn/reghao/oss/store/task/processor/ImageFileProcessor.java

@@ -39,14 +39,14 @@ public class ImageFileProcessor {
         this.putObjectService = putObjectService;
     }
 
-    public UploadFileRet processImage(ObjectResult objectResult, boolean processFile) throws Exception {
+    public UploadFileRet processImage(ObjectResult objectResult) throws Exception {
         String objectName = objectResult.getObjectName();
         String objectId = objectResult.getObjectId();
         String imageFileId = objectId;
         String objectUrl = objectNameService.getObjectUrl(objectName);
         boolean duplicate = objectResult.isDuplicate();
         if (duplicate) {
-            return processDuplicate(objectResult,processFile);
+            return processDuplicate(objectResult);
         }
 
         String absolutePath = objectResult.getAbsolutePath();
@@ -63,7 +63,7 @@ public class ImageFileProcessor {
         int height = size.getHeight();
         List<ImageFile> list = new ArrayList<>();
         list.add(new ImageFile(imageFileId, objectId, format, objectUrl, width, height));
-        if (processFile) {
+        if (false) {
             ImageFile imageFile = getConvertedImageFile(objectResult, "webp", width, height);
             list.add(imageFile);
         }
@@ -72,7 +72,7 @@ public class ImageFileProcessor {
         return new UploadFileRet(objectId, null);
     }
 
-    private UploadFileRet processDuplicate(ObjectResult objectResult, boolean processFile) throws Exception {
+    private UploadFileRet processDuplicate(ObjectResult objectResult) throws Exception {
         String objectName = objectResult.getObjectName();
         String objectId = objectResult.getObjectId();
         String imageFileId = objectId;
@@ -84,7 +84,7 @@ public class ImageFileProcessor {
         List<ImageFile> list = new ArrayList<>();
         list.add(imageFile1);
 
-        if (processFile) {
+        if (false) {
             if (imageFiles.size() > 1) {
                 for (int i = 1; i < imageFiles.size(); i++) {
                     ImageFile imageFile2 = imageFiles.get(i);

+ 1 - 1
store-api/src/main/java/cn/reghao/oss/store/api/dto/ObjectChannel.java

@@ -19,7 +19,7 @@ public class ObjectChannel implements Serializable {
     private String prefix;
     private Long maxSize;
     private Integer fileType;
-    private Boolean processFile;
+    private Boolean seturl;
     private Integer scope;
     private String domain;
     private Integer createBy;

+ 1 - 5
store-api/src/main/java/cn/reghao/oss/store/api/rest/UploadFileRet.java

@@ -13,7 +13,7 @@ public class UploadFileRet implements Serializable {
     private static final long serialVersionUID = 1L;
 
     private final String uploadId;
-    private String url;
+    private final String url;
     private final boolean merged;
 
     public UploadFileRet(String uploadId) {
@@ -27,8 +27,4 @@ public class UploadFileRet implements Serializable {
         this.url = url;
         this.merged = true;
     }
-
-    public void setUrl(String url) {
-        this.url = url;
-    }
 }