mirror of
https://github.com/hanzo-apps/dataroom.git
synced 2026-10-30 14:47:36 +00:00
features/storage/ was Papermark's ee/features/storage — commercial-licensed
code that commit 98f0da7fa renamed out of ee/ byte-identical rather than
deleting, leaving it under our AGPL root licence. Deleted and rewritten.
lib/storage/config.ts resolves one bucket from the environment. The upstream
version carried a hardcoded EU/US region matrix selected by the `usStorage`
feature flag; that flag is served by @vercel/edge-config, is false whenever
EDGE_CONFIG is unset, and no per-document region is persisted anywhere in the
schema — so the second region was unreachable on our deployments. Required
vars now throw at the boundary instead of resolving a partial config.
lib/storage/tus-store.ts builds a plain S3Store. MultiRegionS3Store subclassed
it and reassigned this.client/this.bucket per request on a shared instance, so
two concurrent uploads from different teams could observe each other's bucket.
Construction-time config removes the race. It also now forwards the endpoint,
so resumable uploads reach S3-compatible backends.
lib/files/aws-client.ts collapses to two functions: with one config the
team/non-team split was duplication, and getS3Client, getS3ClientForTeam and
getLambdaClient had no callers outside the module.
LICENSE: drop the carve-out clause pointing at ee/LICENSE and app/(ee) —
both directories are gone, so the pointer dangled. Papermark's copyright
line and the AGPL-3.0 text are untouched.
Co-authored-by: Hanzo Dev <[email protected]>
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 { getS3ClientAndConfig } 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 } = getS3ClientAndConfig();
|
|
|
|
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,
|
|
};
|
|
}
|
|
};
|