({
repo,
integration,
config,
}: {
repo: StorageRepo;
integration: typeof Db.storageIntegrations.$inferSelect;
config: GoogleDriveIntegrationConfig;
})
| 333 | ); |
| 334 | |
| 335 | const makeGoogleDriveAccess = ({ |
| 336 | repo, |
| 337 | integration, |
| 338 | config, |
| 339 | }: { |
| 340 | repo: StorageRepo; |
| 341 | integration: typeof Db.storageIntegrations.$inferSelect; |
| 342 | config: GoogleDriveIntegrationConfig; |
| 343 | }) => { |
| 344 | const integrationId = integration.id; |
| 345 | const ownerId = integration.ownerId; |
| 346 | const tokenStore = makeGoogleDriveTokenStore(repo, integration); |
| 347 | |
| 348 | const getObjectRecord = (key: string) => |
| 349 | mapStorageError(requireDriveObject(repo, integrationId, key)); |
| 350 | const recoverDriveFileId = ( |
| 351 | key: string, |
| 352 | previous: typeof Db.storageObjects.$inferSelect, |
| 353 | ) => |
| 354 | findGoogleDriveFileByObjectKey(config, key, tokenStore).pipe( |
| 355 | Effect.flatMap( |
| 356 | Option.match({ |
| 357 | onNone: () => |
| 358 | Effect.fail( |
| 359 | new StorageDomain.StorageError({ |
| 360 | cause: new Error(`Google Drive object not found: ${key}`), |
| 361 | }), |
| 362 | ), |
| 363 | onSome: (file) => { |
| 364 | const videoId = parseObjectKeyVideoId(key); |
| 365 | const contentType = file.mimeType ?? previous.contentType; |
| 366 | return mapStorageError( |
| 367 | repo.upsertObject({ |
| 368 | integrationId, |
| 369 | ownerId, |
| 370 | videoId, |
| 371 | objectKey: key, |
| 372 | providerObjectId: file.id, |
| 373 | uploadStatus: "complete", |
| 374 | contentType, |
| 375 | contentLength: |
| 376 | parseGoogleDriveContentLength(file) ?? |
| 377 | previous.contentLength ?? |
| 378 | null, |
| 379 | metadata: { |
| 380 | ...(previous.metadata ?? {}), |
| 381 | videoId: videoId ?? previous.metadata?.videoId, |
| 382 | fileName: file.name ?? previous.metadata?.fileName, |
| 383 | contentType: file.mimeType ?? previous.metadata?.contentType, |
| 384 | }, |
| 385 | }), |
| 386 | ).pipe(Effect.as(file.id)); |
| 387 | }, |
| 388 | }), |
| 389 | ), |
| 390 | ); |
| 391 | const withRecoveredDriveFile = <A>( |
| 392 | key: string, |
no test coverage detected