Browse Source

update:歌曲上传播放支持高质量大文件v1

tujidelv 1 year ago
parent
commit
5bed97000e

+ 6 - 1
src/main/java/top/lvzhiqiang/service/impl/CoinServiceImpl.java

@@ -1958,7 +1958,12 @@ public class CoinServiceImpl implements CoinService {
             fileMusicCollection.setCategoryName(categoryName);
             String remark = StringUtils.isNotEmpty(fileMusicCollection.getRemark()) && fileMusicCollection.getRemark().length() > 20 ? (fileMusicCollection.getRemark().substring(0, 20) + "...") : fileMusicCollection.getRemark();
             fileMusicCollection.setRemark("<span class=\"primary\" avid=\"" + fileMusicCollection.getId() + " \" >" + remark + " </span>");
-            fileMusicCollection.setLowQualityUrl(ftpBaseUrl + ftpBasePath + fileMusicCollection.getLowQualityUrl());
+            if (StringUtils.isNotEmpty(fileMusicCollection.getLowQualityUrl())) {
+                fileMusicCollection.setLowQualityUrl(ftpBaseUrl + ftpBasePath + fileMusicCollection.getLowQualityUrl());
+            }
+            if (StringUtils.isNotEmpty(fileMusicCollection.getHighQualityUrl())) {
+                fileMusicCollection.setHighQualityUrl(ftpBaseUrl + ftpBasePath + fileMusicCollection.getHighQualityUrl());
+            }
 
             // 优先级
             Integer score = Integer.valueOf(fileMusicCollection.getScore());

+ 49 - 0
src/main/java/top/lvzhiqiang/service/impl/MusicInfoServiceImpl.java

@@ -101,6 +101,27 @@ public class MusicInfoServiceImpl extends BaseServiceImpl<Object> implements Mus
                         imageUrl = parentPath + "/" + newName;
                         fileMusicCollection.setLowQualityUrl(imageUrl);
                     }
+                } else if (file != null && StringUtils.isNotEmpty(file.getOriginalFilename()) && "high".equals(qualityType)) {
+                    // 1、给上传的图片生成新的文件名
+                    // 1.1获取原始文件名
+                    String oldName = file.getOriginalFilename();
+                    // 1.2使用FtpUtil工具类生成新的文件名,新文件名 = newName + 文件后缀
+                    String newName = FtpUtil.genImageName();
+                    newName = newName + oldName.substring(oldName.lastIndexOf("."));
+                    // 2、把图片上传到图片服务器
+                    // 2.1获取上传的io流
+                    InputStream input = file.getInputStream();
+
+                    // 2.2调用FtpUtil工具类进行上传
+                    boolean result = FtpUtil.uploadFile(ftpBasePath, parentPath, newName, input);
+
+                    if (result) {
+                        imageSize = BigDecimal.valueOf(file.getSize()).divide(new BigDecimal("1048576")).setScale(2, RoundingMode.UP).toPlainString().concat("MB");
+                        fileMusicCollection.setSize(imageSize);
+                        // 返回给前端图片访问路径
+                        imageUrl = parentPath + "/" + newName;
+                        fileMusicCollection.setHighQualityUrl(imageUrl);
+                    }
                 }
 
                 fileMusicCollection.setTitle(title);
@@ -197,10 +218,38 @@ public class MusicInfoServiceImpl extends BaseServiceImpl<Object> implements Mus
                     } else {
                         throw new BusinessException(ResultCodeEnum.UNKNOWN_ERROR.getCode(), "上传新文件失败!");
                     }
