|
@@ -11,11 +11,8 @@ export class FileService {
|
|
@Config('export.root_path')
|
|
@Config('export.root_path')
|
|
root_path;
|
|
root_path;
|
|
|
|
|
|
- @Config('export.file_type')
|
|
|
|
- file_type;
|
|
|
|
-
|
|
|
|
- async upload(files, fields) {
|
|
|
|
- const path = `${this.root_path}${sep}${this.file_type}`;
|
|
|
|
|
|
+ async upload(files, fields, route) {
|
|
|
|
+ const path = `${this.root_path}${sep}${route}`;
|
|
if (!path) {
|
|
if (!path) {
|
|
throw new ServiceError(
|
|
throw new ServiceError(
|
|
'服务端没有设置存储路径',
|
|
'服务端没有设置存储路径',
|
|
@@ -34,10 +31,16 @@ export class FileService {
|
|
await sharp(val.data)
|
|
await sharp(val.data)
|
|
.toFormat('jpg', { mozjpeg: true })
|
|
.toFormat('jpg', { mozjpeg: true })
|
|
.toFile(`${filePath}${filename}.jpg`);
|
|
.toFile(`${filePath}${filename}.jpg`);
|
|
|
|
+ const dirs = [];
|
|
|
|
+ if (route && route !== '_') {
|
|
|
|
+ const subs = route.split('_');
|
|
|
|
+ dirs.push(...subs);
|
|
|
|
+ }
|
|
|
|
+ const uri = `/files/${dirs.join('/')}/${filename}.jpg`;
|
|
return {
|
|
return {
|
|
id: filename,
|
|
id: filename,
|
|
name: `${filename}.jpg`,
|
|
name: `${filename}.jpg`,
|
|
- uri: `/files/${path}/${filename}.jpg`,
|
|
|
|
|
|
+ uri,
|
|
};
|
|
};
|
|
}
|
|
}
|
|
}
|
|
}
|