Skip to content

Commit

Permalink
fix date
Browse files Browse the repository at this point in the history
  • Loading branch information
Richard Xiong committed Nov 9, 2024
1 parent 4be5aff commit ef4e7a3
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
13 changes: 6 additions & 7 deletions helpers/drive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export interface FileMetadata {
}

type StringSearch = string | { contains: string } | { not: string };
type NumberComparison = number | { gt: number } | { lt: number };
type DateComparison = { eq: string } | { gt: string } | { lt: string };

interface QueryMatch {
name?: StringSearch | StringSearch[];
Expand All @@ -23,7 +23,7 @@ interface QueryMatch {
starred?: boolean;
query?: string;
properties?: Record<string, string>;
modifiedTime?: NumberComparison;
modifiedTime?: DateComparison;
}

export const folderMimeType = "application/vnd.google-apps.folder";
Expand All @@ -48,11 +48,10 @@ const queryHandlers = {
([key, value]) =>
`properties has { key='${key}' and value='${value}' }`
),
modifiedTime: (modifiedTime: NumberComparison) => {
if (typeof modifiedTime === "number")
return `modifiedTime=${modifiedTime}`;
if ("gt" in modifiedTime) return `modifiedTime > ${modifiedTime.gt}`;
if ("lt" in modifiedTime) return `modifiedTime < ${modifiedTime.lt}`;
modifiedTime: (modifiedTime: DateComparison) => {
if ("eq" in modifiedTime) return `modifiedTime = '${modifiedTime.eq}'`;
if ("gt" in modifiedTime) return `modifiedTime > '${modifiedTime.gt}'`;
if ("lt" in modifiedTime) return `modifiedTime < '${modifiedTime.lt}'`;
},
};

Expand Down
8 changes: 7 additions & 1 deletion main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,13 @@ export default class ObsidianGoogleDrive extends Plugin {

const recentlyModified = await this.drive.searchFiles({
include: ["id"],
matches: [{ modifiedTime: { gt: this.settings.lastSyncedAt } }],
matches: [
{
modifiedTime: {
gt: new Date(this.settings.lastSyncedAt).toISOString(),
},
},
],
});
if (!recentlyModified) {
return new Notice("An error occurred fetching Google Drive files.");
Expand Down

0 comments on commit ef4e7a3

Please sign in to comment.