0.16.1-1 Fix registry Makemkv
This commit is contained in:
@@ -1,13 +1,18 @@
|
||||
const fs = require('fs');
|
||||
const os = require('os');
|
||||
const path = require('path');
|
||||
const { execFile } = require('child_process');
|
||||
const logger = require('./logger').child('MAKEMKV_KEY');
|
||||
|
||||
const MAKEMKV_BETA_KEY_API_URL = 'https://cable.ayra.ch/makemkv/api.php?raw';
|
||||
const MAKEMKV_BETA_KEY_API_URL = 'https://cable.ayra.ch/makemkv/api.php?json';
|
||||
const MAKEMKV_BETA_KEY_API_USER_AGENT = process.env.MAKEMKV_BETA_KEY_API_USER_AGENT
|
||||
|| 'Ripster/1.0 (MakeMKV beta key sync)';
|
||||
const MAKEMKV_BETA_KEY_API_FROM = process.env.MAKEMKV_BETA_KEY_API_FROM
|
||||
|| 'ripster@localhost';
|
||||
|| 'admin@example.invalid';
|
||||
const MAKEMKV_BETA_KEY_API_TIMEOUT_MS = Math.max(
|
||||
1000,
|
||||
Number(process.env.MAKEMKV_BETA_KEY_API_TIMEOUT_MS || 15000)
|
||||
);
|
||||
|
||||
function normalizeRegistrationKey(rawValue) {
|
||||
return String(rawValue || '').trim();
|
||||
@@ -89,27 +94,42 @@ async function syncRegistrationKeyToConfig(rawValue, options = {}) {
|
||||
}
|
||||
|
||||
async function fetchCurrentBetaKey() {
|
||||
const response = await fetch(MAKEMKV_BETA_KEY_API_URL, {
|
||||
headers: {
|
||||
'User-Agent': MAKEMKV_BETA_KEY_API_USER_AGENT,
|
||||
'From': MAKEMKV_BETA_KEY_API_FROM,
|
||||
'Accept': 'text/plain, text/html;q=0.9, */*;q=0.8',
|
||||
'Cache-Control': 'no-cache',
|
||||
'Pragma': 'no-cache'
|
||||
}
|
||||
});
|
||||
const errors = [];
|
||||
|
||||
if (!response.ok) {
|
||||
const error = new Error(`Betakey konnte nicht geladen werden (HTTP ${response.status}).`);
|
||||
try {
|
||||
return await fetchCurrentBetaKeyViaCurl();
|
||||
} catch (error) {
|
||||
errors.push(error?.message || String(error));
|
||||
logger.warn('beta-key:curl-failed', {
|
||||
error: error?.message || String(error)
|
||||
});
|
||||
}
|
||||
|
||||
try {
|
||||
return await fetchCurrentBetaKeyViaFetch();
|
||||
} catch (error) {
|
||||
errors.push(error?.message || String(error));
|
||||
logger.warn('beta-key:fetch-failed', {
|
||||
error: error?.message || String(error)
|
||||
});
|
||||
}
|
||||
|
||||
const error = new Error(`Betakey konnte nicht geladen werden. Details: ${errors.join(' | ')}`);
|
||||
error.statusCode = 502;
|
||||
throw error;
|
||||
}
|
||||
|
||||
function parseBetaKeyResponse(rawBody) {
|
||||
let payload = null;
|
||||
try {
|
||||
payload = JSON.parse(String(rawBody || '{}'));
|
||||
} catch (_error) {
|
||||
const error = new Error('Betakey-Antwort ist kein gültiges JSON.');
|
||||
error.statusCode = 502;
|
||||
throw error;
|
||||
}
|
||||
|
||||
const rawBody = await response.text();
|
||||
const betaKey = String(rawBody || '')
|
||||
.split(/\r?\n/)
|
||||
.map((line) => line.trim())
|
||||
.find(Boolean) || '';
|
||||
const betaKey = String(payload?.key || '').trim();
|
||||
|
||||
if (!/^[A-Za-z0-9][A-Za-z0-9-]{15,}$/.test(betaKey)) {
|
||||
const error = new Error('Betakey-Antwort ist ungültig.');
|
||||
@@ -123,6 +143,68 @@ async function fetchCurrentBetaKey() {
|
||||
};
|
||||
}
|
||||
|
||||
function fetchCurrentBetaKeyViaCurl() {
|
||||
return new Promise((resolve, reject) => {
|
||||
execFile(
|
||||
'curl',
|
||||
[
|
||||
'-fsSL',
|
||||
'--max-time', String(Math.ceil(MAKEMKV_BETA_KEY_API_TIMEOUT_MS / 1000)),
|
||||
'-A', MAKEMKV_BETA_KEY_API_USER_AGENT,
|
||||
'-H', `From: ${MAKEMKV_BETA_KEY_API_FROM}`,
|
||||
'-H', 'Accept: text/plain, text/html;q=0.9, */*;q=0.8',
|
||||
'-H', 'Accept-Language: de,en-US;q=0.7,en;q=0.3',
|
||||
'-H', 'Cache-Control: no-cache',
|
||||
'-H', 'Pragma: no-cache',
|
||||
MAKEMKV_BETA_KEY_API_URL
|
||||
],
|
||||
{
|
||||
timeout: MAKEMKV_BETA_KEY_API_TIMEOUT_MS,
|
||||
maxBuffer: 1024 * 1024
|
||||
},
|
||||
(error, stdout, stderr) => {
|
||||
if (error) {
|
||||
const resolvedError = new Error(
|
||||
`curl fehlgeschlagen (${error.code || 'unknown'}): ${String(stderr || error.message || '').trim() || 'keine Details'}`
|
||||
);
|
||||
resolvedError.statusCode = 502;
|
||||
reject(resolvedError);
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
resolve(parseBetaKeyResponse(stdout));
|
||||
} catch (parseError) {
|
||||
reject(parseError);
|
||||
}
|
||||
}
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
async function fetchCurrentBetaKeyViaFetch() {
|
||||
const response = await fetch(MAKEMKV_BETA_KEY_API_URL, {
|
||||
headers: {
|
||||
'User-Agent': MAKEMKV_BETA_KEY_API_USER_AGENT,
|
||||
'From': MAKEMKV_BETA_KEY_API_FROM,
|
||||
'Accept': 'text/plain, text/html;q=0.9, */*;q=0.8',
|
||||
'Accept-Language': 'de,en-US;q=0.7,en;q=0.3',
|
||||
'Cache-Control': 'no-cache',
|
||||
'Pragma': 'no-cache'
|
||||
},
|
||||
signal: AbortSignal.timeout(MAKEMKV_BETA_KEY_API_TIMEOUT_MS)
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
const error = new Error(`HTTP ${response.status}`);
|
||||
error.statusCode = 502;
|
||||
throw error;
|
||||
}
|
||||
|
||||
const rawBody = await response.text();
|
||||
return parseBetaKeyResponse(rawBody);
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
MAKEMKV_BETA_KEY_API_URL,
|
||||
fetchCurrentBetaKey,
|
||||
|
||||
Reference in New Issue
Block a user