|
@@ -6,15 +6,18 @@ import * as Path from 'node:path';
|
|
|
const moment = require('moment');
|
|
|
const sharp = require('sharp');
|
|
|
const sep = Path.sep;
|
|
|
+const assert = require('assert');
|
|
|
@Provide()
|
|
|
export class FileService {
|
|
|
@Config('export.root_path')
|
|
|
root_path;
|
|
|
|
|
|
- async upload(files, fields, route) {
|
|
|
- const dirs = [];
|
|
|
- if (route && route !== '_') {
|
|
|
- const subs = route.split('_');
|
|
|
+ async upload(files, fields, params) {
|
|
|
+ const { appid, catalog, item } = params;
|
|
|
+ assert(appid);
|
|
|
+ const dirs = [appid];
|
|
|
+ if (catalog && catalog !== '_') {
|
|
|
+ const subs = catalog.split('_');
|
|
|
dirs.push(...subs);
|
|
|
}
|
|
|
const rootPath = `${this.root_path}${sep}`;
|
|
@@ -37,10 +40,11 @@ export class FileService {
|
|
|
}
|
|
|
// TODO: 指定文件名或者按时间生成文件名
|
|
|
// const name = moment().format('YYYYMMDDHHmmss');
|
|
|
- const path = `${rootPath}${sep}${dirs.join(sep)}${sep}`;
|
|
|
- const filePath = `${path}${sep}`;
|
|
|
+ const path = `${rootPath}${dirs.join(sep)}${sep}`;
|
|
|
+ const filePath = `${path}`;
|
|
|
for (const val of files) {
|
|
|
- const filename = moment().format('YYYYMMDDHHmmss');
|
|
|
+ let filename = item;
|
|
|
+ if (!item) filename = moment().format('YYYYMMDDHHmmss');
|
|
|
await sharp(val.data)
|
|
|
.toFormat('jpg', { mozjpeg: true })
|
|
|
.toFile(`${filePath}${filename}.jpg`);
|