Plan Phase C and D implementation
Co-authored-by: qinfendebingshuo <207279273+qinfendebingshuo@users.noreply.github.com> Agent-Logs-Url: https://github.com/qinfendebingshuo/guanghulab/sessions/a581dc42-267b-44e1-b669-6ad503a47f49
This commit is contained in:
parent
ec8f85522a
commit
d8810d1546
|
|
@ -72,7 +72,9 @@ function processInbox() {
|
||||||
var timestamp = Utilities.formatDate(
|
var timestamp = Utilities.formatDate(
|
||||||
new Date(), 'Asia/Shanghai', 'yyyyMMdd-HHmmss'
|
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';
|
var filename = timestamp + '-' + safeName + '.json';
|
||||||
|
|
||||||
// 写入 GitHub 仓库
|
// 写入 GitHub 仓库
|
||||||
|
|
@ -161,7 +163,7 @@ function writeToGitHub(token, filePath, content) {
|
||||||
+ CONFIG.GITHUB_REPO + '/contents/' + filePath;
|
+ CONFIG.GITHUB_REPO + '/contents/' + filePath;
|
||||||
|
|
||||||
var payload = {
|
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),
|
content: Utilities.base64Encode(content, Utilities.Charset.UTF_8),
|
||||||
branch: CONFIG.GITHUB_BRANCH
|
branch: CONFIG.GITHUB_BRANCH
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -65,6 +65,13 @@ function collectFiles(dirPath, recursive) {
|
||||||
return results;
|
return results;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 转义 Drive API 查询中的单引号
|
||||||
|
*/
|
||||||
|
function escapeQuery(str) {
|
||||||
|
return str.replace(/\\/g, '\\\\').replace(/'/g, "\\'");
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 在 Drive 中查找或创建文件夹(按路径逐级创建)
|
* 在 Drive 中查找或创建文件夹(按路径逐级创建)
|
||||||
*/
|
*/
|
||||||
|
|
@ -73,7 +80,8 @@ async function getOrCreateDriveFolder(drive, parentId, folderPath) {
|
||||||
let currentParentId = parentId;
|
let currentParentId = parentId;
|
||||||
|
|
||||||
for (const part of parts) {
|
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({
|
const res = await drive.files.list({
|
||||||
q: query,
|
q: query,
|
||||||
fields: 'files(id, name)',
|
fields: 'files(id, name)',
|
||||||
|
|
@ -103,7 +111,8 @@ async function getOrCreateDriveFolder(drive, parentId, folderPath) {
|
||||||
* 在 Drive 目标文件夹中查找同名文件
|
* 在 Drive 目标文件夹中查找同名文件
|
||||||
*/
|
*/
|
||||||
async function findFileInDrive(drive, folderId, fileName) {
|
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({
|
const res = await drive.files.list({
|
||||||
q: query,
|
q: query,
|
||||||
fields: 'files(id, name, md5Checksum)',
|
fields: 'files(id, name, md5Checksum)',
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue