fix: doodstream two-step upload (follow HTML form redirect)
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
9da6629e19
commit
fda07da4bd
@ -286,16 +286,59 @@ class DoodstreamUploader {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!payload) {
|
if (!payload) {
|
||||||
// Try to extract from HTML response
|
// Try to extract filecode directly from HTML
|
||||||
const match = resText.match(/filecode['":\s]+['"]([a-zA-Z0-9]+)['"]/i);
|
const codeMatch = resText.match(/filecode['":\s]+['"]([a-zA-Z0-9]+)['"]/i);
|
||||||
if (match) {
|
if (codeMatch) {
|
||||||
return {
|
return {
|
||||||
download_url: `https://doodstream.com/d/${match[1]}`,
|
download_url: `https://doodstream.com/d/${codeMatch[1]}`,
|
||||||
embed_url: `https://doodstream.com/e/${match[1]}`,
|
embed_url: `https://doodstream.com/e/${codeMatch[1]}`,
|
||||||
file_code: match[1]
|
file_code: codeMatch[1]
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
throw new Error(`Doodstream Upload: Keine gueltige Antwort (HTTP ${statusCode}, Body: ${resText.slice(0, 150)})`);
|
|
||||||
|
// Follow HTML form redirect (two-step upload)
|
||||||
|
const formAction = resText.match(/<form[^>]*action=['"]([^'"]+)['"]/i);
|
||||||
|
if (formAction) {
|
||||||
|
const hiddenFields = {};
|
||||||
|
const inputRegex = /<input[^>]*type=['"]hidden['"][^>]*name=['"]([^'"]+)['"][^>]*value=['"]([^'"]*)['"]/gi;
|
||||||
|
let m;
|
||||||
|
while ((m = inputRegex.exec(resText)) !== null) {
|
||||||
|
hiddenFields[m[1]] = m[2];
|
||||||
|
}
|
||||||
|
// Also try reversed attribute order (value before name)
|
||||||
|
const inputRegex2 = /<input[^>]*value=['"]([^'"]*)['""][^>]*name=['"]([^'"]+)['"]/gi;
|
||||||
|
while ((m = inputRegex2.exec(resText)) !== null) {
|
||||||
|
if (!hiddenFields[m[2]]) hiddenFields[m[2]] = m[1];
|
||||||
|
}
|
||||||
|
|
||||||
|
const formData = new URLSearchParams(hiddenFields);
|
||||||
|
const followRes = await this._fetch(formAction[1], {
|
||||||
|
method: 'POST',
|
||||||
|
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
|
||||||
|
body: formData.toString()
|
||||||
|
});
|
||||||
|
const followText = await followRes.text();
|
||||||
|
|
||||||
|
// Try JSON from follow response
|
||||||
|
let followPayload;
|
||||||
|
try { followPayload = JSON.parse(followText); } catch {}
|
||||||
|
if (followPayload) {
|
||||||
|
payload = followPayload;
|
||||||
|
} else {
|
||||||
|
// Try filecode from follow response HTML
|
||||||
|
const followCode = followText.match(/filecode['":\s]+['"]([a-zA-Z0-9]+)['"]/i);
|
||||||
|
if (followCode) {
|
||||||
|
return {
|
||||||
|
download_url: `https://doodstream.com/d/${followCode[1]}`,
|
||||||
|
embed_url: `https://doodstream.com/e/${followCode[1]}`,
|
||||||
|
file_code: followCode[1]
|
||||||
|
};
|
||||||
|
}
|
||||||
|
throw new Error(`Doodstream Upload: Redirect-Antwort ungueltig (${followText.slice(0, 150)})`);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
throw new Error(`Doodstream Upload: Keine gueltige Antwort (HTTP ${statusCode}, Body: ${resText.slice(0, 150)})`);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (payload.status && Number(payload.status) !== 200 && payload.msg) {
|
if (payload.status && Number(payload.status) !== 200 && payload.msg) {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user