Skip to content

Commit

Permalink
Fixed copying of files
Browse files Browse the repository at this point in the history
  • Loading branch information
marekdedic committed Oct 10, 2024
1 parent b8e4654 commit 30e95bf
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/backend/utils/DriveBackedValue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export class DriveBackedValue_<T> {

private getExistingDriveFileContents(fileId: string): T {
return JSON.parse(
this.driveService.Files.get(fileId, null, { alt: "media" }) as string,
this.driveService.Files.get(fileId, null, { alt: "media" as const }),
) as T;
}

Expand Down
22 changes: 17 additions & 5 deletions src/backend/utils/SafeDriveService/SafeFilesCollection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,15 @@ const safeFileKeys: DeepKeyof<SafeFile> = {
},
};

interface GetArg {
alt?: string;
}
type GetReturn<F extends DeepKeyof<SafeFile>, A extends GetArg> = A extends {
alt: "media";
}
? string
: DeepPick<SafeFile, F>;

export interface SafeFileList<F extends DeepKeyof<SafeFile>> {
items: Array<DeepPick<SafeFile, F>>;
nextPageToken?: string | undefined;
Expand Down Expand Up @@ -121,21 +130,24 @@ export class SafeFilesCollection_ {
return ret;
}

public get<F extends DeepKeyof<SafeFile>>(
public get<F extends DeepKeyof<SafeFile>, A extends GetArg>(
fileId: string,
fields: F | null,
optionalArgs: { alt?: string } = {},
): DeepPick<SafeFile, F> {
optionalArgs: A = {} as A,
): GetReturn<F, A> {
const ret = this.unsafeFiles.get(fileId, {
...optionalArgs,
...(fields !== null && {
fields: stringifyFields_(fields),
}),
});
if (!SafeFilesCollection_.fileIsSafe(ret, fields)) {
if (
typeof ret !== "string" &&
!SafeFilesCollection_.fileIsSafe(ret, fields)
) {
throw new Error("");
}
return ret;
return ret as unknown as GetReturn<F, A>;
}

public insert<F extends DeepKeyof<SafeFile>>(
Expand Down

0 comments on commit 30e95bf

Please sign in to comment.