mirror of
https://github.com/documenso/documenso.git
synced 2025-11-10 04:22:32 +10:00
Implementation of a universal upload allowing for multiple storage backends starting with `database` and `s3`. Allows clients to put and retrieve files from either client or server using a blend of client and server actions.
23 lines
530 B
TypeScript
23 lines
530 B
TypeScript
import { match } from 'ts-pattern';
|
|
|
|
import { DocumentDataType } from '@documenso/prisma/client';
|
|
|
|
import { deleteS3File } from './server-actions';
|
|
|
|
export type DeleteFileOptions = {
|
|
type: DocumentDataType;
|
|
data: string;
|
|
};
|
|
|
|
export const deleteFile = async ({ type, data }: DeleteFileOptions) => {
|
|
return await match(type)
|
|
.with(DocumentDataType.S3_PATH, async () => deleteFileFromS3(data))
|
|
.otherwise(() => {
|
|
return;
|
|
});
|
|
};
|
|
|
|
const deleteFileFromS3 = async (key: string) => {
|
|
await deleteS3File(key);
|
|
};
|