chore: scripts Dokploy/BPS (cron secret, Ads MCC, sync y probes)
Incluye utilidades de ops para CRON_SECRET, login customer Google Ads, sync de seguimiento BPS y probes de conexiones. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
64
scripts/list_drive_calendars.ts
Normal file
64
scripts/list_drive_calendars.ts
Normal file
@@ -0,0 +1,64 @@
|
||||
/** List Drive calendar folder and find BPS files. */
|
||||
import { config } from 'dotenv';
|
||||
import { resolve } from 'path';
|
||||
config({ path: resolve(process.cwd(), '.env.local') });
|
||||
|
||||
import { getValidAccessToken } from '../src/lib/google-drive';
|
||||
|
||||
const FOLDER = '12tPM0_nuVEf9MBUeyipmcWAJ-gFFgqXh';
|
||||
|
||||
async function listChildren(token: string, parentId: string) {
|
||||
const out: { id: string; name: string; mimeType: string }[] = [];
|
||||
let pageToken: string | undefined;
|
||||
do {
|
||||
const params = new URLSearchParams({
|
||||
q: `'${parentId}' in parents and trashed=false`,
|
||||
fields: 'nextPageToken,files(id,name,mimeType,modifiedTime)',
|
||||
pageSize: '100',
|
||||
supportsAllDrives: 'true',
|
||||
includeItemsFromAllDrives: 'true',
|
||||
corpora: 'allDrives',
|
||||
});
|
||||
if (pageToken) params.set('pageToken', pageToken);
|
||||
const r = await fetch(`https://www.googleapis.com/drive/v3/files?${params}`, {
|
||||
headers: { Authorization: `Bearer ${token}` },
|
||||
});
|
||||
const j = (await r.json()) as {
|
||||
files?: { id: string; name: string; mimeType: string }[];
|
||||
nextPageToken?: string;
|
||||
};
|
||||
if (!r.ok) throw new Error(JSON.stringify(j).slice(0, 400));
|
||||
out.push(...(j.files || []));
|
||||
pageToken = j.nextPageToken;
|
||||
} while (pageToken);
|
||||
return out;
|
||||
}
|
||||
|
||||
async function main() {
|
||||
const token = await getValidAccessToken();
|
||||
console.log('token ok');
|
||||
const top = await listChildren(token, FOLDER);
|
||||
console.log('top count', top.length);
|
||||
for (const f of top.sort((a, b) => a.name.localeCompare(b.name))) {
|
||||
const kind = f.mimeType.includes('folder') ? 'DIR' : 'FILE';
|
||||
console.log(`${kind}\t${f.name}\t${f.id}`);
|
||||
}
|
||||
const bps = top.filter((f) => /bps|blue.?parrot|parrot/i.test(f.name));
|
||||
console.log('\nBPS matches', bps.length);
|
||||
for (const f of bps) {
|
||||
if (f.mimeType.includes('folder')) {
|
||||
const kids = await listChildren(token, f.id);
|
||||
console.log(`\n--- ${f.name} (${kids.length}) ---`);
|
||||
for (const k of kids.sort((a, b) => a.name.localeCompare(b.name))) {
|
||||
console.log(
|
||||
` ${k.mimeType.includes('folder') ? 'DIR' : 'FILE'}\t${k.name}\t${k.id}`
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
main().catch((e) => {
|
||||
console.error(e);
|
||||
process.exit(1);
|
||||
});
|
||||
Reference in New Issue
Block a user