update
This commit is contained in:
32
assistant/src/module/upload/mv.ts
Normal file
32
assistant/src/module/upload/mv.ts
Normal file
@@ -0,0 +1,32 @@
|
||||
import type { AssistantConfig } from '@/module/assistant/index.ts';
|
||||
import fs from 'node:fs';
|
||||
import path from 'node:path';
|
||||
export class UploadManager {
|
||||
config: AssistantConfig;
|
||||
constructor(config: AssistantConfig) {
|
||||
this.config = config;
|
||||
}
|
||||
mvFile(opts: {
|
||||
temppath: string;
|
||||
type: 'file' | 's3';
|
||||
targetPath: string;
|
||||
}) {
|
||||
const { type, temppath, targetPath } = opts;
|
||||
if (type === 'file') {
|
||||
const pageDir = this.config.configPath?.pagesDir!;
|
||||
const fullTargetPath = targetPath.startsWith('/')
|
||||
? targetPath
|
||||
: path.join(pageDir, targetPath);
|
||||
const targetDir = fullTargetPath.substring(0, fullTargetPath.lastIndexOf('/'));
|
||||
if (!fs.existsSync(targetDir)) {
|
||||
fs.mkdirSync(targetDir, { recursive: true });
|
||||
}
|
||||
fs.renameSync(temppath, fullTargetPath);
|
||||
return fullTargetPath;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export const uploadManager = (config: AssistantConfig) => {
|
||||
return new UploadManager(config);
|
||||
}
|
||||
Reference in New Issue
Block a user