Skip to content
This repository was archived by the owner on Sep 9, 2025. It is now read-only.

Commit eb7016a

Browse files
authored
Merge pull request #2189 from pekarja5/cache-loading-fix
Fixed JSON cache loading
2 parents 65832f9 + 151a9b8 commit eb7016a

File tree

3 files changed

+11
-8
lines changed

3 files changed

+11
-8
lines changed

src/backend/utils/DriveBackedValue.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,9 @@ export class DriveBackedValue_<T> {
7575
}
7676

7777
private getExistingDriveFileContents(fileId: string): T {
78-
return JSON.parse(
79-
this.driveService.Files.get(fileId, null, { alt: "media" as const }),
80-
) as T;
78+
return this.driveService.Files.get(fileId, null, {
79+
alt: "media" as const,
80+
}) as T;
8181
}
8282

8383
private getExistingDriveFileId(folderId: string): string | null {

src/backend/utils/SafeDriveService/SafeFilesCollection.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@ interface GetArg {
4848
type GetReturn<F extends DeepKeyof<SafeFile>, A extends GetArg> = A extends {
4949
alt: "media";
5050
}
51-
? string
51+
? // eslint-disable-next-line @typescript-eslint/no-explicit-any -- Raw file can contain anything
52+
any
5253
: DeepPick<SafeFile, F>;
5354

5455
function fileIsSafe_<F extends DeepKeyof<SafeFile>>(
@@ -144,9 +145,13 @@ export const SafeFilesCollection_ = {
144145
fields: stringifyFields_(fields),
145146
}),
146147
});
147-
if (typeof ret !== "string" && !fileIsSafe_(ret, fields)) {
148+
if (
149+
!("alt" in optionalArgs && optionalArgs.alt === "media") &&
150+
!fileIsSafe_(ret, fields)
151+
) {
148152
throw new Error("Files.get: File is not safe.");
149153
}
154+
// eslint-disable-next-line @typescript-eslint/no-unsafe-return -- Raw file can contain anything
150155
return ret as unknown as GetReturn<F, A>;
151156
},
152157

tests/backend/utils/DriveBackedValue.test.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -377,9 +377,7 @@ test("DriveBackedValue loads a value - the folder exists, the value exists", ()
377377
],
378378
};
379379
const driveServiceMock = mockedSafeDriveService();
380-
vi.mocked(driveServiceMock.Files.get).mockReturnValueOnce(
381-
JSON.stringify("VALUE"),
382-
);
380+
vi.mocked(driveServiceMock.Files.get).mockReturnValueOnce("VALUE");
383381
vi.mocked(driveServiceMock.Files.list)
384382
.mockReturnValueOnce(response1)
385383
.mockReturnValueOnce(response2);

0 commit comments

Comments
 (0)