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

Function copyGoogleDriveFile

packages/web-backend/src/Storage/GoogleDrive.ts:1205–1264  ·  view source on GitHub ↗
({
	repo,
	config,
	sourceFileId,
	input,
	tokenStore,
}: {
	repo: StorageRepo;
	config: GoogleDriveIntegrationConfig;
	sourceFileId: string;
	input: CreateGoogleDriveUploadInput;
	tokenStore?: GoogleDriveTokenStore;
})

Source from the content-addressed store, hash-verified

1203 ).pipe(Effect.asVoid);
1204
1205export const copyGoogleDriveFile = ({
1206 repo,
1207 config,
1208 sourceFileId,
1209 input,
1210 tokenStore,
1211}: {
1212 repo: StorageRepo;
1213 config: GoogleDriveIntegrationConfig;
1214 sourceFileId: string;
1215 input: CreateGoogleDriveUploadInput;
1216 tokenStore?: GoogleDriveTokenStore;
1217}) =>
1218 Effect.gen(function* () {
1219 const parentId = yield* getGoogleDriveUploadParentId(
1220 repo,
1221 config,
1222 input,
1223 tokenStore,
1224 );
1225 const response = yield* driveFetch(
1226 config,
1227 appendSharedDriveCreateParams(
1228 `${DRIVE_API_BASE}/files/${encodeURIComponent(sourceFileId)}/copy?fields=id,name,mimeType,size`,
1229 ),
1230 {
1231 method: "POST",
1232 headers: { "Content-Type": "application/json" },
1233 body: JSON.stringify({
1234 name: getDriveFileName(input.key),
1235 parents: [parentId],
1236 appProperties: {
1237 capObjectKey: input.key,
1238 },
1239 }),
1240 },
1241 tokenStore,
1242 );
1243 const copied = yield* Effect.tryPromise({
1244 try: () => parseDriveJson<GoogleDriveFile>(response),
1245 catch: (cause) => new Storage.StorageError({ cause }),
1246 });
1247 if (!copied.id) {
1248 return yield* Effect.fail(
1249 new Storage.StorageError({
1250 cause: new Error("Google Drive copy did not return an id"),
1251 }),
1252 );
1253 }
1254 yield* repo.upsertObject({
1255 integrationId: input.integrationId,
1256 ownerId: input.ownerId,
1257 videoId: input.videoId,
1258 objectKey: input.key,
1259 providerObjectId: copied.id,
1260 uploadStatus: "complete",
1261 contentType: copied.mimeType ?? input.contentType,
1262 contentLength: copied.size ? Number(copied.size) : null,

Callers 1

makeGoogleDriveAccessFunction · 0.90

Calls 5

driveFetchFunction · 0.85
getDriveFileNameFunction · 0.85
parseDriveJsonFunction · 0.85

Tested by

no test coverage detected