Lint errors
This commit is contained in:
parent
0c72d5a37c
commit
1d82c4ffb9
6 changed files with 102 additions and 97 deletions
|
|
@ -3,42 +3,42 @@ import { promises as fs } from "fs";
|
|||
import path from "path";
|
||||
|
||||
export class LocalStorageAdapter implements IStorageAdapter {
|
||||
private baseDir: string;
|
||||
private baseDir: string;
|
||||
|
||||
constructor(baseDir: string) {
|
||||
this.baseDir = baseDir;
|
||||
constructor(baseDir: string) {
|
||||
this.baseDir = baseDir;
|
||||
}
|
||||
|
||||
async save(key: string, data: Buffer): Promise<string> {
|
||||
const fullPath = path.join(this.baseDir, key);
|
||||
await fs.mkdir(path.dirname(fullPath), { recursive: true });
|
||||
await fs.writeFile(fullPath, data);
|
||||
return key;
|
||||
}
|
||||
|
||||
async get(key: string): Promise<Buffer> {
|
||||
const fullPath = path.join(this.baseDir, key);
|
||||
return fs.readFile(fullPath);
|
||||
}
|
||||
|
||||
async delete(key: string): Promise<void> {
|
||||
const fullPath = path.join(this.baseDir, key);
|
||||
try {
|
||||
await fs.unlink(fullPath);
|
||||
} catch (error) {
|
||||
const err = error as NodeJS.ErrnoException;
|
||||
if (err?.code === "ENOENT" || err?.code === "ENOTDIR") {
|
||||
return;
|
||||
}
|
||||
|
||||
console.error(`Failed to delete file at ${fullPath}: `, error);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
async save(key: string, data: Buffer): Promise<string> {
|
||||
const fullPath = path.join(this.baseDir, key);
|
||||
await fs.mkdir(path.dirname(fullPath), { recursive: true });
|
||||
await fs.writeFile(fullPath, data);
|
||||
return key;
|
||||
}
|
||||
|
||||
async get(key: string): Promise<Buffer> {
|
||||
const fullPath = path.join(this.baseDir, key);
|
||||
return fs.readFile(fullPath);
|
||||
}
|
||||
|
||||
async delete(key: string): Promise<void> {
|
||||
const fullPath = path.join(this.baseDir, key);
|
||||
try {
|
||||
await fs.unlink(fullPath);
|
||||
} catch (error) {
|
||||
const err = error as NodeJS.ErrnoException;
|
||||
if (err?.code === "ENOENT" || err?.code === "ENOTDIR") {
|
||||
return;
|
||||
}
|
||||
|
||||
console.error(`Failed to delete file at ${fullPath}: `, error);
|
||||
throw error
|
||||
}
|
||||
}
|
||||
|
||||
getStream(key: string): ReadableStream<Uint8Array> {
|
||||
const fullPath = path.join(this.baseDir, key);
|
||||
const file = Bun.file(fullPath);
|
||||
return file.stream();
|
||||
}
|
||||
}
|
||||
getStream(key: string): ReadableStream<Uint8Array> {
|
||||
const fullPath = path.join(this.baseDir, key);
|
||||
const file = Bun.file(fullPath);
|
||||
return file.stream();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue