feat: save files

This commit is contained in:
xiaojunnuo
2023-06-25 23:45:13 +08:00
parent 671d273e2f
commit 99522fb49a
3 changed files with 20 additions and 5 deletions
@@ -28,11 +28,16 @@ export class FileStore {
writeFile(filename: string, file: Buffer) {
const localPath = this.buildFilePath(filename);
fs.writeFileSync(localPath, file);
return localPath;
}
private buildFilePath(filename: string) {
return path.join(this.rootDir, this.scope, dayjs().format("YYYY-MM-DD"), this.parent, filename);
const parentDir = path.join(this.rootDir, this.scope + "", dayjs().format("YYYY-MM-DD"), this.parent + "");
if (!fs.existsSync(parentDir)) {
fs.mkdirSync(parentDir, { recursive: true });
}
return path.join(parentDir, filename);
}
}