mirror of
https://github.com/docmost/docmost.git
synced 2025-11-23 00:01:09 +10:00
copy storage function
This commit is contained in:
@ -25,6 +25,16 @@ export class LocalDriver implements StorageDriver {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async copy(fromFilePath: string, toFilePath: string): Promise<void> {
|
||||||
|
try {
|
||||||
|
if (await this.exists(fromFilePath)) {
|
||||||
|
await fs.copy(fromFilePath, toFilePath);
|
||||||
|
}
|
||||||
|
} catch (err) {
|
||||||
|
throw new Error(`Failed to copy file: ${(err as Error).message}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
async read(filePath: string): Promise<Buffer> {
|
async read(filePath: string): Promise<Buffer> {
|
||||||
try {
|
try {
|
||||||
return await fs.readFile(this._fullPath(filePath));
|
return await fs.readFile(this._fullPath(filePath));
|
||||||
|
|||||||
@ -1,5 +1,6 @@
|
|||||||
import { S3StorageConfig, StorageDriver, StorageOption } from '../interfaces';
|
import { S3StorageConfig, StorageDriver, StorageOption } from '../interfaces';
|
||||||
import {
|
import {
|
||||||
|
CopyObjectCommand,
|
||||||
DeleteObjectCommand,
|
DeleteObjectCommand,
|
||||||
GetObjectCommand,
|
GetObjectCommand,
|
||||||
HeadObjectCommand,
|
HeadObjectCommand,
|
||||||
@ -39,6 +40,22 @@ export class S3Driver implements StorageDriver {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async copy(fromFilePath: string, toFilePath: string): Promise<void> {
|
||||||
|
try {
|
||||||
|
if (await this.exists(fromFilePath)) {
|
||||||
|
await this.s3Client.send(
|
||||||
|
new CopyObjectCommand({
|
||||||
|
Bucket: this.config.bucket,
|
||||||
|
CopySource: `${this.config.bucket}/${fromFilePath}`,
|
||||||
|
Key: toFilePath,
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
} catch (err) {
|
||||||
|
throw new Error(`Failed to copy file: ${(err as Error).message}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
async read(filePath: string): Promise<Buffer> {
|
async read(filePath: string): Promise<Buffer> {
|
||||||
try {
|
try {
|
||||||
const command = new GetObjectCommand({
|
const command = new GetObjectCommand({
|
||||||
|
|||||||
@ -1,6 +1,8 @@
|
|||||||
export interface StorageDriver {
|
export interface StorageDriver {
|
||||||
upload(filePath: string, file: Buffer): Promise<void>;
|
upload(filePath: string, file: Buffer): Promise<void>;
|
||||||
|
|
||||||
|
copy(fromFilePath: string, toFilePath: string): Promise<void>;
|
||||||
|
|
||||||
read(filePath: string): Promise<Buffer>;
|
read(filePath: string): Promise<Buffer>;
|
||||||
|
|
||||||
exists(filePath: string): Promise<boolean>;
|
exists(filePath: string): Promise<boolean>;
|
||||||
|
|||||||
Reference in New Issue
Block a user