MCPcopy Index your code
hub / github.com/CapSoftware/Cap / Storage

Class Storage

packages/web-backend/src/Storage/index.ts:745–949  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

743};
744
745export class Storage extends Effect.Service<Storage>()("Storage", {
746 effect: Effect.gen(function* () {
747 const repo = yield* StorageRepo;
748 const s3Buckets = yield* S3Buckets;
749
750 const getS3WritableAccessForUser = Effect.fn(
751 "Storage.getS3WritableAccessForUser",
752 )(function* (
753 userId: User.UserId,
754 organizationId?: Organisation.OrganisationId,
755 ) {
756 if (organizationId) {
757 const organizationBucket = yield* mapStorageError(
758 s3Buckets.getBucketAccessForOrganization(organizationId),
759 );
760
761 if (Option.isSome(organizationBucket)) {
762 const [s3, customBucket] = organizationBucket.value;
763 return {
764 access: makeS3Access(s3),
765 bucketId: Option.map(customBucket, (bucket) => bucket.id),
766 storageIntegrationId: Option.none(),
767 };
768 }
769 }
770
771 const [s3, customBucket] = yield* mapStorageError(
772 s3Buckets.getBucketAccessForUser(userId),
773 );
774 return {
775 access: makeS3Access(s3),
776 bucketId: Option.map(customBucket, (bucket) => bucket.id),
777 storageIntegrationId: Option.none(),
778 };
779 });
780
781 const getDriveAccess = Effect.fn("Storage.getDriveAccess")(function* (
782 integrationId: StorageDomain.StorageIntegrationId,
783 ) {
784 const integration = yield* mapStorageError(
785 repo.getIntegrationById(integrationId),
786 ).pipe(
787 Effect.flatMap(
788 Option.match({
789 onNone: () =>
790 Effect.fail(
791 new StorageDomain.StorageError({
792 cause: new Error("Storage integration not found"),
793 }),
794 ),
795 onSome: Effect.succeed,
796 }),
797 ),
798 );
799 const config = yield* mapStorageError(
800 repo.getGoogleDriveConfig(integration),
801 );
802 return makeGoogleDriveAccess({ repo, integration, config });

Callers

nothing calls this directly

Calls 3

mapStorageErrorFunction · 0.85
makeS3AccessFunction · 0.85
makeGoogleDriveAccessFunction · 0.85

Tested by

no test coverage detected