Browse Source

更新文件处理相关数据模型和方法

reghao 2 years ago
parent
commit
e55b1bb014

+ 3 - 2
dfs-store/src/main/java/cn/reghao/dfs/store/controller/ObjectUploadController.java

@@ -104,7 +104,7 @@ public class ObjectUploadController {
             UploadFileRet uploadFileRet = fileProcessor.process(objectResult, channelId);
             if (uploadFileRet == null) {
                 String url = objectNameService.getObjectUrl(objectResult.getObjectName());
-                uploadFileRet = new UploadFileRet(objectResult.getObjectId(), url);
+                uploadFileRet = new UploadFileRet(objectResult.getObjectId(), url, false);
             }
 
             // TODO PutMessageConverter 中生成的文件需要显式删除
@@ -163,7 +163,8 @@ public class ObjectUploadController {
 
         UploadFileRet uploadFileRet = fileProcessor.process(objectResult, channelId);
         if (uploadFileRet == null) {
-            return WebResult.failWithMsg("processing file failed");
+            String url = objectNameService.getObjectUrl(objectResult.getObjectName());
+            uploadFileRet = new UploadFileRet(objectResult.getObjectId(), url, false);
         }
         return WebResult.success(uploadFileRet);
     }

+ 5 - 1
dfs-store/src/main/java/cn/reghao/dfs/store/model/po/VideoUrl.java

@@ -18,15 +18,19 @@ public class VideoUrl extends BaseObject<Integer> {
     private String objectId;
     private String urlType;
     private String url;
+    private Long bitRate;
     private String quality;
     private Integer width;
     private Integer height;
+    private Integer order;
 
-    public VideoUrl(String videoFileId, String objectId, String urlType, String url, MediaResolution mediaResolution) {
+    public VideoUrl(String videoFileId, String objectId, String urlType, String url,
+                    Long bitRate, MediaResolution mediaResolution) {
         this.videoFileId = videoFileId;
         this.objectId = objectId;
         this.urlType = urlType;
         this.url = url;
+        this.bitRate = bitRate;
         this.quality = mediaResolution.getQuality();
         this.width = mediaResolution.getWidth();
         this.height = mediaResolution.getHeight();

+ 2 - 2
dfs-store/src/main/java/cn/reghao/dfs/store/service/ObjectMultipartUploadService.java

@@ -83,7 +83,7 @@ public class ObjectMultipartUploadService {
             putObjectService.copyObject(objectProp, filename, fileMeta);
 
             String url = String.format("https://%s/%s", domain, objectProp);
-            return new UploadFileRet(sha256sum, url);
+            return new UploadFileRet(sha256sum, url, false);
         }
 
         Set<Long> set = map.computeIfAbsent(sha256sum, k -> new HashSet<>());
@@ -124,7 +124,7 @@ public class ObjectMultipartUploadService {
             map.remove(sha256sum);
             pathMap.remove(sha256sum);
             String url = String.format("https://%s/%s", domain, objectProp);
-            return new UploadFileRet(sha256sum, url);
+            return new UploadFileRet(sha256sum, url, false);
         }
     }
 }

+ 3 - 3
dfs-store/src/main/java/cn/reghao/dfs/store/task/AudioFileProcessor.java

@@ -58,7 +58,7 @@ public class AudioFileProcessor {
             String audioCodec = audioFile.getCodec();
             AudioFile audioFile1 = new AudioFile(audioFileId, objectId1, audioCodec, url1);
             mediaRepository.saveAudioFile(audioFile1);
-            return new UploadFileRet(objectId1, url1);
+            return new UploadFileRet(objectId1, url1, true);
         }
 
         String absolutePath = objectResult.getAbsolutePath();
@@ -81,7 +81,7 @@ public class AudioFileProcessor {
         String url1 = objectNameService.getObjectUrl(objectResult1.getObjectName());
         AudioFile audioFile = new AudioFile(audioFileId, objectId1, audioCodec, url1);
         mediaRepository.saveAudioFile(audioFile);
-        return new UploadFileRet(objectId1, url1);
+        return new UploadFileRet(objectId1, url1, true);
     }
 
     private UploadFileRet getConvertedAudioFile(String audioFileId, File file, String originalObjectName, String suffix) {
@@ -107,7 +107,7 @@ public class AudioFileProcessor {
             String codec = "aac";
             AudioFile audioFile = new AudioFile(audioFileId, objectId, codec, url);
             mediaRepository.saveAudioFile(audioFile);
-            return new UploadFileRet(objectId, url);
+            return new UploadFileRet(objectId, url, true);
         } catch (Exception e) {
             e.printStackTrace();
         }

+ 2 - 1
dfs-store/src/main/java/cn/reghao/dfs/store/task/ConvertTask.java

@@ -48,8 +48,9 @@ public class ConvertTask implements Runnable {
             int width = videoProps.getCodedWidth().intValue();
             int height = videoProps.getCodedHeight().intValue();
 
+            long bitRate = videoProps.getBitRate();
             MediaResolution mediaResolution = MediaQuality.getQuality(width, height);
-            VideoUrl videoUrl = new VideoUrl(videoFileId, objectName, VideoUrlType.mp4.name(), url, mediaResolution);
+            VideoUrl videoUrl = new VideoUrl(videoFileId, objectName, VideoUrlType.mp4.name(), url, bitRate, mediaResolution);
             //videoUrlMapper.save(videoUrl);
             destFile.delete();
         } catch (Exception e) {

+ 1 - 1
dfs-store/src/main/java/cn/reghao/dfs/store/task/DiskFileProcessor.java

@@ -21,6 +21,6 @@ public class DiskFileProcessor {
         String objectName = objectResult.getObjectName();
         String objectId = objectResult.getObjectId();
         String url = objectNameService.getObjectUrl(objectName);
-        return new UploadFileRet(objectId, url);
+        return new UploadFileRet(objectId, url, false);
     }
 }

+ 4 - 4
dfs-store/src/main/java/cn/reghao/dfs/store/task/ImageFileProcessor.java

@@ -67,7 +67,7 @@ public class ImageFileProcessor {
             ImageUrl imageUrl1 = new ImageUrl(objectId, format, objectId, url, width, height);
 
             mediaRepository.saveImageFile(imageFile1, List.of(imageUrl1));
-            return new UploadFileRet(objectId, url);
+            return new UploadFileRet(objectId, url, true);
         }
 
         String absolutePath = objectResult.getAbsolutePath();
@@ -82,7 +82,7 @@ public class ImageFileProcessor {
                 ImageFile imageFile = new ImageFile(objectId, width, height);
                 ImageUrl imageUrl = new ImageUrl(objectId, format, objectId, url, width, height);
                 mediaRepository.saveImageFile(imageFile, List.of(imageUrl));
-                return new UploadFileRet(objectId, url);
+                return new UploadFileRet(objectId, url, true);
             } else {
                 log.info("不支持 {} 格式的文件", format);
             }
@@ -124,7 +124,7 @@ public class ImageFileProcessor {
             list.add(imageUrl1);
 
             mediaRepository.saveImageFile(imageFile1, list);
-            return new UploadFileRet(objectId, url);
+            return new UploadFileRet(objectId, url, true);
         }
 
         String absolutePath = objectResult.getAbsolutePath();
@@ -148,7 +148,7 @@ public class ImageFileProcessor {
                 }
 
                 mediaRepository.saveImageFile(imageFile, imageUrls);
-                return new UploadFileRet(objectId, url);
+                return new UploadFileRet(objectId, url, true);
             } else {
                 log.info("不支持 {} 格式的文件", format);
             }

+ 10 - 6
dfs-store/src/main/java/cn/reghao/dfs/store/task/VideoFileProcessor.java

@@ -70,14 +70,16 @@ public class VideoFileProcessor {
             }
 
             String urlType = videoUrl.getUrlType();
+            String url = objectNameService.getObjectUrl(objectName);
+            long bitRate = videoUrl.getBitRate();
             String quality = videoUrl.getQuality();
             int width = videoUrl.getWidth();
             int height = videoUrl.getHeight();
-            String url = objectNameService.getObjectUrl(objectName);
-            VideoUrl videoUrl1 = new VideoUrl(videoFileId, videoFileId, urlType, url, quality, width, height);
+            int order = 1;
+            VideoUrl videoUrl1 = new VideoUrl(videoFileId, videoFileId, urlType, url, bitRate, quality, width, height, order);
 
             mediaRepository.saveVideoFile(videoFile1, videoUrl1);
-            return new UploadFileRet(videoFileId, url);
+            return new UploadFileRet(videoFileId, url, true);
         }
 
         String absolutePath = objectResult.getAbsolutePath();
@@ -118,11 +120,12 @@ public class VideoFileProcessor {
         String objectId1 = objectResult1.getObjectId();
         String url1 = objectNameService.getObjectUrl(objectName1);*/
 
+        long bitRate = videoProps.getBitRate();
         MediaResolution mediaResolution = MediaQuality.getQuality(width, height);
         String urlType = FileType.getVideoUrlType(absolutePath);
-        VideoUrl videoUrl  = new VideoUrl(videoFileId, videoFileId, urlType, originalUrl, mediaResolution);;
+        VideoUrl videoUrl  = new VideoUrl(videoFileId, videoFileId, urlType, originalUrl, bitRate, mediaResolution);
         mediaRepository.saveVideoFile(videoFile, videoUrl);
-        return new UploadFileRet(videoFileId, originalUrl);
+        return new UploadFileRet(videoFileId, originalUrl, true);
         //log.info("添加视频格式转码任务");
         //threadPool.submit(new ConvertTask());
     }
@@ -151,8 +154,9 @@ public class VideoFileProcessor {
             String objectId = objectResult.getObjectId();
             String url = objectNameService.getObjectUrl(objectResult.getObjectName());
             String urlType = FileType.getVideoUrlType(absolutePath);
+            long bitRate = 0;
             MediaResolution mediaResolution = MediaQuality.getQuality(width, height);
-            return new VideoUrl(videoFileId, objectId, urlType, url, mediaResolution);
+            return new VideoUrl(videoFileId, objectId, urlType, url, bitRate, mediaResolution);
         } catch (Exception e) {
             e.printStackTrace();
         }

+ 5 - 2
dfs-store/src/main/resources/mapper/VideoFileMapper.xml

@@ -16,9 +16,12 @@
         select * from video_file
     </select>
     <select id="findVideoInfo" resultType="cn.reghao.oss.api.dto.VideoInfo">
-        select video_file_id,duration,horizontal
+        select video_file.video_file_id,video_file.duration,video_file.horizontal,video_url.quality
         from video_file
-        where video_file_id=#{videoFileId}
+        inner join video_url
+        on video_file.video_file_id=video_url.video_file_id and video_file.video_file_id=#{videoFileId}
+        order by video_url.order asc
+        limit 1
     </select>
     <select id="findByVideoFileId" resultType="cn.reghao.dfs.store.model.po.VideoFile">
         select * from video_file

+ 2 - 2
dfs-store/src/main/resources/mapper/VideoUrlMapper.xml

@@ -4,9 +4,9 @@
 <mapper namespace="cn.reghao.dfs.store.db.mapper.VideoUrlMapper">
     <insert id="save" useGeneratedKeys="true" keyProperty="id">
         insert into video_url
-        (`video_file_id`,`object_id`,`url_type`,`width`,`height`,`quality`,`url`)
+        (`video_file_id`,`object_id`,`url_type`,`url`,`bit_rate`,`quality`,`width`,`height`,`order`)
         values
-        (#{videoFileId},#{objectId},#{urlType},#{width},#{height},#{quality},#{url})
+        (#{videoFileId},#{objectId},#{urlType},#{url},#{bitRate},#{quality},#{width},#{height},#{order})
     </insert>
 
     <select id="findAll" resultType="cn.reghao.dfs.store.model.po.VideoUrl">