feat(storage): group archives by the BPM order field
This commit is contained in:
1 parent
607b240aa3
commit
fff2a29ec0
13 files changed
+163
-18
No files matched your search
@@ -1,6 +1,7 @@
|
||||
'use strict';
|
||||
const fs=require('node:fs/promises');const path=require('node:path');
|
||||
const {SmbClient,segments,inside}=require('./storage-files.cjs');
|
||||
const {orderFolder}=require('./storage-order.cjs');
|
||||
const fail=(message,status=400)=>Object.assign(new Error(message),{status});
|
||||
const safe=e=>e.status?e:fail(({ENOENT:'找不到文件或归档目录,请检查路径。',EACCES:'没有共享目录访问权限。',EPERM:'没有共享目录操作权限。',ENOSPC:'存储服务器空间不足。',ENOTDIR:'指定路径不是目录。'})[e.code]||'存储操作未完成,请检查服务器与网络。',502);
|
||||
class StorageService{
|
||||
@@ -58,7 +59,14 @@ class StorageService{
|
||||
segments(directory);if(typeof jobId!=='string'||!jobId||jobId.length>200)throw fail('请选择已完成的 PDF 导出任务。');
|
||||
const job=this.jobs.jobs().find(j=>j.jobId===jobId);if(!job||job.status!=='success'||typeof job.path!=='string')throw fail('请选择已完成且存在的 PDF。');
|
||||
const record=this.store.beginArchive(id,jobId,actor,directory);
|
||||
try{const [root,file]=await Promise.all([fs.realpath(this.outputDir),fs.realpath(job.path)]);if(!inside(root,file)||file===root||path.extname(file).toLowerCase()!=='.pdf')throw fail('PDF 不在本工具输出目录内。');const area=await this.client.area(server),result=await area.archive(file,path.basename(file),directory);return this.store.finishArchive(record.id,'success',{...result,serverName:server.name});}
|
||||
try{
|
||||
const [root,file]=await Promise.all([fs.realpath(this.outputDir),fs.realpath(job.path)]);
|
||||
if(!inside(root,file)||file===root||path.extname(file).toLowerCase()!=='.pdf')throw fail('PDF 不在本工具输出目录内。');
|
||||
const grouping=orderFolder(job),base=segments(directory),current=base.at(-1)||segments(server.directory).at(-1);
|
||||
const target=(current===grouping.orderFolder?base:[...base,grouping.orderFolder]).join('/');segments(target);
|
||||
const area=await this.client.area(server),result=await area.archive(file,path.basename(file),target);
|
||||
return this.store.finishArchive(record.id,'success',{...result,...grouping,baseDirectory:directory,directory:target,serverName:server.name});
|
||||
}
|
||||
catch(e){const error=safe(e);this.store.finishArchive(record.id,'error',{error:error.message,serverName:server.name});throw error;}
|
||||
});
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user