windows credential file path resolution fix

This commit is contained in:
Anish Pednekar 2025-01-22 15:54:49 +05:30
commit c701fe7dea

View file

@ -12,6 +12,7 @@ import {
import fs from "fs"; import fs from "fs";
import { google } from "googleapis"; import { google } from "googleapis";
import path from "path"; import path from "path";
import { fileURLToPath } from 'url';
const drive = google.drive("v3"); const drive = google.drive("v3");
@ -176,7 +177,7 @@ server.setRequestHandler(CallToolRequestSchema, async (request) => {
}); });
const credentialsPath = process.env.GDRIVE_CREDENTIALS_PATH || path.join( const credentialsPath = process.env.GDRIVE_CREDENTIALS_PATH || path.join(
path.dirname(new URL(import.meta.url).pathname), path.dirname(fileURLToPath(import.meta.url)),
"../../../.gdrive-server-credentials.json", "../../../.gdrive-server-credentials.json",
); );
@ -184,7 +185,7 @@ async function authenticateAndSaveCredentials() {
console.log("Launching auth flow…"); console.log("Launching auth flow…");
const auth = await authenticate({ const auth = await authenticate({
keyfilePath: process.env.GDRIVE_OAUTH_PATH || path.join( keyfilePath: process.env.GDRIVE_OAUTH_PATH || path.join(
path.dirname(new URL(import.meta.url).pathname), path.dirname(fileURLToPath(import.meta.url)),
"../../../gcp-oauth.keys.json", "../../../gcp-oauth.keys.json",
), ),
scopes: ["https://www.googleapis.com/auth/drive.readonly"], scopes: ["https://www.googleapis.com/auth/drive.readonly"],