| 743 | }; |
| 744 | |
| 745 | export 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 }); |
nothing calls this directly
no test coverage detected