-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest_obj.ts
More file actions
33 lines (29 loc) · 1.38 KB
/
Copy pathtest_obj.ts
File metadata and controls
33 lines (29 loc) · 1.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import { readFileSync, writeFileSync } from 'fs';
import { resolve } from 'path';
import { homedir } from 'os';
async function run() {
const configStr = readFileSync(resolve(homedir(), 'Library/Preferences/.wrangler/config/default.toml'), 'utf8');
const tokenMatch = configStr.match(/oauth_token = "(.*)"/);
const token = tokenMatch![1];
const acctRes = await fetch("https://api.cloudflare.com/client/v4/accounts", {
headers: { Authorization: `Bearer ${token}` }
});
const accounts = await acctRes.json();
const accountId = accounts.result[0].id;
console.log("Found account:", accountId);
const bucketsRes = await fetch(`https://api.cloudflare.com/client/v4/accounts/${accountId}/r2/buckets`, {
headers: { Authorization: `Bearer ${token}` }
});
const buckets = await bucketsRes.json();
console.log("Buckets length:", buckets.result.buckets.length);
if (buckets.result.buckets.length > 0) {
const bucketName = buckets.result.buckets[0].name;
const objsRes = await fetch(`https://api.cloudflare.com/client/v4/accounts/${accountId}/r2/buckets/${bucketName}/objects?delimiter=%2F`, {
headers: { Authorization: `Bearer ${token}` }
});
const objs = await objsRes.json();
console.log("Objects payload keys:", Object.keys(objs.result));
console.log("Objects payload structure:", JSON.stringify(objs.result, null, 2).slice(0, 1000));
}
}
run();