fix(pricetrack): ASIN文件路径防本地路径误提交+fileKey兜底反查
This commit is contained in:
+9
-1
@@ -86,6 +86,7 @@ public class PriceTrackTaskService {
|
|||||||
private final TaskFileJobService taskFileJobService;
|
private final TaskFileJobService taskFileJobService;
|
||||||
private final TaskDistributedLockService taskDistributedLockService;
|
private final TaskDistributedLockService taskDistributedLockService;
|
||||||
private final TaskProgressLightAssembler taskProgressLightAssembler;
|
private final TaskProgressLightAssembler taskProgressLightAssembler;
|
||||||
|
private final com.nanri.aiimage.modules.file.service.LocalFileStorageService localFileStorageService;
|
||||||
|
|
||||||
private FileTaskEntity loadTaskForExecution(Long taskId) {
|
private FileTaskEntity loadTaskForExecution(Long taskId) {
|
||||||
Map<Long, FileTaskEntity> cachedTasks = priceTrackTaskCacheService.getTaskCacheBatch(List.of(taskId));
|
Map<Long, FileTaskEntity> cachedTasks = priceTrackTaskCacheService.getTaskCacheBatch(List.of(taskId));
|
||||||
@@ -1463,7 +1464,14 @@ public class PriceTrackTaskService {
|
|||||||
}
|
}
|
||||||
File file = new File(rawPath);
|
File file = new File(rawPath);
|
||||||
if (!file.isFile()) {
|
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);
|
String lowerName = file.getName().toLowerCase(Locale.ROOT);
|
||||||
if (lowerName.endsWith(".csv")) {
|
if (lowerName.endsWith(".csv")) {
|
||||||
|
|||||||
@@ -491,29 +491,34 @@ function saveActiveLoopRunId() {
|
|||||||
// ========== 文件上传 ==========
|
// ========== 文件上传 ==========
|
||||||
async function selectAsinFile() {
|
async function selectAsinFile() {
|
||||||
const api = getPywebviewApi()
|
const api = getPywebviewApi()
|
||||||
|
let paths: string[] = []
|
||||||
if (api?.select_files) {
|
if (api?.select_files) {
|
||||||
const result = await api.select_files({
|
const result = await api.select_files({
|
||||||
filters: [{ name: 'Excel/CSV', extensions: 'xlsx,xls,csv' }],
|
filters: [{ name: 'Excel/CSV', extensions: 'xlsx,xls,csv' }],
|
||||||
multiple: true,
|
multiple: true,
|
||||||
})
|
})
|
||||||
if (result?.paths?.length) {
|
if (!result?.paths?.length) return
|
||||||
if (!(await passGuard(checkSelectedFiles(result.paths, { allowedExtensions: EXCEL_CSV_EXTENSIONS })))) return
|
if (!(await passGuard(checkSelectedFiles(result.paths, { allowedExtensions: EXCEL_CSV_EXTENSIONS })))) return
|
||||||
asinFiles.value = result.paths
|
paths = result.paths
|
||||||
asinUploadedFiles.value = await uploadAsinPathsToJava(result.paths)
|
} else if (api?.select_brand_xlsx_files) {
|
||||||
ElMessage.success(`已选择 ${result.paths.length} 个ASIN文件`)
|
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
|
return
|
||||||
}
|
}
|
||||||
if (api?.select_brand_xlsx_files) {
|
try {
|
||||||
const paths = await api.select_brand_xlsx_files()
|
|
||||||
if (!paths?.length) return
|
|
||||||
if (!(await passGuard(checkSelectedFiles(paths, { allowedExtensions: EXCEL_CSV_EXTENSIONS })))) return
|
|
||||||
asinFiles.value = paths
|
asinFiles.value = paths
|
||||||
asinUploadedFiles.value = await uploadAsinPathsToJava(paths)
|
asinUploadedFiles.value = await uploadAsinPathsToJava(paths)
|
||||||
ElMessage.success(`已选择 ${paths.length} 个ASIN文件`)
|
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() {
|
async function selectAsinFolder() {
|
||||||
@@ -564,10 +569,8 @@ async function uploadAsinPathsToJava(paths: Array<string | { absolutePath: strin
|
|||||||
}
|
}
|
||||||
|
|
||||||
function resolveAsinRequestPaths() {
|
function resolveAsinRequestPaths() {
|
||||||
if (asinUploadedFiles.value.length) {
|
// 只提交上传成功后的服务器本地路径;未上传成功时不兜底本地路径(服务器无法读取)
|
||||||
return asinUploadedFiles.value.map((item) => item.localPath).filter((path) => !!path)
|
return asinUploadedFiles.value.map((item) => item.localPath).filter((path) => !!path)
|
||||||
}
|
|
||||||
return asinFiles.value
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function resolveCountryCodesForRequest() {
|
function resolveCountryCodesForRequest() {
|
||||||
|
|||||||
Reference in New Issue
Block a user