OpenCode Deployer commited on
Commit ·
036fcb8
1
Parent(s): 7c7f70b
update
Browse files- service/gdrive/list-files.js +55 -2
service/gdrive/list-files.js
CHANGED
|
@@ -1,11 +1,64 @@
|
|
| 1 |
const GoogleDriveService = require('./gdrive-service');
|
| 2 |
|
|
|
|
|
|
|
|
|
|
| 3 |
async function main() {
|
| 4 |
const drive = new GoogleDriveService();
|
| 5 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6 |
}
|
| 7 |
|
| 8 |
main().catch(error => {
|
| 9 |
console.error('执行过程中发生错误:', error);
|
| 10 |
process.exit(1);
|
| 11 |
-
});
|
|
|
|
| 1 |
const GoogleDriveService = require('./gdrive-service');
|
| 2 |
|
| 3 |
+
// 共享目录的文件夹ID(从共享链接中提取)
|
| 4 |
+
const SHARED_FOLDER_ID = '1UCRmKH3yfMq4u6NjMMW9av30oyNjTgFk';
|
| 5 |
+
|
| 6 |
async function main() {
|
| 7 |
const drive = new GoogleDriveService();
|
| 8 |
+
|
| 9 |
+
try {
|
| 10 |
+
console.log('正在列举共享目录下的文件...');
|
| 11 |
+
console.log('文件夹ID:', SHARED_FOLDER_ID);
|
| 12 |
+
|
| 13 |
+
// 构建查询条件,只列出指定文件夹下的文件
|
| 14 |
+
const query = `'${SHARED_FOLDER_ID}' in parents and trashed=false`;
|
| 15 |
+
|
| 16 |
+
// 列出共享目录下的文件
|
| 17 |
+
const result = await drive.listFiles({
|
| 18 |
+
query: query,
|
| 19 |
+
pageSize: 100 // 增加每页文件数量
|
| 20 |
+
});
|
| 21 |
+
|
| 22 |
+
if (result.files && result.files.length > 0) {
|
| 23 |
+
console.log(`\n找到 ${result.files.length} 个文件/文件夹:`);
|
| 24 |
+
console.log('='.repeat(80));
|
| 25 |
+
|
| 26 |
+
result.files.forEach((file, index) => {
|
| 27 |
+
const type = file.mimeType === 'application/vnd.google-apps.folder' ? '[文件夹]' : '[文件]';
|
| 28 |
+
const size = file.size ? `(${(parseInt(file.size) / 1024).toFixed(2)} KB)` : '(大小未知)';
|
| 29 |
+
const modifiedTime = file.modifiedTime ? new Date(file.modifiedTime).toLocaleString('zh-CN') : '时间未知';
|
| 30 |
+
|
| 31 |
+
console.log(`${index + 1}. ${type} ${file.name} ${size}`);
|
| 32 |
+
console.log(` ID: ${file.id}`);
|
| 33 |
+
console.log(` 修改时间: ${modifiedTime}`);
|
| 34 |
+
console.log(` 类型: ${file.mimeType}`);
|
| 35 |
+
console.log('-'.repeat(80));
|
| 36 |
+
});
|
| 37 |
+
} else {
|
| 38 |
+
console.log('共享目录为空或无法访问该目录');
|
| 39 |
+
}
|
| 40 |
+
|
| 41 |
+
// 如果有更多文件,显示分页信息
|
| 42 |
+
if (result.nextPageToken) {
|
| 43 |
+
console.log('\n注意: 还有更多文件,如需查看请使用分页功能');
|
| 44 |
+
}
|
| 45 |
+
|
| 46 |
+
} catch (error) {
|
| 47 |
+
console.error('列举共享目录文件失败:', error.message);
|
| 48 |
+
|
| 49 |
+
// 提供一些调试信息
|
| 50 |
+
if (error.message.includes('not found')) {
|
| 51 |
+
console.log('可能的原因:');
|
| 52 |
+
console.log('1. 文件夹ID不正确');
|
| 53 |
+
console.log('2. 服务账户没有访问该共享目录的权限');
|
| 54 |
+
console.log('3. 共享目录已被删除或移动');
|
| 55 |
+
}
|
| 56 |
+
|
| 57 |
+
process.exit(1);
|
| 58 |
+
}
|
| 59 |
}
|
| 60 |
|
| 61 |
main().catch(error => {
|
| 62 |
console.error('执行过程中发生错误:', error);
|
| 63 |
process.exit(1);
|
| 64 |
+
});
|