mirror of
https://github.com/hanzoai/dataroom.git
synced 2026-10-30 18:41:07 +00:00
Introduces team-specific S3 storage configuration and multi-region support, allowing teams to use either EU or US S3 buckets based on feature flags. Refactors file operations (upload, copy, delete, presigned URLs, Lambda invocations) to resolve storage region and credentials per team. Adds new storage config and multi-region S3Store, updates API routes and utility functions to use team-aware clients, and extends feature flags with 'usStorage'.
60 lines
1.2 KiB
TypeScript
60 lines
1.2 KiB
TypeScript
import { CopyObjectCommand, ListObjectsV2Command } from "@aws-sdk/client-s3";
|
|
import { DocumentStorageType } from "@prisma/client";
|
|
import { match } from "ts-pattern";
|
|
|
|
import { getTeamS3ClientAndConfig } from "./aws-client";
|
|
|
|
export const copyFileToBucketServer = async ({
|
|
filePath,
|
|
storageType,
|
|
teamId,
|
|
}: {
|
|
filePath: string;
|
|
storageType: DocumentStorageType;
|
|
teamId: string;
|
|
}) => {
|
|
const { type, data } = await match(storageType)
|
|
.with("S3_PATH", async () =>
|
|
copyFileToBucketInS3Server({ filePath, teamId }),
|
|
)
|
|
.otherwise(() => {
|
|
return {
|
|
type: null,
|
|
data: null,
|
|
};
|
|
});
|
|
|
|
return { type, data };
|
|
};
|
|
|
|
const copyFileToBucketInS3Server = async ({
|
|
filePath,
|
|
teamId,
|
|
}: {
|
|
filePath: string;
|
|
teamId: string;
|
|
}) => {
|
|
const { client, config } = await getTeamS3ClientAndConfig(teamId);
|
|
|
|
try {
|
|
const copyCommand = new CopyObjectCommand({
|
|
CopySource: `${config.bucket}/${filePath}`,
|
|
Bucket: config.advancedBucket,
|
|
Key: filePath,
|
|
});
|
|
|
|
await client.send(copyCommand);
|
|
|
|
return {
|
|
type: DocumentStorageType.S3_PATH,
|
|
data: filePath,
|
|
};
|
|
} catch (error) {
|
|
console.error(error);
|
|
return {
|
|
type: null,
|
|
data: null,
|
|
};
|
|
}
|
|
};
|