diff --git a/scripts/grid-db/drive-to-github-bridge.gs b/scripts/grid-db/drive-to-github-bridge.gs index c04ad6e1..fcb970a9 100644 --- a/scripts/grid-db/drive-to-github-bridge.gs +++ b/scripts/grid-db/drive-to-github-bridge.gs @@ -72,7 +72,9 @@ function processInbox() { var timestamp = Utilities.formatDate( new Date(), 'Asia/Shanghai', 'yyyyMMdd-HHmmss' ); - var safeName = file.getName().replace(/[^a-zA-Z0-9\-_]/g, ''); + var safeName = file.getName().replace(/[^a-zA-Z0-9.\-_]/g, ''); + // Strip any existing extension, then add .json + safeName = safeName.replace(/\.[^.]+$/, ''); var filename = timestamp + '-' + safeName + '.json'; // 写入 GitHub 仓库 @@ -161,7 +163,7 @@ function writeToGitHub(token, filePath, content) { + CONFIG.GITHUB_REPO + '/contents/' + filePath; var payload = { - message: 'auto: Gemini inbox via Drive bridge [skip ci]', + message: 'auto: Gemini inbox via Drive bridge (' + filePath.split('/').pop() + ') [skip ci]', content: Utilities.base64Encode(content, Utilities.Charset.UTF_8), branch: CONFIG.GITHUB_BRANCH }; diff --git a/scripts/grid-db/sync-to-drive.js b/scripts/grid-db/sync-to-drive.js index 0ffc37c6..2403b914 100644 --- a/scripts/grid-db/sync-to-drive.js +++ b/scripts/grid-db/sync-to-drive.js @@ -65,6 +65,13 @@ function collectFiles(dirPath, recursive) { return results; } +/** + * 转义 Drive API 查询中的单引号 + */ +function escapeQuery(str) { + return str.replace(/\\/g, '\\\\').replace(/'/g, "\\'"); +} + /** * 在 Drive 中查找或创建文件夹(按路径逐级创建) */ @@ -73,7 +80,8 @@ async function getOrCreateDriveFolder(drive, parentId, folderPath) { let currentParentId = parentId; for (const part of parts) { - const query = `name='${part}' and '${currentParentId}' in parents and mimeType='application/vnd.google-apps.folder' and trashed=false`; + const safePart = escapeQuery(part); + const query = `name='${safePart}' and '${currentParentId}' in parents and mimeType='application/vnd.google-apps.folder' and trashed=false`; const res = await drive.files.list({ q: query, fields: 'files(id, name)', @@ -103,7 +111,8 @@ async function getOrCreateDriveFolder(drive, parentId, folderPath) { * 在 Drive 目标文件夹中查找同名文件 */ async function findFileInDrive(drive, folderId, fileName) { - const query = `name='${fileName}' and '${folderId}' in parents and trashed=false`; + const safeFileName = escapeQuery(fileName); + const query = `name='${safeFileName}' and '${folderId}' in parents and trashed=false`; const res = await drive.files.list({ q: query, fields: 'files(id, name, md5Checksum)',