From f6b9aba0b8eba2e9f0da01fde77c474a95fd8591 Mon Sep 17 00:00:00 2001 From: Josh Moore Date: Fri, 14 Jul 2023 18:15:20 -0600 Subject: [PATCH] feat: added basic S3 structure kind of --- backend/s3.ts | 37 ++++++++++++++++++++++++++++++++++--- common/types.d.ts | 30 +++++++++++++++++++++++++++++- 2 files changed, 63 insertions(+), 4 deletions(-) diff --git a/backend/s3.ts b/backend/s3.ts index 103b718..d98c276 100644 --- a/backend/s3.ts +++ b/backend/s3.ts @@ -1,14 +1,45 @@ +import { ReadStream } from 'fs'; +import { UserConfig } from './UserConfig'; +import { log } from './log'; +import { AssFile } from 'ass'; + +const NYI = 'Not yet implemented'; +const NYR = 'S3 not ready'; +const s3readyCheck = (): boolean => UserConfig.ready && UserConfig.config.s3 != null; + /** * Uploads a file to your configured S3 provider */ -export const uploadFileS3 = () => { } +export const uploadFileS3 = (file: ReadStream, metadata: AssFile): Promise => new Promise((resolve, reject) => { + if (!s3readyCheck) return reject(NYR); + + // todo: S3 upload logic + metadata.filename; + metadata.mimetype; + metadata.sha256; + + log.warn('S3 Upload', NYI); + reject(NYI); +}); /** * Gets a file from your configured S3 provider */ -export const getFileS3 = () => { } +export const getFileS3 = (): Promise => new Promise((resolve, reject) => { + if (!s3readyCheck) return reject(NYR); + + // todo: S3 get logic + + log.warn('S3 Get', NYI); + reject(NYI); +}); /** * Deletes a file from your configured S3 provider */ -export const deleteFileS3 = () => { } +export const deleteFileS3 = (): Promise => new Promise((resolve, reject) => { + if (!s3readyCheck) return reject(NYR); + + log.warn('S3 Delete', NYI); + reject(NYI); +}); diff --git a/common/types.d.ts b/common/types.d.ts index 46b3cc3..9f43341 100644 --- a/common/types.d.ts +++ b/common/types.d.ts @@ -19,6 +19,30 @@ declare module 'ass' { idSize: number; gfySize: number; maximumFileSize: number; + + s3?: S3Configuration; + } + + interface S3Configuration { + /** + * S3 endpoint to use + */ + endpoint: string; + /** + * Bucket to upload to + */ + bucket: string; + /** + * Optional region. Required for some providers + */ + region?: string; + /** + * Access credentials + */ + credentials: { + accessKey: string; + secretKey: string; + } } interface UserConfigTypeChecker { @@ -47,7 +71,11 @@ declare module 'ass' { filename: string; save: { local?: string; - s3?: any; + s3?: { + privateUrl?: string; + publicUrl?: string; + thumbnailUrl?: string; + } } sha256: string; timestamp: string;