feat: 优化
This commit is contained in:
@@ -668,10 +668,13 @@ const handleBatchDelete = async () => {
|
||||
}
|
||||
|
||||
const formatFileSize = (size) => {
|
||||
if (size < 1024) return size + ' B'
|
||||
if (size < 1024 * 1024) return (size / 1024).toFixed(2) + ' KB'
|
||||
if (size < 1024 * 1024 * 1024) return (size / (1024 * 1024)).toFixed(2) + ' MB'
|
||||
return (size / (1024 * 1024 * 1024)).toFixed(2) + ' GB'
|
||||
const units = ['B', 'KB', 'MB', 'GB']
|
||||
let unitIndex = 0
|
||||
while (size >= 1024 && unitIndex < units.length - 1) {
|
||||
size /= 1024
|
||||
unitIndex++
|
||||
}
|
||||
return `${size.toFixed(2)} ${units[unitIndex]}`
|
||||
}
|
||||
|
||||
const formatDate = (date) => {
|
||||
|
||||
@@ -19,7 +19,7 @@ function getBaseUrl() {
|
||||
}
|
||||
return ''
|
||||
}
|
||||
//
|
||||
|
||||
const BASE_URL = getBaseUrl()
|
||||
|
||||
/**
|
||||
@@ -61,7 +61,7 @@ export const isDev = () => {
|
||||
*/
|
||||
export function getApiUrl(module, path) {
|
||||
const base = API_BASE[module] || API_BASE.APP
|
||||
return `${base}${path.startsWith('/') ? path : '/' + path}`
|
||||
return `${base}${path.startsWith('/') ? '' : '/'}${path}`
|
||||
}
|
||||
|
||||
export default API_BASE
|
||||
|
||||
@@ -216,39 +216,32 @@ public class BatchProduceAlignment {
|
||||
*/
|
||||
private Map<String, Integer> calculateCropParams(int sourceWidth, int sourceHeight, String cropMode) {
|
||||
Map<String, Integer> cropParams = new HashMap<>();
|
||||
double targetRatio = 9.0 / 16.0; // 9:16竖屏比例
|
||||
|
||||
if ("fill".equals(cropMode)) {
|
||||
// 填充模式:不裁剪,保持原尺寸
|
||||
if ("fill".equals(cropMode)) {
|
||||
cropParams.put("X", 0);
|
||||
cropParams.put("Y", 0);
|
||||
cropParams.put("Width", sourceWidth);
|
||||
cropParams.put("Height", sourceHeight);
|
||||
} else if ("smart".equals(cropMode)) {
|
||||
// 智能裁剪功能暂未开放,自动降级为居中裁剪
|
||||
log.info("[裁剪模式] smart模式暂未开放,自动降级为center模式");
|
||||
double cropHeight = sourceHeight;
|
||||
double cropWidth = cropHeight * targetRatio;
|
||||
int cropX = (int) Math.round((sourceWidth - cropWidth) / 2);
|
||||
int cropY = 0;
|
||||
|
||||
cropParams.put("X", cropX);
|
||||
cropParams.put("Y", cropY);
|
||||
cropParams.put("Width", (int) Math.round(cropWidth));
|
||||
cropParams.put("Height", (int) Math.round(cropHeight));
|
||||
} else {
|
||||
// center模式:居中裁剪(默认)
|
||||
double cropHeight = sourceHeight;
|
||||
double cropWidth = cropHeight * targetRatio;
|
||||
int cropX = (int) Math.round((sourceWidth - cropWidth) / 2);
|
||||
int cropY = 0;
|
||||
|
||||
cropParams.put("X", cropX);
|
||||
cropParams.put("Y", cropY);
|
||||
cropParams.put("Width", (int) Math.round(cropWidth));
|
||||
cropParams.put("Height", (int) Math.round(cropHeight));
|
||||
log.debug("[裁剪计算] 源尺寸={}x{}, 模式=fill, 裁剪参数={}", sourceWidth, sourceHeight, cropParams);
|
||||
return cropParams;
|
||||
}
|
||||
|
||||
// center/smart模式:居中裁剪(smart暂未开放,降级为center)
|
||||
if ("smart".equals(cropMode)) {
|
||||
log.info("[裁剪模式] smart模式暂未开放,自动降级为center模式");
|
||||
}
|
||||
|
||||
double targetRatio = 9.0 / 16.0; // 9:16竖屏比例
|
||||
double cropHeight = sourceHeight;
|
||||
double cropWidth = cropHeight * targetRatio;
|
||||
int cropX = (int) Math.round((sourceWidth - cropWidth) / 2);
|
||||
|
||||
cropParams.put("X", cropX);
|
||||
cropParams.put("Y", 0);
|
||||
cropParams.put("Width", (int) Math.round(cropWidth));
|
||||
cropParams.put("Height", (int) Math.round(cropHeight));
|
||||
|
||||
log.debug("[裁剪计算] 源尺寸={}x{}, 模式={}, 裁剪参数={}", sourceWidth, sourceHeight, cropMode, cropParams);
|
||||
return cropParams;
|
||||
}
|
||||
|
||||
@@ -589,6 +589,11 @@ public class MixTaskServiceImpl implements MixTaskService {
|
||||
}
|
||||
}
|
||||
|
||||
private static final int MIN_TOTAL_DURATION = 15;
|
||||
private static final int MAX_TOTAL_DURATION = 30;
|
||||
private static final int MIN_SEGMENT_DURATION = 3;
|
||||
private static final int MAX_SEGMENT_DURATION = 5;
|
||||
|
||||
/**
|
||||
* 验证新格式场景配置
|
||||
*/
|
||||
@@ -618,9 +623,7 @@ public class MixTaskServiceImpl implements MixTaskService {
|
||||
}
|
||||
|
||||
// 场景时长验证
|
||||
if (scene.getDuration() < 3 || scene.getDuration() > 5) {
|
||||
throw new IllegalArgumentException("场景" + i + "时长需在3-5秒之间,当前:" + scene.getDuration() + "秒");
|
||||
}
|
||||
validateSegmentDuration(scene.getDuration(), "场景" + i);
|
||||
|
||||
// 候选素材验证
|
||||
for (int j = 0; j < scene.getCandidates().size(); j++) {
|
||||
@@ -634,18 +637,11 @@ public class MixTaskServiceImpl implements MixTaskService {
|
||||
}
|
||||
}
|
||||
|
||||
// 3. 计算总时长
|
||||
// 3. 计算并校验总时长
|
||||
int totalDuration = req.getScenes().stream()
|
||||
.mapToInt(MixTaskSaveReqVO.SceneConfig::getDuration)
|
||||
.sum();
|
||||
|
||||
// 4. 总时长校验(15s-30s)
|
||||
if (totalDuration < 15) {
|
||||
throw new IllegalArgumentException("总时长不能小于15秒,当前:" + totalDuration + "秒");
|
||||
}
|
||||
if (totalDuration > 30) {
|
||||
throw new IllegalArgumentException("总时长不能超过30秒,当前:" + totalDuration + "秒");
|
||||
}
|
||||
validateTotalDuration(totalDuration);
|
||||
|
||||
log.info("[MixTask][新格式场景校验通过] totalDuration={}s, sceneCount={}", totalDuration, req.getScenes().size());
|
||||
}
|
||||
@@ -664,21 +660,35 @@ public class MixTaskServiceImpl implements MixTaskService {
|
||||
.mapToInt(MixTaskSaveReqVO.MaterialItem::getDuration)
|
||||
.sum();
|
||||
|
||||
// 3. 总时长校验(15s-30s)
|
||||
if (totalDuration < 15) {
|
||||
throw new IllegalArgumentException("总时长不能小于15秒,当前:" + totalDuration + "秒");
|
||||
}
|
||||
if (totalDuration > 30) {
|
||||
throw new IllegalArgumentException("总时长不能超过30秒,当前:" + totalDuration + "秒");
|
||||
}
|
||||
// 3. 校验总时长
|
||||
validateTotalDuration(totalDuration);
|
||||
|
||||
// 4. 单个素材时长校验(3s-5s)
|
||||
// 4. 单个素材时长校验
|
||||
for (MixTaskSaveReqVO.MaterialItem item : req.getMaterials()) {
|
||||
if (item.getDuration() < 3 || item.getDuration() > 5) {
|
||||
throw new IllegalArgumentException("单个素材时长需在3-5秒之间,当前:" + item.getDuration() + "秒");
|
||||
}
|
||||
validateSegmentDuration(item.getDuration(), "素材");
|
||||
}
|
||||
|
||||
log.info("[MixTask][旧格式素材校验通过] totalDuration={}s, materialCount={}", totalDuration, req.getMaterials().size());
|
||||
}
|
||||
|
||||
/**
|
||||
* 校验总时长
|
||||
*/
|
||||
private void validateTotalDuration(int totalDuration) {
|
||||
if (totalDuration < MIN_TOTAL_DURATION) {
|
||||
throw new IllegalArgumentException("总时长不能小于" + MIN_TOTAL_DURATION + "秒,当前:" + totalDuration + "秒");
|
||||
}
|
||||
if (totalDuration > MAX_TOTAL_DURATION) {
|
||||
throw new IllegalArgumentException("总时长不能超过" + MAX_TOTAL_DURATION + "秒,当前:" + totalDuration + "秒");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 校验单个片段时长
|
||||
*/
|
||||
private void validateSegmentDuration(int duration, String context) {
|
||||
if (duration < MIN_SEGMENT_DURATION || duration > MAX_SEGMENT_DURATION) {
|
||||
throw new IllegalArgumentException(context + "时长需在" + MIN_SEGMENT_DURATION + "-" + MAX_SEGMENT_DURATION + "秒之间,当前:" + duration + "秒");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user