fix: preserve explicit Doodstream web login and reuse OTP sessions
CI / verify (push) Canceled after 0s

This commit is contained in:
Sucukdeluxe
2026-09-12 14:38:10 +02:00
parent fd4bee35eb
commit 0e4a9613fb
9 changed files with 188 additions and 34 deletions
+22 -3
View File
@@ -20,6 +20,10 @@ const { createHash } = require('node:crypto');
function selectUploadAuth(hoster, account) {
if (!account || typeof account !== 'object') return {};
if (account.authType === 'login' && account.username && account.password) {
return { username: account.username, password: account.password };
}
if (hoster === 'doodstream.com' && account.apiKey) {
return { apiKey: account.apiKey };
}
@@ -72,6 +76,7 @@ function createDoodstreamOtpCoordinator(options = {}) {
const key = credentialKey(username, password);
const existing = activeState(key);
if (existing?.inFlight) return existing.inFlight;
if (existing?.ready && input.requestNewChallenge !== true) return existing.result;
if (otp && !existing?.pending) {
return {
status: 'otp_required',
@@ -87,8 +92,11 @@ function createDoodstreamOtpCoordinator(options = {}) {
const operation = (async () => {
try {
await uploader.login(username, password, otp || undefined);
if (states.get(key)?.operationId === operationId) states.delete(key);
return { status: 'ok', message: 'Login ok, Upload-Seite bereit' };
const result = { status: 'ok', message: 'Login erfolgreich' };
if (states.get(key)?.operationId === operationId) {
storeState(key, { operationId, uploader, ready: true, expiresAt: now() + challengeTtlMs, result, inFlight: null });
}
return result;
} catch (error) {
if (error?.otpRequired === true) {
const result = { status: 'otp_required', message: error.message || 'OTP erforderlich' };
@@ -137,7 +145,18 @@ function createDoodstreamOtpCoordinator(options = {}) {
return operation;
}
return { check };
async function acquire(input) {
const result = await check(input);
const session = activeState(credentialKey(input.username, input.password));
if (result.status !== 'ok' || !session?.ready) {
const error = new Error(result.message || 'OTP erforderlich');
error.otpRequired = result.status === 'otp_required';
throw error;
}
return session.uploader.cloneSession();
}
return { check, acquire };
}
module.exports = { createDoodstreamOtpCoordinator, selectUploadAuth };