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

Function recoverDriveFileId

packages/web-backend/src/Storage/index.ts:350–390  ·  view source on GitHub ↗
(
		key: string,
		previous: typeof Db.storageObjects.$inferSelect,
	)

Source from the content-addressed store, hash-verified

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,
393 object: typeof Db.storageObjects.$inferSelect,

Callers 1

withRecoveredDriveFileFunction · 0.85

Calls 4

parseObjectKeyVideoIdFunction · 0.85
mapStorageErrorFunction · 0.85

Tested by

no test coverage detected