修复
This commit is contained in:
@@ -331,70 +331,49 @@ public class TikUserFileServiceImpl implements TikUserFileService {
|
||||
log.info("[deleteFiles][用户({})删除文件成功,数量({})]", userId, fileIds.size());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getVideoPlayUrl(Long fileId) {
|
||||
/**
|
||||
* 查询用户文件(校验归属权)
|
||||
*/
|
||||
private TikUserFileDO getUserFile(Long fileId) {
|
||||
Long userId = SecurityFrameworkUtils.getLoginUserId();
|
||||
|
||||
// 查询文件(根据 fileId 字段查询)
|
||||
TikUserFileDO file = userFileMapper.selectOne(new LambdaQueryWrapperX<TikUserFileDO>()
|
||||
.eq(TikUserFileDO::getFileId, fileId)
|
||||
.eq(TikUserFileDO::getId, fileId)
|
||||
.eq(TikUserFileDO::getUserId, userId));
|
||||
|
||||
if (file == null) {
|
||||
throw exception(FILE_NOT_EXISTS, "文件不存在");
|
||||
}
|
||||
return file;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getVideoPlayUrl(Long fileId) {
|
||||
TikUserFileDO file = getUserFile(fileId);
|
||||
|
||||
// 校验文件URL是否为空
|
||||
if (StrUtil.isBlank(file.getFileUrl())) {
|
||||
throw exception(FILE_NOT_EXISTS, "文件URL为空");
|
||||
}
|
||||
|
||||
// 校验是否为视频文件
|
||||
boolean isVideo = StrUtil.containsIgnoreCase(file.getFileType(), "video");
|
||||
if (!isVideo) {
|
||||
if (!StrUtil.containsIgnoreCase(file.getFileType(), "video")) {
|
||||
throw exception(FILE_CATEGORY_INVALID, "文件不是视频类型");
|
||||
}
|
||||
|
||||
// 生成预签名URL(24小时有效期)
|
||||
return getCachedPresignUrl(file.getFileUrl(), PRESIGN_URL_EXPIRATION_SECONDS);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getAudioPlayUrl(Long fileId) {
|
||||
Long userId = SecurityFrameworkUtils.getLoginUserId();
|
||||
TikUserFileDO file = getUserFile(fileId);
|
||||
|
||||
// 查询文件(根据 fileId 字段查询)
|
||||
TikUserFileDO file = userFileMapper.selectOne(new LambdaQueryWrapperX<TikUserFileDO>()
|
||||
.eq(TikUserFileDO::getFileId, fileId)
|
||||
.eq(TikUserFileDO::getUserId, userId));
|
||||
|
||||
if (file == null) {
|
||||
throw exception(FILE_NOT_EXISTS, "文件不存在");
|
||||
}
|
||||
|
||||
// 校验是否为音频文件
|
||||
if (!StrUtil.containsIgnoreCase(file.getFileType(), "audio")) {
|
||||
throw exception(FILE_CATEGORY_INVALID, "文件不是音频类型");
|
||||
}
|
||||
|
||||
// 生成预签名URL(1小时有效期)
|
||||
return getCachedPresignUrl(file.getFileUrl(), PRESIGN_URL_EXPIRATION_SECONDS);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPreviewUrl(Long fileId, String type) {
|
||||
Long userId = SecurityFrameworkUtils.getLoginUserId();
|
||||
|
||||
// 查询文件(根据主键id查询)
|
||||
TikUserFileDO file = userFileMapper.selectById(fileId);
|
||||
if (file == null || !file.getUserId().equals(userId)) {
|
||||
throw exception(FILE_NOT_EXISTS);
|
||||
}
|
||||
|
||||
// 根据类型返回预览URL
|
||||
TikUserFileDO file = getUserFile(fileId);
|
||||
String previewUrl = determinePreviewUrl(file, type);
|
||||
|
||||
// 生成预签名URL(1小时有效期)
|
||||
return getCachedPresignUrl(previewUrl, PRESIGN_URL_EXPIRATION_SECONDS);
|
||||
}
|
||||
|
||||
@@ -408,14 +387,14 @@ public class TikUserFileServiceImpl implements TikUserFileService {
|
||||
}
|
||||
|
||||
// 明确指定类型
|
||||
if (StrUtil.equals(type, "cover") && StrUtil.isNotBlank(file.getCoverUrl())) {
|
||||
if ("cover".equals(type) && StrUtil.isNotBlank(file.getCoverUrl())) {
|
||||
return file.getCoverUrl();
|
||||
}
|
||||
if (StrUtil.equals(type, "thumbnail") && StrUtil.isNotBlank(file.getThumbnailUrl())) {
|
||||
if ("thumbnail".equals(type) && StrUtil.isNotBlank(file.getThumbnailUrl())) {
|
||||
return file.getThumbnailUrl();
|
||||
}
|
||||
|
||||
// 根据文件类型自动选择
|
||||
// 根据文件类型自动选择:图片优先缩略图,否则原图
|
||||
if (FileTypeUtils.isImage(file.getFileType())) {
|
||||
return StrUtil.isNotBlank(file.getThumbnailUrl()) ? file.getThumbnailUrl() : file.getFileUrl();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user