Skip to content

armgit / Cap

Public Imported from GitHub
0

Open source Loom alternative. Beautiful, shareable screen recordings.

refactor(storage): expose getS3WritableAccessForUser helper

Richie McIlroy46abf6bdd826
diff --git a/packages/web-backend/src/Storage/index.ts b/packages/web-backend/src/Storage/index.ts
index c6263bb88..391e92a41 100644
--- a/packages/web-backend/src/Storage/index.ts
+++ b/packages/web-backend/src/Storage/index.ts
@@ -637,6 +637,19 @@ export class Storage extends Effect.Service<Storage>()("Storage", {
const repo = yield* StorageRepo;
const s3Buckets = yield* S3Buckets;
+ const getS3WritableAccessForUser = Effect.fn(
+ "Storage.getS3WritableAccessForUser",
+ )(function* (userId: User.UserId) {
+ const [s3, customBucket] = yield* mapStorageError(
+ s3Buckets.getBucketAccessForUser(userId),
+ );
+ return {
+ access: makeS3Access(s3),
+ bucketId: Option.map(customBucket, (bucket) => bucket.id),
+ storageIntegrationId: Option.none(),
+ };
+ });
+
const getDriveAccess = Effect.fn("Storage.getDriveAccess")(function* (
integrationId: StorageDomain.StorageIntegrationId,
) {
@@ -676,14 +689,7 @@ export class Storage extends Effect.Service<Storage>()("Storage", {
};
}
- const [s3, customBucket] = yield* mapStorageError(
- s3Buckets.getBucketAccessForUser(userId),
- );
- return {
- access: makeS3Access(s3),
- bucketId: Option.map(customBucket, (bucket) => bucket.id),
- storageIntegrationId: Option.none(),
- };
+ return yield* getS3WritableAccessForUser(userId);
});
const getAccessForVideo = Effect.fn("Storage.getAccessForVideo")(function* (
@@ -716,6 +722,7 @@ export class Storage extends Effect.Service<Storage>()("Storage", {
});
return {
+ getS3WritableAccessForUser,
getWritableAccessForUser,
getAccessForVideo,
createUploadTargetForUser,
@@ -728,6 +735,10 @@ export class Storage extends Effect.Service<Storage>()("Storage", {
Effect.flatMap(Storage, (storage) =>
storage.getWritableAccessForUser(userId),
);
+ static getS3WritableAccessForUser = (userId: User.UserId) =>
+ Effect.flatMap(Storage, (storage) =>
+ storage.getS3WritableAccessForUser(userId),
+ );
static getAccessForVideo = (video: Video.Video) =>
Effect.flatMap(Storage, (storage) => storage.getAccessForVideo(video));
static createUploadTargetForUser = (