diff --git a/farm-aggregator/scripts/dropbox-test.js b/farm-aggregator/scripts/dropbox-test.js new file mode 100644 index 0000000..ed77084 --- /dev/null +++ b/farm-aggregator/scripts/dropbox-test.js @@ -0,0 +1,54 @@ +/** + * Tests Dropbox connectivity and upload access. + * Run: node scripts/dropbox-test.js + */ +import 'dotenv/config'; +import { Dropbox } from 'dropbox'; + +const dbx = new Dropbox({ + clientId: process.env.DROPBOX_APP_KEY, + clientSecret: process.env.DROPBOX_APP_SECRET, + refreshToken: process.env.DROPBOX_REFRESH_TOKEN, +}); + +async function run() { + // 1. Check account info + try { + const account = await dbx.usersGetCurrentAccount(); + console.log('โœ… Connected as:', account.result.name.display_name); + } catch (e) { + console.error('โŒ Auth failed:', e.message); + process.exit(1); + } + + // 2. Try listing root + try { + const root = await dbx.filesListFolder({ path: '' }); + console.log('\n๐Ÿ“ Root folder contents:'); + root.result.entries.forEach((e) => console.log(' ', e['.tag'] === 'folder' ? '๐Ÿ“' : '๐Ÿ“„', e.name)); + } catch (e) { + console.error('โŒ Cannot list root:', e.message); + } + + // 3. Try uploading a test file to /Farm/Summaries + const outbox = process.env.DROPBOX_OUTBOX_PATH ?? '/Farm/Summaries'; + const testPath = `${outbox}/test_${Date.now()}.txt`; + try { + await dbx.filesUpload({ + path: testPath, + contents: `Test upload at ${new Date().toISOString()}`, + mode: { '.tag': 'overwrite' }, + }); + console.log(`\nโœ… Upload succeeded โ†’ ${testPath}`); + // Clean up + await dbx.filesDeleteV2({ path: testPath }); + console.log('๐Ÿงน Test file cleaned up'); + } catch (e) { + console.error(`\nโŒ Upload to ${testPath} failed:`, e.message ?? e); + console.log('\nโ†’ If this is a 400/path error, your Dropbox app likely has App Folder access only.'); + console.log(' Fix: go to dropbox.com/developers โ†’ your app โ†’ Permissions โ†’ change to Full Dropbox'); + console.log(' Then regenerate your refresh token (run dropbox-auth.js again).'); + } +} + +run();