Skip to content

Commit

Permalink
fix fetch id and increase timeout
Browse files Browse the repository at this point in the history
  • Loading branch information
Richard Xiong committed Nov 21, 2024
1 parent 65394d7 commit 2153937
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 17 deletions.
9 changes: 6 additions & 3 deletions helpers/drive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ type StringSearch = string | { contains: string } | { not: string };
type DateComparison = { eq: string } | { gt: string } | { lt: string };

interface QueryMatch {
id?: string;
name?: StringSearch | StringSearch[];
mimeType?: StringSearch | StringSearch[];
parent?: string;
Expand All @@ -36,7 +35,6 @@ const stringSearchToQuery = (search: StringSearch) => {
};

const queryHandlers = {
id: (id: string) => `id='${id}'`,
name: (name: StringSearch) => "name" + stringSearchToQuery(name),
mimeType: (mimeType: StringSearch) =>
"mimeType" + stringSearchToQuery(mimeType),
Expand Down Expand Up @@ -312,7 +310,11 @@ export const getDriveClient = (t: ObsidianGoogleDrive) => {
return true;
};

const getFile = (id: string) => drive.get(`drive/v3/files/${id}?alt=media`);
const getFile = (id: string) =>
drive.get(`drive/v3/files/${id}?alt=media&acknowledgeAbuse=true`);

const getFileMetadata = (id: string) =>
drive.get(`drive/v3/files/${id}`).json<FileMetadata>();

const idFromPath = async (path: string) => {
const files = await searchFiles({
Expand Down Expand Up @@ -448,6 +450,7 @@ export const getDriveClient = (t: ObsidianGoogleDrive) => {
updateFileMetadata,
deleteFile,
getFile,
getFileMetadata,
idFromPath,
idsFromPaths,
getChangesStartToken,
Expand Down
1 change: 1 addition & 0 deletions helpers/ky.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export const getDriveKy = (t: ObsidianGoogleDrive) => {
return ky.extend({
prefixUrl: "https://www.googleapis.com",
hooks: getHooks(t),
timeout: 120_000,
});
};

Expand Down
9 changes: 3 additions & 6 deletions helpers/push.ts
Original file line number Diff line number Diff line change
Expand Up @@ -244,15 +244,12 @@ class ConfirmUndoModal extends Modal {

const [onlineFile, metadata] = await Promise.all([
this.t.drive.getFile(this.filePathToId[path]).arrayBuffer(),
this.t.drive.searchFiles({
matches: [{ id: this.filePathToId[path] }],
include: ["modifiedTime"],
}),
this.t.drive.getFileMetadata(this.filePathToId[path]),
]);
if (!onlineFile || !metadata || !metadata.length) {
if (!onlineFile || !metadata) {
return new Notice("An error occurred fetching Google Drive files.");
}
return this.t.modifyFile(file, onlineFile, metadata[0].modifiedTime);
return this.t.modifyFile(file, onlineFile, metadata.modifiedTime);
}
}

Expand Down
9 changes: 3 additions & 6 deletions helpers/reset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,9 @@ export const reset = async (t: ObsidianGoogleDrive) => {
files.map((file) => async () => {
const [onlineFile, metadata] = await Promise.all([
t.drive.getFile(filePathToId[file.path]).arrayBuffer(),
t.drive.searchFiles({
matches: [{ id: filePathToId[file.path] }],
include: ["modifiedTime"],
}),
t.drive.getFileMetadata(filePathToId[file.path]),
]);
if (!onlineFile || !metadata || !metadata.length) {
if (!onlineFile || !metadata) {
return new Notice(
"An error occurred fetching Google Drive files."
);
Expand All @@ -62,7 +59,7 @@ export const reset = async (t: ObsidianGoogleDrive) => {
syncNotice.setMessage(
getSyncMessage(33, 66, completed, files.length)
);
return t.modifyFile(file, onlineFile, metadata[0].modifiedTime);
return t.modifyFile(file, onlineFile, metadata.modifiedTime);
})
);
}
Expand Down
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"id": "google-drive-sync",
"name": "Google Drive Sync",
"version": "2.2.0",
"version": "2.2.1",
"minAppVersion": "1.6.0",
"description": "Syncs a vault into Google Drive for cross-platform use (works for iOS).",
"author": "Richard Xiong",
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "google-drive-sync",
"version": "2.2.0",
"version": "2.2.1",
"description": "This plugin allows for the use of Google Drive in syncing an Obsidian vault.",
"main": "main.js",
"scripts": {
Expand Down

0 comments on commit 2153937

Please sign in to comment.