Skip to content

Commit

Permalink
Feature: 电台支持acc文件上传
Browse files Browse the repository at this point in the history
  • Loading branch information
yangrunkang committed Jun 18, 2022
1 parent 4d4eeda commit ece21b6
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@

package com.upupor.service.utils.oss;

import com.google.common.collect.Lists;
import com.upupor.framework.BusinessException;
import com.upupor.framework.CcConstant;
import com.upupor.framework.ErrorCode;
Expand Down Expand Up @@ -98,7 +99,7 @@ public static FileUpload create(String dic, String suffix) {


public static String upload(FileUpload fileUpload, InputStream inputStream) throws IOException {
uploadToOss(fileUpload.getFolderName(),inputStream);
uploadToOss(fileUpload.getFolderName(), inputStream);
return fileUpload.getFullUrl();
}

Expand Down Expand Up @@ -157,14 +158,16 @@ public static String upload(MultipartFile file, FileDic fileDic) throws IOExcept
} else if (FileDic.RADIO.equals(fileDic)) {
// 检查文件类型
String fileType = FileUtils.getFileType(file.getInputStream());
if (!"audio/mpeg".equals(fileType)) {
throw new BusinessException(ErrorCode.PARAM_ERROR, "禁止上传非mp3文件");
List<String> detectTypes = Lists.newArrayList("audio/mpeg", "application/octet-stream");
if (!detectTypes.contains(fileType.toLowerCase())) {
throw new BusinessException(ErrorCode.PARAM_ERROR, "禁止上传非mp3或aac文件");
}

// 校验文件后缀
String suffix = FileUpload.getFileSuffix(file);
if (!"mp3".equalsIgnoreCase(suffix)) {
throw new BusinessException(ErrorCode.PARAM_ERROR, "文件类型必须是mp3格式");
List<String> supportFileType = Lists.newArrayList("mp3", "aac");
if (!supportFileType.contains(suffix.toLowerCase())) {
throw new BusinessException(ErrorCode.PARAM_ERROR, "文件类型必须是mp3或aac格式");
}
} else {
fileInputStream = file.getInputStream();
Expand Down Expand Up @@ -263,6 +266,7 @@ public void run() {


private static List<AbstractOss> abstractOssList = new ArrayList<>();

static {
abstractOssList.add(new MinioOss());
}
Expand All @@ -278,9 +282,9 @@ private static void uploadToOss(String folderName, InputStream inputStream) {
}

for (AbstractOss abstractOss : abstractOssList) {
if(abstractOss.ossSource().equals(upuporConfig.getOssSource())){
if (abstractOss.ossSource().equals(upuporConfig.getOssSource())) {
abstractOss.init(upuporConfig);
abstractOss.upload(folderName,inputStream);
abstractOss.upload(folderName, inputStream);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.websocket.server.PathParam;
import java.io.IOException;
import java.util.Objects;

Expand All @@ -60,7 +59,7 @@
@RestController
@RequiredArgsConstructor
@RequestMapping("/file")
public class PictureUploadController {
public class UploadController {

private final MemberService memberService;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
<div class="form-group mb-3">
<label class="text-black-50">上传电台音频文件</label>
<div class="input-group mb-3">
<input type="file" class="form-control custom-file-input" accept=".mp3" id="radio-file" aria-describedby="radio-file">
<input type="file" class="form-control custom-file-input" accept=".mp3,.aac" id="radio-file" aria-describedby="radio-file">
</div>
</div>
<div class="form-group mb-3">
Expand All @@ -61,7 +61,7 @@
<button type="submit" class="btn rounded-3 bg-gradient btn-primary public-radio">发布音频</button>
<div>
<small id="passwordHelpBlock" class="form-text text-muted mt-1">
<span>·&nbsp;当前仅支持mp3格式的电台音频发布</span><br />
<span>·&nbsp;当前仅支持mp3、aac格式的电台音频发布</span><br />
<span>·&nbsp;上传耗时取决于网络环境,如果文件较大,请耐心等待</span>
</small>
</div>
Expand Down

0 comments on commit ece21b6

Please sign in to comment.