mirror of
https://codeberg.org/yeentown/barkey
synced 2024-11-25 08:15:12 +00:00
pre-create the files
directory to reduce IO operations
This commit is contained in:
parent
2deb64486b
commit
b1d9314d6e
1 changed files with 2 additions and 2 deletions
|
@ -24,6 +24,8 @@ export class InternalStorageService {
|
||||||
@Inject(DI.config)
|
@Inject(DI.config)
|
||||||
private config: Config,
|
private config: Config,
|
||||||
) {
|
) {
|
||||||
|
// No one should erase the working directly *while the server is running*.
|
||||||
|
fs.mkdirSync(path, { recursive: true });
|
||||||
}
|
}
|
||||||
|
|
||||||
@bindThis
|
@bindThis
|
||||||
|
@ -38,14 +40,12 @@ export class InternalStorageService {
|
||||||
|
|
||||||
@bindThis
|
@bindThis
|
||||||
public async saveFromPath(key: string, srcPath: string): Promise<string> {
|
public async saveFromPath(key: string, srcPath: string): Promise<string> {
|
||||||
await mkdir(path, { recursive: true });
|
|
||||||
await copyFile(srcPath, this.resolvePath(key));
|
await copyFile(srcPath, this.resolvePath(key));
|
||||||
return `${this.config.url}/files/${key}`;
|
return `${this.config.url}/files/${key}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
@bindThis
|
@bindThis
|
||||||
public async saveFromBuffer(key: string, data: Buffer): Promise<string> {
|
public async saveFromBuffer(key: string, data: Buffer): Promise<string> {
|
||||||
await mkdir(path, { recursive: true });
|
|
||||||
await writeFile(this.resolvePath(key), data);
|
await writeFile(this.resolvePath(key), data);
|
||||||
return `${this.config.url}/files/${key}`;
|
return `${this.config.url}/files/${key}`;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue