mirror of
https://github.com/docmost/docmost.git
synced 2026-05-07 06:23:06 +08:00
error handling
This commit is contained in:
@@ -66,25 +66,25 @@ export class LocalDriver implements StorageDriver {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async readStream(filePath: string): Promise<Readable> {
|
async readStream(filePath: string): Promise<Readable> {
|
||||||
try {
|
const fullPath = this._fullPath(filePath);
|
||||||
return createReadStream(this._fullPath(filePath));
|
if (!(await fs.pathExists(fullPath))) {
|
||||||
} catch (err) {
|
throw new Error(`File not found: ${filePath}`);
|
||||||
throw new Error(`Failed to read file: ${(err as Error).message}`);
|
|
||||||
}
|
}
|
||||||
|
return createReadStream(fullPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
async readRangeStream(
|
async readRangeStream(
|
||||||
filePath: string,
|
filePath: string,
|
||||||
range: { start: number; end: number },
|
range: { start: number; end: number },
|
||||||
): Promise<Readable> {
|
): Promise<Readable> {
|
||||||
try {
|
const fullPath = this._fullPath(filePath);
|
||||||
return createReadStream(this._fullPath(filePath), {
|
if (!(await fs.pathExists(fullPath))) {
|
||||||
start: range.start,
|
throw new Error(`File not found: ${filePath}`);
|
||||||
end: range.end,
|
|
||||||
});
|
|
||||||
} catch (err) {
|
|
||||||
throw new Error(`Failed to read file: ${(err as Error).message}`);
|
|
||||||
}
|
}
|
||||||
|
return createReadStream(fullPath, {
|
||||||
|
start: range.start,
|
||||||
|
end: range.end,
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
async exists(filePath: string): Promise<boolean> {
|
async exists(filePath: string): Promise<boolean> {
|
||||||
|
|||||||
Reference in New Issue
Block a user