mirror of
https://github.com/certd/certd.git
synced 2026-04-24 04:17:25 +08:00
feat: save files
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user