fix(pricetrack): ASIN文件路径防本地路径误提交+fileKey兜底反查
This commit is contained in:
+9
-1
@@ -86,6 +86,7 @@ public class PriceTrackTaskService {
|
||||
private final TaskFileJobService taskFileJobService;
|
||||
private final TaskDistributedLockService taskDistributedLockService;
|
||||
private final TaskProgressLightAssembler taskProgressLightAssembler;
|
||||
private final com.nanri.aiimage.modules.file.service.LocalFileStorageService localFileStorageService;
|
||||
|
||||
private FileTaskEntity loadTaskForExecution(Long taskId) {
|
||||
Map<Long, FileTaskEntity> cachedTasks = priceTrackTaskCacheService.getTaskCacheBatch(List.of(taskId));
|
||||
@@ -1463,7 +1464,14 @@ public class PriceTrackTaskService {
|
||||
}
|
||||
File file = new File(rawPath);
|
||||
if (!file.isFile()) {
|
||||
throw new BusinessException("ASIN file not found: " + rawPath);
|
||||
// 直接路径不可读时兜底:按上传返回的 fileKey 反查服务器本地临时目录
|
||||
File resolved = localFileStorageService.findLocalSourceFile(rawPath);
|
||||
if (resolved != null) {
|
||||
file = resolved;
|
||||
}
|
||||
}
|
||||
if (!file.isFile()) {
|
||||
throw new BusinessException("ASIN 文件不存在或不可读: " + rawPath);
|
||||
}
|
||||
String lowerName = file.getName().toLowerCase(Locale.ROOT);
|
||||
if (lowerName.endsWith(".csv")) {
|
||||
|
||||
@@ -491,29 +491,34 @@ function saveActiveLoopRunId() {
|
||||
// ========== 文件上传 ==========
|
||||
async function selectAsinFile() {
|
||||
const api = getPywebviewApi()
|
||||
let paths: string[] = []
|
||||
if (api?.select_files) {
|
||||
const result = await api.select_files({
|
||||
filters: [{ name: 'Excel/CSV', extensions: 'xlsx,xls,csv' }],
|
||||
multiple: true,
|
||||
})
|
||||
if (result?.paths?.length) {
|
||||
if (!result?.paths?.length) return
|
||||
if (!(await passGuard(checkSelectedFiles(result.paths, { allowedExtensions: EXCEL_CSV_EXTENSIONS })))) return
|
||||
asinFiles.value = result.paths
|
||||
asinUploadedFiles.value = await uploadAsinPathsToJava(result.paths)
|
||||
ElMessage.success(`已选择 ${result.paths.length} 个ASIN文件`)
|
||||
}
|
||||
paths = result.paths
|
||||
} else if (api?.select_brand_xlsx_files) {
|
||||
const selected = await api.select_brand_xlsx_files()
|
||||
if (!selected?.length) return
|
||||
if (!(await passGuard(checkSelectedFiles(selected, { allowedExtensions: EXCEL_CSV_EXTENSIONS })))) return
|
||||
paths = selected
|
||||
} else {
|
||||
ElMessage.warning('当前环境不支持文件选择,请在本地客户端中打开')
|
||||
return
|
||||
}
|
||||
if (api?.select_brand_xlsx_files) {
|
||||
const paths = await api.select_brand_xlsx_files()
|
||||
if (!paths?.length) return
|
||||
if (!(await passGuard(checkSelectedFiles(paths, { allowedExtensions: EXCEL_CSV_EXTENSIONS })))) return
|
||||
try {
|
||||
asinFiles.value = paths
|
||||
asinUploadedFiles.value = await uploadAsinPathsToJava(paths)
|
||||
ElMessage.success(`已选择 ${paths.length} 个ASIN文件`)
|
||||
return
|
||||
} catch (error) {
|
||||
// 上传失败时清空选择,避免本地路径残留被当作服务器路径提交给 Java
|
||||
asinFiles.value = []
|
||||
asinUploadedFiles.value = []
|
||||
ElMessage.error(error instanceof Error ? error.message : '选择失败')
|
||||
}
|
||||
ElMessage.warning('当前环境不支持文件选择,请在本地客户端中打开')
|
||||
}
|
||||
|
||||
async function selectAsinFolder() {
|
||||
@@ -564,10 +569,8 @@ async function uploadAsinPathsToJava(paths: Array<string | { absolutePath: strin
|
||||
}
|
||||
|
||||
function resolveAsinRequestPaths() {
|
||||
if (asinUploadedFiles.value.length) {
|
||||
// 只提交上传成功后的服务器本地路径;未上传成功时不兜底本地路径(服务器无法读取)
|
||||
return asinUploadedFiles.value.map((item) => item.localPath).filter((path) => !!path)
|
||||
}
|
||||
return asinFiles.value
|
||||
}
|
||||
|
||||
function resolveCountryCodesForRequest() {
|
||||
|
||||
Reference in New Issue
Block a user