MCPcopy
hub / github.com/CapSoftware/Cap / makeGoogleDriveAccess

Function makeGoogleDriveAccess

packages/web-backend/src/Storage/index.ts:335–735  ·  view source on GitHub ↗
({
	repo,
	integration,
	config,
}: {
	repo: StorageRepo;
	integration: typeof Db.storageIntegrations.$inferSelect;
	config: GoogleDriveIntegrationConfig;
})

Source from the content-addressed store, hash-verified

333 );
334
335const 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,

Callers 1

StorageClass · 0.85

Calls 15

getGoogleDriveObjectTextFunction · 0.90
copyGoogleDriveFileFunction · 0.90
deleteGoogleDriveFileFunction · 0.90
getObjectRecordFunction · 0.85
mapStorageErrorFunction · 0.85
createDriveObjectUrlFunction · 0.85
withRecoveredDriveFileFunction · 0.85

Tested by

no test coverage detected