+                } else if (file != null && StringUtils.isNotEmpty(file.getOriginalFilename()) && "high".equals(qualityType)) {
+                    // 1、给上传的图片生成新的文件名
+                    // 1.1获取原始文件名
+                    String oldName = file.getOriginalFilename();
+                    // 1.2使用FtpUtil工具类生成新的文件名,新文件名 = newName + 文件后缀
+                    String newName = FtpUtil.genImageName();
+                    newName = newName + oldName.substring(oldName.lastIndexOf("."));
+                    // 2、把图片上传到图片服务器
+                    // 2.1获取上传的io流
+                    InputStream input = file.getInputStream();
+
+                    // 2.2调用FtpUtil工具类进行上传
+                    boolean result = FtpUtil.uploadFile(ftpBasePath, parentPath, newName, input);
+                    if (result) {
+                        FtpUtil.delFile(ftpBasePath + fileMusicCollection.getHighQualityUrl());
+
+                        imageSize = BigDecimal.valueOf(file.getSize()).divide(new BigDecimal("1048576")).setScale(2, RoundingMode.UP).toPlainString().concat("MB");
+                        fileMusicCollection.setSize(imageSize);
+                        // 返回给前端图片访问路径
+                        imageUrl = parentPath + "/" + newName;
+                        fileMusicCollection.setHighQualityUrl(imageUrl);
+                    } else {
+                        throw new BusinessException(ResultCodeEnum.UNKNOWN_ERROR.getCode(), "上传新文件失败!");
+                    }
                 } else if (file != null && StringUtils.isNotEmpty(file.getOriginalFilename()) && "lyric".equals(qualityType)) {
                     // 1、给上传的图片生成新的文件名
                     // 1.1获取原始文件名
                     String lowQualityUrl = fileMusicCollection.getLowQualityUrl();
+                    if (StringUtils.isEmpty(lowQualityUrl)) {
+                        lowQualityUrl = fileMusicCollection.getHighQualityUrl();
+                    }
+
                     String lyricName = lowQualityUrl.substring(0, lowQualityUrl.lastIndexOf(".")) + ".lrc";
                     // 2、把图片上传到图片服务器
                     // 2.1获取上传的io流

+ 2 - 2
src/main/resources/application.yml

@@ -1,8 +1,8 @@
 spring:
   servlet:
     multipart:
-      max-file-size: 10MB
-      max-request-size: 20MB
+      max-file-size: 50MB
+      max-request-size: 100MB
   application:
     name: jav
   # 指定运行环境

+ 6 - 1
src/main/resources/static/js/my-coin.js

@@ -589,7 +589,7 @@ function mainSearch(url, nameEn, slideDiv, typetype, needCustomFlag) {
                         str += '</td>';
                     } else if (nameEn === 'music') {
                         str += '<td style="padding: 0px 10px 0px 10px;">';
-                        str += '<button class="apis-quiet-div-music-play" operationType="play" symbolName="' + dataDetail.lowQualityUrl + '">播放</button>';
+                        str += '<button class="apis-quiet-div-music-play" operationType="play" symbolName="' + dataDetail.lowQualityUrl + '" symbolName2="' + dataDetail.highQualityUrl + '">播放</button>';
                         // str += '<button class="apis-quiet-div-music-pause" operationType="pause" symbolName="' + dataDetail.lowQualityUrl + '">暂停</button>';
                         str += '<button class="apis-quiet-div-music-detail" operationType="detail" symbolName="' + dataDetail.id + '">详情</button>';
                         str += '<button class="apis-quiet-div-music-update" operationType="update" symbolName="' + dataDetail.id + '">编辑</button>';
@@ -877,6 +877,11 @@ function initContentEvent(nameEn) {
         });
         $(".apis-quiet-div-music-play").click(function () {
             var symbol = $(this).attr("symbolName");
+            var symbol2 = $(this).attr("symbolName2");
+            if (symbol === null || symbol === '' || symbol === 'null') {
+                symbol = symbol2;
+            }
+
             var currentSrc = $("#apis-quiet-content > audio > source").attr("src");
             if (currentSrc === symbol) {
                 $("#apis-quiet-content > audio")[0].play();

+ 7 - 4
src/test/java/top/lvzhiqiang/TestCoinExport.java

@@ -66,8 +66,8 @@ public class TestCoinExport {
         InputStream is = null;
         XSSFWorkbook wb = null;
         try {
-            String templatePath = "/Users/l1024v/Downloads/coinRank.xlsx";
-            String outputPath = "/Users/l1024v/Downloads/coinRank_" + LocalDate.now().format(DateUtils.dateFormatter2) + ".xlsx";
+            String templatePath = "D:\\Downloads\\coinRank.xlsx";
+            String outputPath = "D:\\Downloads\\coinRank_" + LocalDate.now().format(DateUtils.dateFormatter2) + ".xlsx";
             is = Files.newInputStream(Paths.get(templatePath));
             wb = new XSSFWorkbook(is);
 
@@ -77,8 +77,9 @@ public class TestCoinExport {
 
             int MAX_NUMBER = 100;
             int sortNum = 1;
-            Proxy proxy = new Proxy(Proxy.Type.SOCKS, new InetSocketAddress("127.0.0.1", 1081));
-            proxy = Proxy.NO_PROXY;
+            Proxy proxy = new Proxy(Proxy.Type.SOCKS, new InetSocketAddress("127.0.0.1", 10808));
+            //proxy = Proxy.NO_PROXY;
+            int jjj = 0;
             for (int i = 1; i <= 5; i++) {
                 String coingeckoCoinsMarketsUrl = InitRunner.dicCodeMap.get("coingecko_coins_markets_url").getCodeValue();
                 Map<String, String> headerMap = new HashMap<>();
@@ -97,6 +98,7 @@ public class TestCoinExport {
 
                 for (int j = 0; j < result.size(); j++) {
                     JSONObject marketData = result.getJSONObject(j);
+                    jjj++;
 
                     XSSFRow row = sheet.createRow(sortNum + 1);
                     int column = 0;
@@ -114,6 +116,7 @@ public class TestCoinExport {
                     // 符号
                     if (marketData.containsKey("symbol") && null != marketData.get("symbol")) {
                         row.createCell(column++).setCellValue(marketData.getString("symbol"));
+                        System.out.println(jjj + ":" + marketData.getString("symbol"));
                     } else {
                         row.createCell(column++).setCellValue("");
                     }