fix: preserve explicit Doodstream web login and reuse OTP sessions
CI / verify (push) Canceled after 0s
CI / verify (push) Canceled after 0s
This commit is contained in:
+22
-3
@@ -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 };
|
||||
|
||||
Reference in New Issue
Block a user