diff --git a/lib/doodstream-upload.js b/lib/doodstream-upload.js index 47d786a..d9a6a2b 100644 --- a/lib/doodstream-upload.js +++ b/lib/doodstream-upload.js @@ -210,6 +210,31 @@ class DoodstreamUploader { // Fallback: try fetching from upload page HTML const pageRes = await this._fetch(BASE_URL + '/?op=upload'); const html = await pageRes.text(); + + // Current doodstream format: the upload server is the action of the + // multipart upload form, e.g. + //
'); + }; + const url = await up._getUploadServer(); + assert.equal(url, 'https://n9.cloudatacdn.com/upload/01?FRESH123'); + assert.equal(up.sessId, 'FRESH123'); // critical: form-field token must match the node URL token +}); + +test('getUploadServer: un-escapes & in the form-action query string', async () => { + const up = new DoodstreamUploader(); + up._fetch = async (url) => { + if (/op=upload_server/.test(url)) return fakeRes('not json'); + return fakeRes(''); + }; + assert.equal(await up._getUploadServer(), 'https://n9.cloudatacdn.com/upload/01?a=1&b=2'); +}); + test('getUploadServer: throws (no silent dead fallback) when discovery fails', async () => { const up = new DoodstreamUploader(); up._fetch = async () => fakeRes('login required', { status: 200 });