Release v2.1.65: safe MCP updates and measured upload scheduling
CI / verify (push) Canceled after 0s
CI / verify (push) Canceled after 0s
This commit is contained in:
1 parent
e3c03d195e
commit
1ff552fc40
26 files changed
+552
-92
No files matched your search
@@ -318,6 +318,18 @@ The previous diagnostic operations map to these MCP tools:
|
|||||||
|
|
||||||
Screen streaming and arbitrary mouse/keyboard control are intentionally not MCP operations. CAPTCHA and interactive authentication challenges remain local; supported one-time account codes can be submitted with `mhu_accounts_otp`. Granting new directories, changing MCP permissions and obtaining the connection code are local security decisions. These boundaries do not disable ordinary upload, queue, account, automation, history or backup operations exposed through the structured tool catalog.
|
Screen streaming and arbitrary mouse/keyboard control are intentionally not MCP operations. CAPTCHA and interactive authentication challenges remain local; supported one-time account codes can be submitted with `mhu_accounts_otp`. Granting new directories, changing MCP permissions and obtaining the connection code are local security decisions. These boundaries do not disable ordinary upload, queue, account, automation, history or backup operations exposed through the structured tool catalog.
|
||||||
|
|
||||||
|
### Official updates and performance monitoring
|
||||||
|
|
||||||
|
The separate **Allow official app updates without another confirmation** permission is disabled by default. Enabling it requires local confirmation. It only authorizes the application's official Windows installer workflow, not shell commands, arbitrary downloads, deletions or backup restores. Portable and unpacked installations are rejected by this remote workflow.
|
||||||
|
|
||||||
|
`mhu_update_install` requires an exact `targetVersion` and an idempotency `requestKey`. The selected official release must match that version. The installer is streamed to a private temporary directory, checked against the release's SHA-512 metadata and checked again from disk before launch. Use `mhu_update_status` to query the persistent job. A repeated key returns the same job, and cannot be reused for a different version.
|
||||||
|
|
||||||
|
The update first saves its resume intent, stops new admission and waits for currently active uploads to finish. It does not interrupt a multipart upload and pretend it can resume from a byte offset. Queue persistence and the normal close handshake must succeed before the installer is launched and the application exits. After restarting, the job completes only when the exact target version is running, MCP has reconnected and the previously running work has been restored. A missing restart, wrong version, revoked permission or persistence failure is not reported as success. The first release containing this workflow must be installed through the existing local updater before remote updates can be used.
|
||||||
|
|
||||||
|
`mhu_performance_get` is read-only and returns bounded in-memory samples of main-thread timer delay, renderer round trips, CPU usage, process memory, asynchronous file-I/O waits and upload-slot occupancy. It does not launch host commands. A slow network request, provider wait or asynchronous disk operation is not itself a main-thread freeze. Long timer gaps are reported as measurement gaps, not proven freezes. Historical samples cover only the current process and their bounded retention window.
|
||||||
|
|
||||||
|
The upload scheduler no longer reserves a global transfer slot while waiting for a hoster's configured start interval. Per-hoster spacing remains enforced at admission. Upload file metadata and chunk reads use asynchronous I/O. These changes do not reduce configured parallelism or change successful-upload confirmation requirements. Synthetic benchmark results demonstrate the targeted scheduling case only; server-specific throughput and freeze improvements require measurements after installing the new version.
|
||||||
|
|
||||||
### Diagnostic artifacts and file transfer
|
### Diagnostic artifacts and file transfer
|
||||||
|
|
||||||
`mhu_diagnostics_files` lists the application's startup journals, native Chromium logs and automatically saved startup failure reports. `mhu_diagnostics_read` reads one listed artifact with bounded pagination. Credentials are filtered from the complete text before pages are returned; offsets refer to characters in the filtered text. Files larger than 8 MiB are rejected by this reader. The existing bounded log-tail tools remain available for larger application logs. Job-specific logs, account cooldowns and manual-action states are exposed through `mhu_queue_job_log` and `mhu_accounts_runtime`; the diagnostic summary also includes current upload-manager and renderer status.
|
`mhu_diagnostics_files` lists the application's startup journals, native Chromium logs and automatically saved startup failure reports. `mhu_diagnostics_read` reads one listed artifact with bounded pagination. Credentials are filtered from the complete text before pages are returned; offsets refer to characters in the filtered text. Files larger than 8 MiB are rejected by this reader. The existing bounded log-tail tools remain available for larger application logs. Job-specific logs, account cooldowns and manual-action states are exposed through `mhu_queue_job_log` and `mhu_accounts_runtime`; the diagnostic summary also includes current upload-manager and renderer status.
|
||||||
|
|||||||
+1
-1
@@ -109,7 +109,7 @@ export default [
|
|||||||
'getUiLocale', 'config', 'hosterSettings', 'ensureAccountStatusEntries', 'syncSelectedUploadHosters', 'renderAccounts', 'renderHosterSummary',
|
'getUiLocale', 'config', 'hosterSettings', 'ensureAccountStatusEntries', 'syncSelectedUploadHosters', 'renderAccounts', 'renderHosterSummary',
|
||||||
'rebuildJobIndex', '_queueStatsCache', 'syncSelectedFilesFromQueue', 'renderQueueTable', 'updateUploadView', 'updateStatusBar', 'queueJobs',
|
'rebuildJobIndex', '_queueStatsCache', 'syncSelectedFilesFromQueue', 'renderQueueTable', 'updateUploadView', 'updateStatusBar', 'queueJobs',
|
||||||
'uploading', 'selectedFiles', 'findAccountById', 'accountStatuses', 'existingImportPaths', 'createAutomationPreviewJob', 'clearDedupKeysForPaths',
|
'uploading', 'selectedFiles', 'findAccountById', 'accountStatuses', 'existingImportPaths', 'createAutomationPreviewJob', 'clearDedupKeysForPaths',
|
||||||
'persistQueueStateNow', 'isStartableQueueStatus', 'startSelectedUpload', '_jobIndexByUploadId', '_deletedJobIds', 'removeJobFromIndex', 'showCopyToast', 'getSelectedHosters'
|
'persistQueueStateNow', 'isStartableQueueStatus', 'startSelectedUpload', '_jobIndexByUploadId', '_deletedJobIds', 'removeJobFromIndex', 'showCopyToast', 'getSelectedHosters', 'cancelStartupQueueAutoStart', '_cancelAutoRetry'
|
||||||
].map(name => [name, 'writable']))
|
].map(name => [name, 'writable']))
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
|
const { statUploadFile, readUploadFile } = require('./upload-file-io');
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
const crypto = require('crypto');
|
const crypto = require('crypto');
|
||||||
const { request, Agent } = require('undici');
|
const { request, Agent } = require('undici');
|
||||||
@@ -67,7 +68,7 @@ class ClouddropUploader {
|
|||||||
if (!this.apiKey) throw new Error('Clouddrop: API-Key fehlt');
|
if (!this.apiKey) throw new Error('Clouddrop: API-Key fehlt');
|
||||||
const fileName = path.basename(filePath);
|
const fileName = path.basename(filePath);
|
||||||
let fileSize = 0;
|
let fileSize = 0;
|
||||||
try { fileSize = fs.statSync(filePath).size; }
|
try { fileSize = (await statUploadFile(filePath)).size; }
|
||||||
catch { throw new Error(`Clouddrop: Datei nicht lesbar: ${fileName}`); }
|
catch { throw new Error(`Clouddrop: Datei nicht lesbar: ${fileName}`); }
|
||||||
if (fileSize <= 0) throw new Error('Clouddrop: Datei ist leer');
|
if (fileSize <= 0) throw new Error('Clouddrop: Datei ist leer');
|
||||||
|
|
||||||
@@ -105,8 +106,7 @@ class ClouddropUploader {
|
|||||||
let bytesRead = 0;
|
let bytesRead = 0;
|
||||||
async function* generate() {
|
async function* generate() {
|
||||||
yield preambleBuf;
|
yield preambleBuf;
|
||||||
const fileStream = fs.createReadStream(filePath, { highWaterMark: 1024 * 1024 });
|
for await (const chunk of readUploadFile(filePath, signal)) {
|
||||||
for await (const chunk of fileStream) {
|
|
||||||
if (signal && signal.aborted) throw new Error('Aborted');
|
if (signal && signal.aborted) throw new Error('Aborted');
|
||||||
if (throttle) await throttle.consume(chunk.length, signal);
|
if (throttle) await throttle.consume(chunk.length, signal);
|
||||||
bytesRead += chunk.length;
|
bytesRead += chunk.length;
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
|
const { statUploadFile, readUploadFile } = require('./upload-file-io');
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
const crypto = require('crypto');
|
const crypto = require('crypto');
|
||||||
const { request } = require('undici');
|
const { request } = require('undici');
|
||||||
@@ -383,7 +384,7 @@ class DoodstreamUploader {
|
|||||||
*/
|
*/
|
||||||
async upload(filePath, progressCb, signal, throttle) {
|
async upload(filePath, progressCb, signal, throttle) {
|
||||||
const fileName = path.basename(filePath);
|
const fileName = path.basename(filePath);
|
||||||
const fileSize = fs.statSync(filePath).size;
|
const fileSize = (await statUploadFile(filePath)).size;
|
||||||
|
|
||||||
// Get upload server
|
// Get upload server
|
||||||
const uploadUrl = await this._getUploadServer();
|
const uploadUrl = await this._getUploadServer();
|
||||||
@@ -413,13 +414,11 @@ class DoodstreamUploader {
|
|||||||
const epilogueBuf = Buffer.from(epilogue, 'utf-8');
|
const epilogueBuf = Buffer.from(epilogue, 'utf-8');
|
||||||
const totalSize = preambleBuf.length + fileSize + epilogueBuf.length;
|
const totalSize = preambleBuf.length + fileSize + epilogueBuf.length;
|
||||||
|
|
||||||
const CHUNK_SIZE = 1024 * 1024;
|
|
||||||
let bytesRead = 0;
|
let bytesRead = 0;
|
||||||
|
|
||||||
async function* generate() {
|
async function* generate() {
|
||||||
yield preambleBuf;
|
yield preambleBuf;
|
||||||
const fileStream = fs.createReadStream(filePath, { highWaterMark: CHUNK_SIZE });
|
for await (const chunk of readUploadFile(filePath, signal)) {
|
||||||
for await (const chunk of fileStream) {
|
|
||||||
if (signal && signal.aborted) throw new Error('Aborted');
|
if (signal && signal.aborted) throw new Error('Aborted');
|
||||||
if (throttle) await throttle.consume(chunk.length, signal);
|
if (throttle) await throttle.consume(chunk.length, signal);
|
||||||
bytesRead += chunk.length;
|
bytesRead += chunk.length;
|
||||||
|
|||||||
+7
-9
@@ -1,4 +1,4 @@
|
|||||||
const fs = require('fs');
|
const { statUploadFile, readUploadFile } = require('./upload-file-io');
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
const crypto = require('crypto');
|
const crypto = require('crypto');
|
||||||
const { request } = require('undici');
|
const { request } = require('undici');
|
||||||
@@ -259,10 +259,10 @@ function parseByseResult(payload) {
|
|||||||
|
|
||||||
// --- Multipart upload with progress ---
|
// --- Multipart upload with progress ---
|
||||||
|
|
||||||
function buildMultipart(filePath, formFields) {
|
async function buildMultipart(filePath, formFields) {
|
||||||
const boundary = '----FormBoundary' + crypto.randomBytes(16).toString('hex');
|
const boundary = '----FormBoundary' + crypto.randomBytes(16).toString('hex');
|
||||||
const fileName = path.basename(filePath);
|
const fileName = path.basename(filePath);
|
||||||
const fileSize = fs.statSync(filePath).size;
|
const fileSize = (await statUploadFile(filePath)).size;
|
||||||
|
|
||||||
let preamble = '';
|
let preamble = '';
|
||||||
for (const [key, value] of Object.entries(formFields)) {
|
for (const [key, value] of Object.entries(formFields)) {
|
||||||
@@ -284,16 +284,14 @@ function buildMultipart(filePath, formFields) {
|
|||||||
return { boundary, preambleBuf, epilogueBuf, totalSize, fileSize };
|
return { boundary, preambleBuf, epilogueBuf, totalSize, fileSize };
|
||||||
}
|
}
|
||||||
|
|
||||||
function createUploadBody(filePath, formFields, onProgress, throttle, signal) {
|
async function createUploadBody(filePath, formFields, onProgress, throttle, signal) {
|
||||||
const { boundary, preambleBuf, epilogueBuf, totalSize, fileSize } = buildMultipart(filePath, formFields);
|
const { boundary, preambleBuf, epilogueBuf, totalSize, fileSize } = await buildMultipart(filePath, formFields);
|
||||||
|
|
||||||
let bytesRead = 0;
|
let bytesRead = 0;
|
||||||
const CHUNK_SIZE = 1024 * 1024;
|
|
||||||
|
|
||||||
async function* generate() {
|
async function* generate() {
|
||||||
yield preambleBuf;
|
yield preambleBuf;
|
||||||
const fileStream = fs.createReadStream(filePath, { highWaterMark: CHUNK_SIZE });
|
for await (const chunk of readUploadFile(filePath, signal)) {
|
||||||
for await (const chunk of fileStream) {
|
|
||||||
if (signal && signal.aborted) throw new Error('Aborted');
|
if (signal && signal.aborted) throw new Error('Aborted');
|
||||||
if (throttle) await throttle.consume(chunk.length, signal);
|
if (throttle) await throttle.consume(chunk.length, signal);
|
||||||
bytesRead += chunk.length;
|
bytesRead += chunk.length;
|
||||||
@@ -558,7 +556,7 @@ async function uploadFile(hosterName, filePath, apiKey, onProgress, signal, thro
|
|||||||
const targetUrl = config.buildUploadUrl(uploadUrl, apiKey);
|
const targetUrl = config.buildUploadUrl(uploadUrl, apiKey);
|
||||||
const formFields = config.formFields(apiKey);
|
const formFields = config.formFields(apiKey);
|
||||||
|
|
||||||
const { iterable, boundary, totalSize } = createUploadBody(filePath, formFields, onProgress, throttle, signal);
|
const { iterable, boundary, totalSize } = await createUploadBody(filePath, formFields, onProgress, throttle, signal);
|
||||||
|
|
||||||
const { body, statusCode, headers } = await request(targetUrl, {
|
const { body, statusCode, headers } = await request(targetUrl, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
|
|||||||
+4
-2
@@ -13,7 +13,7 @@ function page(items, args) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function createMcpApp({ loadConfig, invoke, invokeGuarded = (_context, channel, ...args) => invoke(channel, ...args), renderer, collectors, getGrants, trashFile, canWrite,
|
function createMcpApp({ loadConfig, invoke, invokeGuarded = (_context, channel, ...args) => invoke(channel, ...args), renderer, collectors, getGrants, trashFile, canWrite,
|
||||||
getCapabilities, getProtectedPaths, getInstallationId, getDiagnosticSources, getRuntimeDiagnostics = () => null }) {
|
getCapabilities, getProtectedPaths, getInstallationId, getDiagnosticSources, getRuntimeDiagnostics = () => null, getPerformance = () => null, updates }) {
|
||||||
const transfers = createMcpTransfers({ getGrants, getCapabilities, getProtectedPaths, getInstallationId });
|
const transfers = createMcpTransfers({ getGrants, getCapabilities, getProtectedPaths, getInstallationId });
|
||||||
const sanitize = createMcpSanitizer(loadConfig);
|
const sanitize = createMcpSanitizer(loadConfig);
|
||||||
const guard = context => {
|
const guard = context => {
|
||||||
@@ -57,6 +57,7 @@ function createMcpApp({ loadConfig, invoke, invokeGuarded = (_context, channel,
|
|||||||
...transfers.handlers,
|
...transfers.handlers,
|
||||||
...createMcpDiagnostics({ getSources: getDiagnosticSources, redact: text => sanitize(redactLogText(text, collectSecretValues(loadConfig()))) }),
|
...createMcpDiagnostics({ getSources: getDiagnosticSources, redact: text => sanitize(redactLogText(text, collectSecretValues(loadConfig()))) }),
|
||||||
mhu_app_info: () => invoke('get-app-info'),
|
mhu_app_info: () => invoke('get-app-info'),
|
||||||
|
mhu_performance_get: () => getPerformance(),
|
||||||
mhu_app_state: async (args, context) => ({ ...(await renderer('state', {}, context)), automation: await invoke('automation:get-status') }),
|
mhu_app_state: async (args, context) => ({ ...(await renderer('state', {}, context)), automation: await invoke('automation:get-status') }),
|
||||||
mhu_queue_list: (args, context) => renderer('queue-list', args, context),
|
mhu_queue_list: (args, context) => renderer('queue-list', args, context),
|
||||||
mhu_queue_job_log: async args => page(await invoke('get-job-log', args.jobId), args),
|
mhu_queue_job_log: async args => page(await invoke('get-job-log', args.jobId), args),
|
||||||
@@ -155,7 +156,8 @@ function createMcpApp({ loadConfig, invoke, invokeGuarded = (_context, channel,
|
|||||||
mhu_backup_delete: args => invoke('online-backup:delete-managed', args.id),
|
mhu_backup_delete: args => invoke('online-backup:delete-managed', args.id),
|
||||||
mhu_backup_restore: async (args, context) => { const result = await invokeGuarded(context, 'online-backup:restore', args.key); if (!result.ok) throw new McpAccessError('RESTORE_FAILED'); await refresh(context); return { ok: true, warnings: result.warnings }; },
|
mhu_backup_restore: async (args, context) => { const result = await invokeGuarded(context, 'online-backup:restore', args.key); if (!result.ok) throw new McpAccessError('RESTORE_FAILED'); await refresh(context); return { ok: true, warnings: result.warnings }; },
|
||||||
mhu_update_check: () => invoke('app:check-updates', { forceRefresh: true }),
|
mhu_update_check: () => invoke('app:check-updates', { forceRefresh: true }),
|
||||||
mhu_update_install: (args, context) => invokeGuarded(context, 'app:install-update'),
|
mhu_update_install: (args, context) => updates.start(args, context),
|
||||||
|
mhu_update_status: (args, context) => updates.status(args, context),
|
||||||
mhu_app_restart: () => invoke('app:restart'),
|
mhu_app_restart: () => invoke('app:restart'),
|
||||||
mhu_app_quit: () => invoke('app:quit'),
|
mhu_app_quit: () => invoke('app:quit'),
|
||||||
mhu_secrets_read: args => { const { password, apiKey } = find(args.accountId); return { accountId: args.accountId, password: password || '', apiKey: apiKey || '' }; }
|
mhu_secrets_read: args => { const { password, apiKey } = find(args.accountId); return { accountId: args.accountId, password: password || '', apiKey: apiKey || '' }; }
|
||||||
|
|||||||
+1
-1
@@ -86,7 +86,7 @@ class McpService {
|
|||||||
}
|
}
|
||||||
configure(args) {
|
configure(args) {
|
||||||
validateInput(args, { type: 'object', additionalProperties: false, required: ['enabled', 'name', 'capabilities'], properties: {
|
validateInput(args, { type: 'object', additionalProperties: false, required: ['enabled', 'name', 'capabilities'], properties: {
|
||||||
enabled: { type: 'boolean' }, name: { type: 'string', minLength: 1, maxLength: 100 }, capabilities: { type: 'array', maxItems: 4, items: { type: 'string', enum: CAPABILITIES } }
|
enabled: { type: 'boolean' }, name: { type: 'string', minLength: 1, maxLength: 100 }, capabilities: { type: 'array', maxItems: 5, items: { type: 'string', enum: CAPABILITIES } }
|
||||||
} });
|
} });
|
||||||
if (!args.name.trim()) throw new McpAccessError('INVALID_ARGUMENTS');
|
if (!args.name.trim()) throw new McpAccessError('INVALID_ARGUMENTS');
|
||||||
this.active = false;
|
this.active = false;
|
||||||
|
|||||||
+1
-1
@@ -4,7 +4,7 @@ const { randomUUID, randomBytes } = require('node:crypto');
|
|||||||
const { McpAccessError } = require('./mcp-access');
|
const { McpAccessError } = require('./mcp-access');
|
||||||
|
|
||||||
const RELAY_URL = 'https://downloader.24-music.de/mcp-relay';
|
const RELAY_URL = 'https://downloader.24-music.de/mcp-relay';
|
||||||
const CAPABILITIES = ['read', 'control', 'files', 'secrets'];
|
const CAPABILITIES = ['read', 'control', 'files', 'secrets', 'updates'];
|
||||||
|
|
||||||
class McpStore {
|
class McpStore {
|
||||||
constructor({ directory, encrypt, decrypt }) {
|
constructor({ directory, encrypt, decrypt }) {
|
||||||
|
|||||||
+3
-1
@@ -17,6 +17,7 @@ const file = { rootId: id, relativePath: text() };
|
|||||||
|
|
||||||
const definitions = [
|
const definitions = [
|
||||||
['app_info', 'Read application version and runtime information.', 'read', {}, []],
|
['app_info', 'Read application version and runtime information.', 'read', {}, []],
|
||||||
|
['performance_get', 'Read bounded in-memory main-thread, renderer, CPU, memory, I/O and transfer-slot measurements. Missing samples do not prove a freeze.', 'read', {}, []],
|
||||||
['app_state', 'Read live transfer and automation summary.', 'read', {}, []],
|
['app_state', 'Read live transfer and automation summary.', 'read', {}, []],
|
||||||
['queue_list', 'Read a bounded page of upload jobs.', 'read', { ...page, status: text(40) }, []],
|
['queue_list', 'Read a bounded page of upload jobs.', 'read', { ...page, status: text(40) }, []],
|
||||||
['queue_job_log', 'Read a bounded, secret-filtered log for one upload job.', 'read', { jobId: id, ...page }, ['jobId']],
|
['queue_job_log', 'Read a bounded, secret-filtered log for one upload job.', 'read', { jobId: id, ...page }, ['jobId']],
|
||||||
@@ -94,7 +95,8 @@ const definitions = [
|
|||||||
['backup_delete', 'Delete a selected managed online backup.', 'backup', { id }, ['id'], true],
|
['backup_delete', 'Delete a selected managed online backup.', 'backup', { id }, ['id'], true],
|
||||||
['backup_restore', 'Restore settings from an explicitly supplied online key.', 'backup', { key: text(200) }, ['key'], true],
|
['backup_restore', 'Restore settings from an explicitly supplied online key.', 'backup', { key: text(200) }, ['key'], true],
|
||||||
['update_check', 'Check for an application update without installing it.', 'read', {}, []],
|
['update_check', 'Check for an application update without installing it.', 'read', {}, []],
|
||||||
['update_install', 'Install an available application update.', 'lifecycle', {}, [], true],
|
['update_install', 'Submit an idempotent official installer update for one exact version. Requires separate local updates permission. Poll update_status; completion requires restart and reconnect.', 'updates', { targetVersion: { type: 'string', pattern: '^\\d+\\.\\d+\\.\\d+$', maxLength: 40 }, requestKey: id }, ['targetVersion', 'requestKey']],
|
||||||
|
['update_status', 'Read an owned persistent update job, including progress and post-restart version verification.', 'read', { jobId: id }, []],
|
||||||
['app_restart', 'Restart the application after persisting its state.', 'lifecycle', {}, [], true],
|
['app_restart', 'Restart the application after persisting its state.', 'lifecycle', {}, [], true],
|
||||||
['app_quit', 'Close the application after persisting its state.', 'lifecycle', {}, [], true],
|
['app_quit', 'Close the application after persisting its state.', 'lifecycle', {}, [], true],
|
||||||
['secrets_read', 'Explicitly reveal credentials for one account; disabled by default.', 'secrets.read', account, ['accountId']]
|
['secrets_read', 'Explicitly reveal credentials for one account; disabled by default.', 'secrets.read', account, ['accountId']]
|
||||||
|
|||||||
@@ -0,0 +1,165 @@
|
|||||||
|
const fs = require('node:fs/promises');
|
||||||
|
const path = require('node:path');
|
||||||
|
const { createHash, randomUUID } = require('node:crypto');
|
||||||
|
const { McpAccessError } = require('./mcp-access');
|
||||||
|
|
||||||
|
const VERSION = /^\d+\.\d+\.\d+$/;
|
||||||
|
const TERMINAL = new Set(['completed', 'failed']);
|
||||||
|
|
||||||
|
class McpUpdate {
|
||||||
|
constructor(options) {
|
||||||
|
this.options = options;
|
||||||
|
this.file = path.join(options.directory, 'mcp-update-jobs.json');
|
||||||
|
this.jobs = [];
|
||||||
|
this.writes = Promise.resolve();
|
||||||
|
this.task = null;
|
||||||
|
this.resumeTask = null;
|
||||||
|
this.ready = false;
|
||||||
|
}
|
||||||
|
async load() {
|
||||||
|
try {
|
||||||
|
const stat = await fs.lstat(this.file);
|
||||||
|
if (!stat.isFile() || stat.isSymbolicLink() || stat.size > 16 * 1024 * 1024) throw new Error('invalid');
|
||||||
|
const value = JSON.parse(await fs.readFile(this.file, 'utf8'));
|
||||||
|
if (value.version !== 1 || !Array.isArray(value.jobs) || value.jobs.length > 20
|
||||||
|
|| value.jobs.some(job => !job || !VERSION.test(job.targetVersion) || !/^[a-f0-9]{64}$/.test(job.owner) || !/^[A-Za-z0-9_.:-]{1,128}$/.test(job.requestKey))) throw new Error('invalid');
|
||||||
|
this.jobs = value.jobs;
|
||||||
|
} catch (error) {
|
||||||
|
if (error.code !== 'ENOENT') throw new McpAccessError('UPDATE_STORE_UNAVAILABLE');
|
||||||
|
}
|
||||||
|
this.ready = true;
|
||||||
|
}
|
||||||
|
async save() {
|
||||||
|
const data = JSON.stringify({ version: 1, jobs: this.jobs });
|
||||||
|
if (Buffer.byteLength(data) > 16 * 1024 * 1024) throw new McpAccessError('UPDATE_STORE_LIMIT');
|
||||||
|
const operation = this.writes.then(async () => {
|
||||||
|
await fs.mkdir(path.dirname(this.file), { recursive: true });
|
||||||
|
const temporary = this.file + '.' + randomUUID() + '.tmp';
|
||||||
|
let handle;
|
||||||
|
try {
|
||||||
|
handle = await fs.open(temporary, 'wx', 0o600);
|
||||||
|
await handle.writeFile(data);
|
||||||
|
await handle.sync();
|
||||||
|
await handle.close(); handle = null;
|
||||||
|
await fs.rename(temporary, this.file);
|
||||||
|
} finally {
|
||||||
|
await handle?.close();
|
||||||
|
await fs.unlink(temporary).catch(() => {});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
this.writes = operation.catch(() => {});
|
||||||
|
return operation;
|
||||||
|
}
|
||||||
|
owner(context) { return createHash('sha256').update(context.principalId).digest('hex'); }
|
||||||
|
active() { return this.jobs.find(job => !TERMINAL.has(job.phase)); }
|
||||||
|
blocksTransfers() { const job = this.active(); return !!job && job.phase !== 'awaiting_reconnect'; }
|
||||||
|
public(job) {
|
||||||
|
if (!job) return null;
|
||||||
|
const { owner: _owner, requestKey: _key, resume: _resume, ...value } = job;
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
status(args, context) {
|
||||||
|
const job = args.jobId ? this.jobs.find(item => item.id === args.jobId) : this.jobs.at(-1);
|
||||||
|
if (job && job.owner !== this.owner(context)) throw new McpAccessError('UPDATE_NOT_FOUND');
|
||||||
|
return { job: this.public(job) };
|
||||||
|
}
|
||||||
|
assertAllowed() {
|
||||||
|
if (!this.ready) throw new McpAccessError('UPDATE_STORE_UNAVAILABLE');
|
||||||
|
if (!this.options.canUpdate()) throw new McpAccessError('SCOPE_DENIED');
|
||||||
|
}
|
||||||
|
async phase(job, phase, patch = {}) {
|
||||||
|
Object.assign(job, patch, { phase, updatedAt: Date.now() });
|
||||||
|
await this.save();
|
||||||
|
}
|
||||||
|
async start({ targetVersion, requestKey }, context) {
|
||||||
|
this.assertAllowed();
|
||||||
|
if (!VERSION.test(targetVersion)) throw new McpAccessError('INVALID_ARGUMENTS');
|
||||||
|
const owner = this.owner(context);
|
||||||
|
const existing = this.jobs.find(job => job.owner === owner && job.requestKey === requestKey);
|
||||||
|
if (existing) {
|
||||||
|
if (existing.targetVersion !== targetVersion) throw new McpAccessError('REQUEST_CONFLICT');
|
||||||
|
return this.public(existing);
|
||||||
|
}
|
||||||
|
if (this.active() || this.task) throw new McpAccessError('UPDATE_BUSY');
|
||||||
|
if (!await this.options.supported()) throw new McpAccessError('UPDATE_INSTALLATION_UNSUPPORTED');
|
||||||
|
this.assertAllowed();
|
||||||
|
if (this.active()) throw new McpAccessError('UPDATE_BUSY');
|
||||||
|
const job = { id: randomUUID(), owner, requestKey, targetVersion, sourceVersion: this.options.version(), phase: 'accepted', createdAt: Date.now(), updatedAt: Date.now() };
|
||||||
|
const previous = this.jobs;
|
||||||
|
this.jobs = [...this.jobs.slice(-19), job];
|
||||||
|
try { await this.save(); }
|
||||||
|
catch (error) { this.jobs = previous; throw error; }
|
||||||
|
this.task = new Promise(resolve => setImmediate(resolve)).then(() => this.execute(job)).finally(() => { this.task = null; });
|
||||||
|
return this.public(job);
|
||||||
|
}
|
||||||
|
async execute(job) {
|
||||||
|
let parked = false;
|
||||||
|
try {
|
||||||
|
this.assertAllowed();
|
||||||
|
await this.phase(job, 'checking');
|
||||||
|
const release = await this.options.check();
|
||||||
|
if (!release?.available || release.remoteVersion !== job.targetVersion) throw new McpAccessError('UPDATE_VERSION_MISMATCH');
|
||||||
|
this.assertAllowed();
|
||||||
|
await this.phase(job, 'downloading');
|
||||||
|
const prepared = await this.options.prepare(release, progress => {
|
||||||
|
job.progress = { stage: progress.stage, percent: progress.percent, bytesDownloaded: progress.bytesDownloaded, bytesTotal: progress.bytesTotal };
|
||||||
|
});
|
||||||
|
this.assertAllowed();
|
||||||
|
if (prepared.remoteVersion !== job.targetVersion || !prepared.sha512Verified || !prepared.sha512) throw new McpAccessError('UPDATE_INTEGRITY_REQUIRED');
|
||||||
|
await this.phase(job, 'waiting_uploads', { sha512: prepared.sha512 });
|
||||||
|
job.resume = await this.options.park();
|
||||||
|
await this.save();
|
||||||
|
parked = true;
|
||||||
|
await this.options.drain(() => this.assertAllowed());
|
||||||
|
this.assertAllowed();
|
||||||
|
await this.options.verify(prepared);
|
||||||
|
this.assertAllowed();
|
||||||
|
await this.phase(job, 'quiescing');
|
||||||
|
await this.options.handoff(prepared, job);
|
||||||
|
} catch (error) {
|
||||||
|
const code = error instanceof McpAccessError ? error.code : 'UPDATE_FAILED';
|
||||||
|
try {
|
||||||
|
if (parked && job.resume) await this.options.restore(job.resume);
|
||||||
|
await this.phase(job, 'failed', { errorCode: code, resume: null });
|
||||||
|
} catch { job.phase = 'failed'; job.errorCode = 'UPDATE_RECOVERY_FAILED'; }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
async markLaunching() {
|
||||||
|
const job = this.active();
|
||||||
|
if (!job || job.phase !== 'quiescing') throw new McpAccessError('UPDATE_STATE_INVALID');
|
||||||
|
this.assertAllowed();
|
||||||
|
await this.phase(job, 'awaiting_restart');
|
||||||
|
}
|
||||||
|
async launchFailed() {
|
||||||
|
const job = this.active();
|
||||||
|
if (job) await this.phase(job, 'failed', { errorCode: 'UPDATE_LAUNCH_FAILED' });
|
||||||
|
}
|
||||||
|
async recover({ rendererReady, connected }) {
|
||||||
|
if (!this.ready || this.task || this.resumeTask || !rendererReady) return;
|
||||||
|
const job = this.active();
|
||||||
|
if (!job) return;
|
||||||
|
this.resumeTask = (async () => {
|
||||||
|
if (job.phase === 'awaiting_reconnect') {
|
||||||
|
if (connected) await this.phase(job, 'completed', { completedAt: Date.now(), reconnectedAt: Date.now() });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (job.phase !== 'awaiting_restart' && job.phase !== 'resuming') {
|
||||||
|
if (job.resume) await this.options.restore(job.resume);
|
||||||
|
await this.phase(job, 'failed', { errorCode: 'UPDATE_INTERRUPTED', resume: null });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (this.options.version() !== job.targetVersion) {
|
||||||
|
if (job.resume) await this.options.restore(job.resume);
|
||||||
|
await this.phase(job, 'failed', { errorCode: 'UPDATE_VERSION_NOT_INSTALLED', installedVersion: this.options.version(), resume: null });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
await this.phase(job, 'resuming', { installedVersion: this.options.version() });
|
||||||
|
if (job.resume) await this.options.restore(job.resume);
|
||||||
|
await this.phase(job, connected ? 'completed' : 'awaiting_reconnect', { restoredAt: Date.now(), resume: null,
|
||||||
|
...(connected ? { completedAt: Date.now(), reconnectedAt: Date.now() } : {}) });
|
||||||
|
})().catch(async () => { await this.phase(job, 'failed', { errorCode: 'UPDATE_RECOVERY_FAILED' }).catch(() => {}); }).finally(() => { this.resumeTask = null; });
|
||||||
|
return this.resumeTask;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = { McpUpdate };
|
||||||
@@ -0,0 +1,88 @@
|
|||||||
|
const { performance } = require('node:perf_hooks');
|
||||||
|
const { randomUUID } = require('node:crypto');
|
||||||
|
|
||||||
|
class PerformanceMonitor {
|
||||||
|
constructor({ now = Date.now, monotonic = () => performance.now(), cpu = () => process.cpuUsage(), memory = () => process.memoryUsage(), limit = 600 } = {}) {
|
||||||
|
this.now = now;
|
||||||
|
this.monotonic = monotonic;
|
||||||
|
this.cpu = cpu;
|
||||||
|
this.memory = memory;
|
||||||
|
this.limit = limit;
|
||||||
|
this.bootId = randomUUID();
|
||||||
|
this.startedAt = now();
|
||||||
|
this.samples = [];
|
||||||
|
this.events = [];
|
||||||
|
this.operations = new Map();
|
||||||
|
this.pendingRenderer = new Map();
|
||||||
|
this.sequence = 0;
|
||||||
|
this.timer = null;
|
||||||
|
}
|
||||||
|
record(name, durationMs, failed = false) {
|
||||||
|
if (!/^[a-z][a-z0-9_.:-]{0,79}$/.test(name) || !Number.isFinite(durationMs) || durationMs < 0) return;
|
||||||
|
if (!this.operations.has(name) && this.operations.size >= 128) return;
|
||||||
|
const item = this.operations.get(name) || { name, count: 0, failed: 0, totalMs: 0, maxMs: 0, active: 0 };
|
||||||
|
item.count++;
|
||||||
|
item.failed += Number(failed);
|
||||||
|
item.totalMs += durationMs;
|
||||||
|
item.maxMs = Math.max(item.maxMs, durationMs);
|
||||||
|
item.lastMs = durationMs;
|
||||||
|
item.lastAt = this.now();
|
||||||
|
this.operations.set(name, item);
|
||||||
|
if (durationMs >= 1000) this.event('operation', { name, durationMs, failed });
|
||||||
|
}
|
||||||
|
async measure(name, operation) {
|
||||||
|
const started = this.monotonic();
|
||||||
|
let failed = false;
|
||||||
|
try { return await operation(); }
|
||||||
|
catch (error) { failed = true; throw error; }
|
||||||
|
finally { this.record(name, this.monotonic() - started, failed); }
|
||||||
|
}
|
||||||
|
event(type, details = {}) {
|
||||||
|
this.events.push({ id: ++this.sequence, at: this.now(), type, ...details });
|
||||||
|
if (this.events.length > this.limit) this.events.splice(0, this.events.length - this.limit);
|
||||||
|
}
|
||||||
|
rendererReply(id) {
|
||||||
|
const started = this.pendingRenderer.get(id);
|
||||||
|
if (started === undefined) return;
|
||||||
|
this.pendingRenderer.delete(id);
|
||||||
|
const durationMs = this.monotonic() - started;
|
||||||
|
this.record('renderer.roundtrip', durationMs);
|
||||||
|
}
|
||||||
|
start({ version, getTransfers = () => null, pingRenderer = () => false } = {}) {
|
||||||
|
if (this.timer) return;
|
||||||
|
this.version = version;
|
||||||
|
let previous = this.monotonic();
|
||||||
|
let previousCpu = this.cpu();
|
||||||
|
this.timer = setInterval(() => {
|
||||||
|
const current = this.monotonic();
|
||||||
|
const elapsed = current - previous;
|
||||||
|
const currentCpu = this.cpu();
|
||||||
|
const delayMs = Math.max(0, elapsed - 1000);
|
||||||
|
const sample = { at: this.now(), elapsedMs: elapsed, delayMs, cpuPercent: elapsed > 0 ? (currentCpu.user + currentCpu.system - previousCpu.user - previousCpu.system) / (elapsed * 10) : 0,
|
||||||
|
memory: this.memory(), transfers: getTransfers() };
|
||||||
|
this.samples.push(sample);
|
||||||
|
if (this.samples.length > this.limit) this.samples.shift();
|
||||||
|
if (delayMs > 30000) this.event('measurement-gap', { durationMs: delayMs });
|
||||||
|
else if (delayMs >= 1000) this.event('main-delay', { durationMs: delayMs });
|
||||||
|
for (const [id, started] of this.pendingRenderer) if (current - started >= 5000) {
|
||||||
|
this.pendingRenderer.delete(id);
|
||||||
|
this.event('renderer-unanswered', { durationMs: current - started });
|
||||||
|
}
|
||||||
|
if (!this.pendingRenderer.size) {
|
||||||
|
const id = ++this.sequence;
|
||||||
|
if (pingRenderer(id)) this.pendingRenderer.set(id, current);
|
||||||
|
}
|
||||||
|
previous = current;
|
||||||
|
previousCpu = currentCpu;
|
||||||
|
}, 1000);
|
||||||
|
this.timer.unref?.();
|
||||||
|
}
|
||||||
|
stop() { clearInterval(this.timer); this.timer = null; this.pendingRenderer.clear(); }
|
||||||
|
snapshot() {
|
||||||
|
return { bootId: this.bootId, version: this.version || null, startedAt: this.startedAt, sampledAt: this.now(), running: !!this.timer,
|
||||||
|
samples: this.samples.slice(-300), events: this.events.slice(), operations: [...this.operations.values()].map(item => ({ ...item })) };
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const runtimePerformance = new PerformanceMonitor();
|
||||||
|
module.exports = { PerformanceMonitor, runtimePerformance };
|
||||||
+3
-3
@@ -46,12 +46,12 @@ class Semaphore {
|
|||||||
}
|
}
|
||||||
|
|
||||||
release() {
|
release() {
|
||||||
if (this.queue.length > 0) {
|
this.active = Math.max(0, this.active - 1);
|
||||||
|
if (this.active < this.limit && this.queue.length > 0) {
|
||||||
const entry = this.queue.shift();
|
const entry = this.queue.shift();
|
||||||
this._cleanupEntry(entry);
|
this._cleanupEntry(entry);
|
||||||
|
this.active++;
|
||||||
entry.resolve();
|
entry.resolve();
|
||||||
} else {
|
|
||||||
this.active = Math.max(0, this.active - 1);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+53
-22
@@ -232,12 +232,6 @@ async function parseLatestYml(url, expected = {}, fetchImpl = fetch) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function verifyExeHeader(buf) {
|
|
||||||
// Check MZ header
|
|
||||||
if (buf.length < 128 * 1024) return false;
|
|
||||||
return buf[0] === 0x4D && buf[1] === 0x5A; // 'MZ'
|
|
||||||
}
|
|
||||||
|
|
||||||
async function prepareUpdate(onProgress, options = {}) {
|
async function prepareUpdate(onProgress, options = {}) {
|
||||||
if (activeAbort) activeAbort.abort();
|
if (activeAbort) activeAbort.abort();
|
||||||
const controller = new AbortController();
|
const controller = new AbortController();
|
||||||
@@ -246,6 +240,7 @@ async function prepareUpdate(onProgress, options = {}) {
|
|||||||
const fetchImpl = options.fetchImpl || fetch;
|
const fetchImpl = options.fetchImpl || fetch;
|
||||||
const now = typeof options.now === 'function' ? options.now : Date.now;
|
const now = typeof options.now === 'function' ? options.now : Date.now;
|
||||||
let stagedInstallerPath = '';
|
let stagedInstallerPath = '';
|
||||||
|
let downloadDirectory = '';
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// Stage: starting
|
// Stage: starting
|
||||||
@@ -273,9 +268,12 @@ async function prepareUpdate(onProgress, options = {}) {
|
|||||||
|
|
||||||
// Stage: downloading
|
// Stage: downloading
|
||||||
const tmpDir = options.tempDir || app.getPath('temp');
|
const tmpDir = options.tempDir || app.getPath('temp');
|
||||||
const installerPath = path.join(tmpDir, check.assetName);
|
downloadDirectory = await fs.promises.mkdtemp(path.join(tmpDir, 'mhu-update-'));
|
||||||
|
const installerPath = path.join(downloadDirectory, path.basename(check.assetName));
|
||||||
|
stagedInstallerPath = installerPath;
|
||||||
|
|
||||||
let fileBuffer;
|
let actualSha;
|
||||||
|
let firstBytes;
|
||||||
for (let attempt = 1; attempt <= 3; attempt++) {
|
for (let attempt = 1; attempt <= 3; attempt++) {
|
||||||
signal.throwIfAborted();
|
signal.throwIfAborted();
|
||||||
const downloadController = new AbortController();
|
const downloadController = new AbortController();
|
||||||
@@ -307,7 +305,10 @@ async function prepareUpdate(onProgress, options = {}) {
|
|||||||
let downloadedBytes = 0;
|
let downloadedBytes = 0;
|
||||||
let lastReportedPercent = -1;
|
let lastReportedPercent = -1;
|
||||||
const downloadStartedAt = now();
|
const downloadStartedAt = now();
|
||||||
const chunks = [];
|
const output = await fs.promises.open(installerPath, 'w', 0o600);
|
||||||
|
const hash = crypto.createHash('sha512');
|
||||||
|
firstBytes = Buffer.alloc(0);
|
||||||
|
try {
|
||||||
if (attempt > 1 && onProgress) onProgress({ stage: 'downloading', percent: 0, bytesDownloaded: 0, bytesTotal: manifest.size, bytesPerSecond: 0, etaSeconds: null, attempt });
|
if (attempt > 1 && onProgress) onProgress({ stage: 'downloading', percent: 0, bytesDownloaded: 0, bytesTotal: manifest.size, bytesPerSecond: 0, etaSeconds: null, attempt });
|
||||||
while (true) {
|
while (true) {
|
||||||
signal.throwIfAborted();
|
signal.throwIfAborted();
|
||||||
@@ -317,7 +318,9 @@ async function prepareUpdate(onProgress, options = {}) {
|
|||||||
if (done) break;
|
if (done) break;
|
||||||
downloadedBytes += value.length;
|
downloadedBytes += value.length;
|
||||||
if (downloadedBytes > manifest.size) throw new Error('Heruntergeladene Datei hat eine abweichende Größe');
|
if (downloadedBytes > manifest.size) throw new Error('Heruntergeladene Datei hat eine abweichende Größe');
|
||||||
chunks.push(value);
|
if (firstBytes.length < 2) firstBytes = Buffer.concat([firstBytes, Buffer.from(value).subarray(0, 2 - firstBytes.length)]);
|
||||||
|
hash.update(value);
|
||||||
|
await output.writeFile(value);
|
||||||
const percent = Math.floor((downloadedBytes / manifest.size) * 100);
|
const percent = Math.floor((downloadedBytes / manifest.size) * 100);
|
||||||
if (onProgress && percent !== lastReportedPercent) {
|
if (onProgress && percent !== lastReportedPercent) {
|
||||||
const elapsedMs = Math.max(1, now() - downloadStartedAt);
|
const elapsedMs = Math.max(1, now() - downloadStartedAt);
|
||||||
@@ -334,7 +337,9 @@ async function prepareUpdate(onProgress, options = {}) {
|
|||||||
error.retryable = true;
|
error.retryable = true;
|
||||||
throw error;
|
throw error;
|
||||||
}
|
}
|
||||||
fileBuffer = Buffer.concat(chunks);
|
await output.sync();
|
||||||
|
actualSha = hash.digest('base64');
|
||||||
|
} finally { await output.close(); }
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
signal.throwIfAborted();
|
signal.throwIfAborted();
|
||||||
retry = timedOut || error.retryable === true || ['UND_ERR_SOCKET', 'ECONNRESET', 'ETIMEDOUT', 'EPIPE', 'UND_ERR_CONNECT_TIMEOUT', 'UND_ERR_BODY_TIMEOUT'].includes(error.cause?.code || error.code) || /^(terminated|fetch failed)$/i.test(error.message);
|
retry = timedOut || error.retryable === true || ['UND_ERR_SOCKET', 'ECONNRESET', 'ETIMEDOUT', 'EPIPE', 'UND_ERR_CONNECT_TIMEOUT', 'UND_ERR_BODY_TIMEOUT'].includes(error.cause?.code || error.code) || /^(terminated|fetch failed)$/i.test(error.message);
|
||||||
@@ -356,36 +361,35 @@ async function prepareUpdate(onProgress, options = {}) {
|
|||||||
// Stage: verifying
|
// Stage: verifying
|
||||||
if (onProgress) onProgress({ stage: 'verifying', percent: 0 });
|
if (onProgress) onProgress({ stage: 'verifying', percent: 0 });
|
||||||
|
|
||||||
if (!verifyExeHeader(fileBuffer)) {
|
if (manifest.size < 128 * 1024 || firstBytes[0] !== 0x4d || firstBytes[1] !== 0x5a) {
|
||||||
throw new Error('Heruntergeladene Datei ist keine gültige EXE');
|
throw new Error('Heruntergeladene Datei ist keine gültige EXE');
|
||||||
}
|
}
|
||||||
|
|
||||||
const actualSha = crypto.createHash('sha512').update(fileBuffer).digest('base64');
|
|
||||||
if (actualSha !== expectedSha) {
|
if (actualSha !== expectedSha) {
|
||||||
const actualHex = crypto.createHash('sha512').update(fileBuffer).digest('hex');
|
const actualHex = Buffer.from(actualSha, 'base64').toString('hex');
|
||||||
if (actualHex !== expectedSha.toLowerCase()) {
|
if (actualHex !== expectedSha.toLowerCase()) {
|
||||||
throw new Error('SHA-512 Prüfung fehlgeschlagen');
|
throw new Error('SHA-512 Prüfung fehlgeschlagen');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
stagedInstallerPath = path.join(tmpDir, `${path.basename(check.assetName)}.${crypto.randomUUID()}.download`);
|
|
||||||
fs.writeFileSync(stagedInstallerPath, fileBuffer);
|
|
||||||
fs.rmSync(installerPath, { force: true });
|
|
||||||
fs.renameSync(stagedInstallerPath, installerPath);
|
|
||||||
stagedInstallerPath = '';
|
|
||||||
|
|
||||||
const prepared = {
|
const prepared = {
|
||||||
installerPath,
|
installerPath,
|
||||||
|
sha512: actualSha,
|
||||||
|
size: manifest.size,
|
||||||
|
sha512Verified: true,
|
||||||
assetName: check.assetName,
|
assetName: check.assetName,
|
||||||
remoteVersion: check.remoteVersion || '',
|
remoteVersion: check.remoteVersion || '',
|
||||||
transportTag: check.transportTag || ''
|
transportTag: check.transportTag || ''
|
||||||
};
|
};
|
||||||
|
await verifyPreparedUpdate(prepared);
|
||||||
|
stagedInstallerPath = '';
|
||||||
if (onProgress) onProgress({ stage: 'prepared', percent: 100 });
|
if (onProgress) onProgress({ stage: 'prepared', percent: 100 });
|
||||||
return prepared;
|
return prepared;
|
||||||
|
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
const failure = signal.aborted ? new Error('Update abgebrochen') : err;
|
const failure = signal.aborted ? new Error('Update abgebrochen') : err;
|
||||||
if (stagedInstallerPath) fs.rmSync(stagedInstallerPath, { force: true });
|
if (stagedInstallerPath) await fs.promises.unlink(stagedInstallerPath).catch(() => {});
|
||||||
|
if (downloadDirectory) await fs.promises.rmdir(downloadDirectory).catch(() => {});
|
||||||
if (onProgress) onProgress({ stage: signal.aborted ? 'aborted' : 'error', error: failure.message });
|
if (onProgress) onProgress({ stage: signal.aborted ? 'aborted' : 'error', error: failure.message });
|
||||||
throw failure;
|
throw failure;
|
||||||
} finally {
|
} finally {
|
||||||
@@ -393,6 +397,32 @@ async function prepareUpdate(onProgress, options = {}) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function verifyPreparedUpdate(prepared) {
|
||||||
|
if (!prepared?.sha512Verified || !prepared.sha512 || !Number.isSafeInteger(prepared.size)) throw new Error('Update-Prüfsumme fehlt');
|
||||||
|
const stat = await fs.promises.lstat(prepared.installerPath);
|
||||||
|
if (!stat.isFile() || stat.isSymbolicLink() || stat.nlink !== 1 || stat.size !== prepared.size) throw new Error('Update-Datei wurde verändert');
|
||||||
|
const handle = await fs.promises.open(prepared.installerPath, 'r');
|
||||||
|
try {
|
||||||
|
const hash = crypto.createHash('sha512');
|
||||||
|
const before = await handle.stat();
|
||||||
|
if (before.ino !== stat.ino || before.dev !== stat.dev || before.size !== stat.size) throw new Error('Update-Datei wurde ausgetauscht');
|
||||||
|
for await (const chunk of handle.createReadStream({ autoClose: false })) hash.update(chunk);
|
||||||
|
const after = await handle.stat();
|
||||||
|
if (after.size !== before.size || after.mtimeMs !== before.mtimeMs || after.ctimeMs !== before.ctimeMs || hash.digest('base64') !== prepared.sha512) throw new Error('SHA-512 Prüfung fehlgeschlagen');
|
||||||
|
} finally { await handle.close(); }
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
async function launchVerifiedUpdate(prepared, directory, options = {}) {
|
||||||
|
await verifyPreparedUpdate(prepared);
|
||||||
|
const spawn = options.spawnImpl || require('node:child_process').spawn;
|
||||||
|
const child = spawn(prepared.installerPath, ['/S', '--updated', '--force-run', `/D=${directory}`], { detached: true, windowsHide: true, stdio: 'ignore' });
|
||||||
|
await new Promise((resolve, reject) => { child.once('error', reject); child.once('spawn', resolve); });
|
||||||
|
child.unref();
|
||||||
|
launchedInstallerPaths.add(path.resolve(prepared.installerPath).toLowerCase());
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
function launchPreparedUpdate(prepared, options = {}) {
|
function launchPreparedUpdate(prepared, options = {}) {
|
||||||
const installerPath = prepared && typeof prepared.installerPath === 'string' ? prepared.installerPath : '';
|
const installerPath = prepared && typeof prepared.installerPath === 'string' ? prepared.installerPath : '';
|
||||||
if (!installerPath) throw new Error('Vorbereitetes Update ist unvollständig');
|
if (!installerPath) throw new Error('Vorbereitetes Update ist unvollständig');
|
||||||
@@ -403,6 +433,7 @@ function launchPreparedUpdate(prepared, options = {}) {
|
|||||||
try {
|
try {
|
||||||
spawnImpl(installerPath, ['/S', '--updated', '--force-run'], {
|
spawnImpl(installerPath, ['/S', '--updated', '--force-run'], {
|
||||||
detached: true,
|
detached: true,
|
||||||
|
windowsHide: true,
|
||||||
stdio: 'ignore'
|
stdio: 'ignore'
|
||||||
}).unref();
|
}).unref();
|
||||||
return true;
|
return true;
|
||||||
@@ -418,4 +449,4 @@ function abortUpdate() {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = { checkForUpdate, fetchGithubReleaseNotes, prepareUpdate, launchPreparedUpdate, abortUpdate, isNewer, resolveReleaseVersion, pickSetupAsset, parseLatestYml, createUpdateAnnouncementState };
|
module.exports = { checkForUpdate, fetchGithubReleaseNotes, prepareUpdate, verifyPreparedUpdate, launchVerifiedUpdate, launchPreparedUpdate, abortUpdate, isNewer, resolveReleaseVersion, pickSetupAsset, parseLatestYml, createUpdateAnnouncementState };
|
||||||
@@ -0,0 +1,23 @@
|
|||||||
|
const fs = require('node:fs');
|
||||||
|
const { runtimePerformance } = require('./performance-monitor');
|
||||||
|
|
||||||
|
const statUploadFile = file => runtimePerformance.measure('file.stat', () => fs.promises.stat(file));
|
||||||
|
|
||||||
|
async function* readUploadFile(file, signal) {
|
||||||
|
signal?.throwIfAborted();
|
||||||
|
const stream = fs.createReadStream(file, { highWaterMark: 1024 * 1024, ...(signal ? { signal } : {}) });
|
||||||
|
const iterator = stream[Symbol.asyncIterator]();
|
||||||
|
try {
|
||||||
|
for (;;) {
|
||||||
|
const result = await runtimePerformance.measure('file.read', () => iterator.next());
|
||||||
|
if (result.done) break;
|
||||||
|
signal?.throwIfAborted();
|
||||||
|
yield result.value;
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
stream.destroy();
|
||||||
|
await iterator.return?.();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = { statUploadFile, readUploadFile };
|
||||||
+41
-22
@@ -10,6 +10,7 @@ const DoodstreamUploader = require('./doodstream-upload');
|
|||||||
const ClouddropUploader = require('./clouddrop-upload');
|
const ClouddropUploader = require('./clouddrop-upload');
|
||||||
const Semaphore = require('./semaphore');
|
const Semaphore = require('./semaphore');
|
||||||
const Throttle = require('./throttle');
|
const Throttle = require('./throttle');
|
||||||
|
const { runtimePerformance } = require('./performance-monitor');
|
||||||
const { probeFileHead } = require('./file-probe');
|
const { probeFileHead } = require('./file-probe');
|
||||||
const { normalizeFailureDetails } = require('./upload-diagnostics');
|
const { normalizeFailureDetails } = require('./upload-diagnostics');
|
||||||
const { classifyAccountFailure, selectFallbackAccount } = require('./account-rotation');
|
const { classifyAccountFailure, selectFallbackAccount } = require('./account-rotation');
|
||||||
@@ -47,6 +48,7 @@ class UploadManager extends EventEmitter {
|
|||||||
this.pendingCancelledJobIds = new Set();
|
this.pendingCancelledJobIds = new Set();
|
||||||
this.pendingCancelAll = false;
|
this.pendingCancelAll = false;
|
||||||
this.sessionBytes = 0;
|
this.sessionBytes = 0;
|
||||||
|
this.transferredBytes = 0;
|
||||||
this._transientErrorTotal = 0;
|
this._transientErrorTotal = 0;
|
||||||
this.lastStartTime = {}; // hoster -> timestamp of last upload start
|
this.lastStartTime = {}; // hoster -> timestamp of last upload start
|
||||||
this.intervalLocks = {}; // hoster -> Promise chain for serialized interval waits
|
this.intervalLocks = {}; // hoster -> Promise chain for serialized interval waits
|
||||||
@@ -115,13 +117,28 @@ class UploadManager extends EventEmitter {
|
|||||||
|
|
||||||
getDiagnostics() {
|
getDiagnostics() {
|
||||||
const activeByHoster = {};
|
const activeByHoster = {};
|
||||||
|
const phases = {};
|
||||||
for (const v of this.activeJobs.values()) {
|
for (const v of this.activeJobs.values()) {
|
||||||
const h = v && v.hoster ? v.hoster : 'unknown';
|
const h = v && v.hoster ? v.hoster : 'unknown';
|
||||||
activeByHoster[h] = (activeByHoster[h] || 0) + 1;
|
activeByHoster[h] = (activeByHoster[h] || 0) + 1;
|
||||||
|
const phase = v.phase || 'getting-server';
|
||||||
|
phases[phase] = (phases[phase] || 0) + 1;
|
||||||
}
|
}
|
||||||
let pending = 0;
|
let pending = 0;
|
||||||
for (const sem of Object.values(this.semaphores)) pending += (sem && sem.pending) || 0;
|
for (const sem of Object.values(this.semaphores)) pending += (sem && sem.pending) || 0;
|
||||||
return { activeByHoster, transientErrors: this._transientErrorTotal, pending, active: this.activeJobs.size };
|
return { activeByHoster, transientErrors: this._transientErrorTotal, pending, active: this.activeJobs.size,
|
||||||
|
globalSlots: this.globalSemaphore ? { active: this.globalSemaphore.active, pending: this.globalSemaphore.pending, limit: this.globalSemaphore.limit } : null,
|
||||||
|
hosterSlots: Object.fromEntries(Object.entries(this.semaphores).map(([hoster, sem]) => [hoster, { active: sem.active, pending: sem.pending, limit: sem.limit }])),
|
||||||
|
sessionBytes: this.sessionBytes, transferredBytes: this.transferredBytes, batchStartedAt: this.startTime,
|
||||||
|
speedKbs: [...this.activeJobs.values()].reduce((sum, job) => sum + (job.speedKbs || 0), 0), phases };
|
||||||
|
}
|
||||||
|
|
||||||
|
_recordTransferred(entry, bytes, total) {
|
||||||
|
if (!Number.isFinite(bytes) || bytes < 0) return;
|
||||||
|
const next = Math.min(bytes, total);
|
||||||
|
this.transferredBytes += Math.max(0, next - entry.bytesUploaded);
|
||||||
|
entry.bytesUploaded = next;
|
||||||
|
entry.phase = next >= total ? 'awaiting-confirmation' : 'uploading';
|
||||||
}
|
}
|
||||||
|
|
||||||
clearFailedAccount(hoster, accountId) {
|
clearFailedAccount(hoster, accountId) {
|
||||||
@@ -368,6 +385,7 @@ class UploadManager extends EventEmitter {
|
|||||||
if (pendingCancelAll) this.abortController.abort();
|
if (pendingCancelAll) this.abortController.abort();
|
||||||
this.startTime = Date.now();
|
this.startTime = Date.now();
|
||||||
this.sessionBytes = 0;
|
this.sessionBytes = 0;
|
||||||
|
this.transferredBytes = 0;
|
||||||
this.activeJobs.clear();
|
this.activeJobs.clear();
|
||||||
this.jobAbortControllers.clear();
|
this.jobAbortControllers.clear();
|
||||||
this.cancelledJobIds.clear();
|
this.cancelledJobIds.clear();
|
||||||
@@ -478,6 +496,7 @@ class UploadManager extends EventEmitter {
|
|||||||
} else {
|
} else {
|
||||||
try { fileSize = (await fs.promises.stat(task.file)).size; } catch { fileNotFound = true; }
|
try { fileSize = (await fs.promises.stat(task.file)).size; } catch { fileNotFound = true; }
|
||||||
}
|
}
|
||||||
|
if (cachedResult && fileSize > 0) cachedResult.size = fileSize;
|
||||||
|
|
||||||
const maxAttempts = Math.max(1, (settings.retries || 0) + 1);
|
const maxAttempts = Math.max(1, (settings.retries || 0) + 1);
|
||||||
const jobAbortController = new AbortController();
|
const jobAbortController = new AbortController();
|
||||||
@@ -502,6 +521,7 @@ class UploadManager extends EventEmitter {
|
|||||||
if (finalResultRecorded) return;
|
if (finalResultRecorded) return;
|
||||||
finalResultRecorded = true;
|
finalResultRecorded = true;
|
||||||
finalStatus = status;
|
finalStatus = status;
|
||||||
|
if (status === 'error') runtimePerformance.event('upload-error', { hoster: task.hoster });
|
||||||
|
|
||||||
const result = {
|
const result = {
|
||||||
jobId,
|
jobId,
|
||||||
@@ -573,7 +593,7 @@ class UploadManager extends EventEmitter {
|
|||||||
// queueJobs array; the first event it actually needs from main is the
|
// queueJobs array; the first event it actually needs from main is the
|
||||||
// 'getting-server' / 'uploading' transition for the jobs that the
|
// 'getting-server' / 'uploading' transition for the jobs that the
|
||||||
// semaphore lets through.
|
// semaphore lets through.
|
||||||
await hosterSemaphore.acquire(admissionSignal);
|
await runtimePerformance.measure('slots.hoster', () => hosterSemaphore.acquire(admissionSignal));
|
||||||
hosterSlotAcquired = true;
|
hosterSlotAcquired = true;
|
||||||
|
|
||||||
if (this.stopAfterActive) {
|
if (this.stopAfterActive) {
|
||||||
@@ -585,7 +605,7 @@ class UploadManager extends EventEmitter {
|
|||||||
|
|
||||||
let fileProbe = null;
|
let fileProbe = null;
|
||||||
try {
|
try {
|
||||||
fileProbe = await probeFileHead(task.file, 512);
|
fileProbe = await runtimePerformance.measure('file.probe', () => probeFileHead(task.file, 512));
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
fileProbe = { ok: false, error: err && err.message, kind: 'unreadable' };
|
fileProbe = { ok: false, error: err && err.message, kind: 'unreadable' };
|
||||||
}
|
}
|
||||||
@@ -597,16 +617,15 @@ class UploadManager extends EventEmitter {
|
|||||||
headHex: fileProbe && fileProbe.headHex ? fileProbe.headHex.slice(0, 32) : null
|
headHex: fileProbe && fileProbe.headHex ? fileProbe.headHex.slice(0, 32) : null
|
||||||
});
|
});
|
||||||
|
|
||||||
if (globalSemaphore) {
|
const acquireGlobal = async () => {
|
||||||
await globalSemaphore.acquire(admissionSignal);
|
if (globalSemaphore) {
|
||||||
globalSlotAcquired = true;
|
await runtimePerformance.measure('slots.global', () => globalSemaphore.acquire(admissionSignal));
|
||||||
}
|
globalSlotAcquired = true;
|
||||||
|
}
|
||||||
if (this.stopAfterActive) throw new Error('Warteschlange angehalten');
|
};
|
||||||
|
|
||||||
if (settings.timeIntervalSec > 0) {
|
if (settings.timeIntervalSec > 0) {
|
||||||
await this._waitForInterval(task.hoster, settings.timeIntervalSec * 1000, admissionSignal);
|
await runtimePerformance.measure('slots.interval', () => this._waitForInterval(task.hoster, settings.timeIntervalSec * 1000, admissionSignal, acquireGlobal));
|
||||||
}
|
} else await acquireGlobal();
|
||||||
|
|
||||||
if (this.stopAfterActive) throw new Error('Warteschlange angehalten');
|
if (this.stopAfterActive) throw new Error('Warteschlange angehalten');
|
||||||
|
|
||||||
@@ -746,7 +765,7 @@ class UploadManager extends EventEmitter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
activeEntry.speedKbs = currentSpeedKbs;
|
activeEntry.speedKbs = currentSpeedKbs;
|
||||||
activeEntry.bytesUploaded = bytesUploaded;
|
this._recordTransferred(activeEntry, bytesUploaded, fileSize);
|
||||||
|
|
||||||
if (now - lastEmitTime < PROGRESS_EMIT_INTERVAL) return;
|
if (now - lastEmitTime < PROGRESS_EMIT_INTERVAL) return;
|
||||||
lastEmitTime = now;
|
lastEmitTime = now;
|
||||||
@@ -1080,7 +1099,7 @@ class UploadManager extends EventEmitter {
|
|||||||
lastSpeedTime = now;
|
lastSpeedTime = now;
|
||||||
}
|
}
|
||||||
activeEntry.speedKbs = currentSpeedKbs;
|
activeEntry.speedKbs = currentSpeedKbs;
|
||||||
activeEntry.bytesUploaded = bytesUploaded;
|
this._recordTransferred(activeEntry, bytesUploaded, fileSize);
|
||||||
if (now - lastEmitTime < PROGRESS_EMIT_INTERVAL) return;
|
if (now - lastEmitTime < PROGRESS_EMIT_INTERVAL) return;
|
||||||
lastEmitTime = now;
|
lastEmitTime = now;
|
||||||
const elapsed = Math.round((now - jobStart) / 1000);
|
const elapsed = Math.round((now - jobStart) / 1000);
|
||||||
@@ -1234,7 +1253,7 @@ class UploadManager extends EventEmitter {
|
|||||||
lastSpeedTime = now;
|
lastSpeedTime = now;
|
||||||
}
|
}
|
||||||
activeEntry.speedKbs = currentSpeedKbs;
|
activeEntry.speedKbs = currentSpeedKbs;
|
||||||
activeEntry.bytesUploaded = bytesUploaded;
|
this._recordTransferred(activeEntry, bytesUploaded, fileSize);
|
||||||
if (now - lastEmitTime < PROGRESS_EMIT_INTERVAL) return;
|
if (now - lastEmitTime < PROGRESS_EMIT_INTERVAL) return;
|
||||||
lastEmitTime = now;
|
lastEmitTime = now;
|
||||||
const elapsed = Math.round((now - jobStart) / 1000);
|
const elapsed = Math.round((now - jobStart) / 1000);
|
||||||
@@ -1490,18 +1509,20 @@ class UploadManager extends EventEmitter {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
_waitForInterval(hoster, intervalMs, signal) {
|
_waitForInterval(hoster, intervalMs, signal, admit = async () => {}) {
|
||||||
// Serialize interval waits per hoster so concurrent jobs queue up properly
|
// Serialize interval waits per hoster so concurrent jobs queue up properly
|
||||||
const prev = this.intervalLocks[hoster] || Promise.resolve();
|
const prev = this.intervalLocks[hoster];
|
||||||
const next = prev.then(async () => {
|
const waitAndAdmit = async () => {
|
||||||
const now = Date.now();
|
const now = Date.now();
|
||||||
const last = this.lastStartTime[hoster] || 0;
|
const last = this.lastStartTime[hoster] || 0;
|
||||||
const elapsed = now - last;
|
const elapsed = now - last;
|
||||||
if (elapsed < intervalMs) {
|
if (elapsed < intervalMs) {
|
||||||
await this._sleep(intervalMs - elapsed, signal);
|
await this._sleep(intervalMs - elapsed, signal);
|
||||||
}
|
}
|
||||||
|
await admit();
|
||||||
this.lastStartTime[hoster] = Date.now();
|
this.lastStartTime[hoster] = Date.now();
|
||||||
});
|
};
|
||||||
|
const next = prev ? prev.then(waitAndAdmit) : waitAndAdmit();
|
||||||
this.intervalLocks[hoster] = next.catch(() => {});
|
this.intervalLocks[hoster] = next.catch(() => {});
|
||||||
return next;
|
return next;
|
||||||
}
|
}
|
||||||
@@ -1521,9 +1542,7 @@ class UploadManager extends EventEmitter {
|
|||||||
}
|
}
|
||||||
const fileName = path.basename(task.file);
|
const fileName = path.basename(task.file);
|
||||||
if (!results.has(task.file)) {
|
if (!results.has(task.file)) {
|
||||||
let size = 0;
|
results.set(task.file, { name: fileName, size: 0, results: [] });
|
||||||
try { size = fs.statSync(task.file).size; } catch {}
|
|
||||||
results.set(task.file, { name: fileName, size, results: [] });
|
|
||||||
}
|
}
|
||||||
this._additionalPromises.push(this._runJob(task, results, signal));
|
this._additionalPromises.push(this._runJob(task, results, signal));
|
||||||
addResult.added++;
|
addResult.added++;
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
const fs = require('fs');
|
const { statUploadFile, readUploadFile } = require('./upload-file-io');
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
const crypto = require('crypto');
|
const crypto = require('crypto');
|
||||||
const { request } = require('undici');
|
const { request } = require('undici');
|
||||||
@@ -179,7 +179,7 @@ class VidmolyUploader {
|
|||||||
*/
|
*/
|
||||||
async upload(filePath, onProgress, signal, throttle) {
|
async upload(filePath, onProgress, signal, throttle) {
|
||||||
const fileName = path.basename(filePath);
|
const fileName = path.basename(filePath);
|
||||||
const fileSize = fs.statSync(filePath).size;
|
const fileSize = (await statUploadFile(filePath)).size;
|
||||||
const baselineCodes = await this._captureVmFileCodes();
|
const baselineCodes = await this._captureVmFileCodes();
|
||||||
|
|
||||||
const { uploadUrl, params, fileFieldName } = await this.getUploadParams();
|
const { uploadUrl, params, fileFieldName } = await this.getUploadParams();
|
||||||
@@ -213,12 +213,10 @@ class VidmolyUploader {
|
|||||||
const totalSize = preambleBuf.length + fileSize + epilogueBuf.length;
|
const totalSize = preambleBuf.length + fileSize + epilogueBuf.length;
|
||||||
|
|
||||||
let bytesRead = 0;
|
let bytesRead = 0;
|
||||||
const CHUNK_SIZE = 1024 * 1024;
|
|
||||||
|
|
||||||
async function* generate() {
|
async function* generate() {
|
||||||
yield preambleBuf;
|
yield preambleBuf;
|
||||||
const fileStream = fs.createReadStream(filePath, { highWaterMark: CHUNK_SIZE });
|
for await (const chunk of readUploadFile(filePath, signal)) {
|
||||||
for await (const chunk of fileStream) {
|
|
||||||
if (signal && signal.aborted) throw new Error('Aborted');
|
if (signal && signal.aborted) throw new Error('Aborted');
|
||||||
if (throttle) await throttle.consume(chunk.length, signal);
|
if (throttle) await throttle.consume(chunk.length, signal);
|
||||||
bytesRead += chunk.length;
|
bytesRead += chunk.length;
|
||||||
|
|||||||
+3
-5
@@ -1,4 +1,4 @@
|
|||||||
const fs = require('fs');
|
const { statUploadFile, readUploadFile } = require('./upload-file-io');
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
const crypto = require('crypto');
|
const crypto = require('crypto');
|
||||||
const { request } = require('undici');
|
const { request } = require('undici');
|
||||||
@@ -212,7 +212,7 @@ class VoeUploader {
|
|||||||
*/
|
*/
|
||||||
async upload(filePath, onProgress, signal, throttle) {
|
async upload(filePath, onProgress, signal, throttle) {
|
||||||
const fileName = path.basename(filePath);
|
const fileName = path.basename(filePath);
|
||||||
const fileSize = fs.statSync(filePath).size;
|
const fileSize = (await statUploadFile(filePath)).size;
|
||||||
const baselineCodes = await this._captureFileCodes();
|
const baselineCodes = await this._captureFileCodes();
|
||||||
|
|
||||||
// Step 1: Get CSRF token from upload page
|
// Step 1: Get CSRF token from upload page
|
||||||
@@ -243,12 +243,10 @@ class VoeUploader {
|
|||||||
const totalSize = preambleBuf.length + fileSize + epilogueBuf.length;
|
const totalSize = preambleBuf.length + fileSize + epilogueBuf.length;
|
||||||
|
|
||||||
let bytesRead = 0;
|
let bytesRead = 0;
|
||||||
const CHUNK_SIZE = 1024 * 1024;
|
|
||||||
|
|
||||||
async function* generate() {
|
async function* generate() {
|
||||||
yield preambleBuf;
|
yield preambleBuf;
|
||||||
const fileStream = fs.createReadStream(filePath, { highWaterMark: CHUNK_SIZE });
|
for await (const chunk of readUploadFile(filePath, signal)) {
|
||||||
for await (const chunk of fileStream) {
|
|
||||||
if (signal && signal.aborted) throw new Error('Aborted');
|
if (signal && signal.aborted) throw new Error('Aborted');
|
||||||
if (throttle) await throttle.consume(chunk.length, signal);
|
if (throttle) await throttle.consume(chunk.length, signal);
|
||||||
bytesRead += chunk.length;
|
bytesRead += chunk.length;
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ const { createDoodstreamOtpCoordinator, selectUploadAuth } = require('./lib/acco
|
|||||||
const { createAccountCooldownController, createAccountPicker, selectFallbackAccount } = require('./lib/account-rotation');
|
const { createAccountCooldownController, createAccountPicker, selectFallbackAccount } = require('./lib/account-rotation');
|
||||||
const ClouddropUploader = require('./lib/clouddrop-upload');
|
const ClouddropUploader = require('./lib/clouddrop-upload');
|
||||||
const { CloudLogSync } = require('./lib/cloud-log-sync');
|
const { CloudLogSync } = require('./lib/cloud-log-sync');
|
||||||
const { checkForUpdate, prepareUpdate, launchPreparedUpdate, abortUpdate, createUpdateAnnouncementState } = require('./lib/updater');
|
const { checkForUpdate, prepareUpdate, verifyPreparedUpdate, launchVerifiedUpdate, launchPreparedUpdate, abortUpdate, createUpdateAnnouncementState } = require('./lib/updater');
|
||||||
const backupCrypto = require('./lib/backup-crypto');
|
const backupCrypto = require('./lib/backup-crypto');
|
||||||
const { downloadOnlineBackup, downloadRecoveryPublicKey, normalizeOnlineBackupRetention } = require('./lib/online-backup');
|
const { downloadOnlineBackup, downloadRecoveryPublicKey, normalizeOnlineBackupRetention } = require('./lib/online-backup');
|
||||||
const { createOnlineBackupKeyring } = require('./lib/online-backup-keyring');
|
const { createOnlineBackupKeyring } = require('./lib/online-backup-keyring');
|
||||||
@@ -47,6 +47,8 @@ const { normalizeAutomationSettings, automationCompletionKey, createAutomationCo
|
|||||||
const { McpService } = require('./lib/mcp-service');
|
const { McpService } = require('./lib/mcp-service');
|
||||||
const { createMcpApp } = require('./lib/mcp-app');
|
const { createMcpApp } = require('./lib/mcp-app');
|
||||||
const { McpAccessError } = require('./lib/mcp-access');
|
const { McpAccessError } = require('./lib/mcp-access');
|
||||||
|
const { runtimePerformance } = require('./lib/performance-monitor');
|
||||||
|
const { McpUpdate } = require('./lib/mcp-update');
|
||||||
const mcpLocalHandlers = new Map();
|
const mcpLocalHandlers = new Map();
|
||||||
const mcpRawHandle = ipcMain.handle.bind(ipcMain);
|
const mcpRawHandle = ipcMain.handle.bind(ipcMain);
|
||||||
ipcMain.handle = (channel, handler) => {
|
ipcMain.handle = (channel, handler) => {
|
||||||
@@ -98,12 +100,15 @@ if (_perfOn) {
|
|||||||
try { p = fn.call(this, evt, ...args); }
|
try { p = fn.call(this, evt, ...args); }
|
||||||
catch (e) { _ipcLog(`ipc ${channel} sync-throw wall=${(performance.now() - t0).toFixed(0)}ms`); throw e; }
|
catch (e) { _ipcLog(`ipc ${channel} sync-throw wall=${(performance.now() - t0).toFixed(0)}ms`); throw e; }
|
||||||
const sync = performance.now() - t0;
|
const sync = performance.now() - t0;
|
||||||
|
runtimePerformance.record(`ipc-sync.${channel.replace(/[^a-z0-9_.:-]/gi, '').toLowerCase()}`, sync);
|
||||||
if (p && typeof p.then === 'function') {
|
if (p && typeof p.then === 'function') {
|
||||||
return Promise.resolve(p).finally(() => {
|
return Promise.resolve(p).finally(() => {
|
||||||
const total = performance.now() - t0;
|
const total = performance.now() - t0;
|
||||||
|
runtimePerformance.record(`ipc.${channel.replace(/[^a-z0-9_.:-]/gi, '').toLowerCase()}`, total);
|
||||||
if (total >= IPC_SLOW_MS) _ipcLog(`ipc ${channel} wall=${total.toFixed(0)}ms sync=${sync.toFixed(0)}ms`);
|
if (total >= IPC_SLOW_MS) _ipcLog(`ipc ${channel} wall=${total.toFixed(0)}ms sync=${sync.toFixed(0)}ms`);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
runtimePerformance.record(`ipc.${channel.replace(/[^a-z0-9_.:-]/gi, '').toLowerCase()}`, sync);
|
||||||
if (sync >= IPC_SLOW_MS) _ipcLog(`ipc ${channel} wall=${sync.toFixed(0)}ms sync`);
|
if (sync >= IPC_SLOW_MS) _ipcLog(`ipc ${channel} wall=${sync.toFixed(0)}ms sync`);
|
||||||
return p;
|
return p;
|
||||||
});
|
});
|
||||||
@@ -135,6 +140,8 @@ let preparedUpdate = null;
|
|||||||
let updatePreparationPromise = null;
|
let updatePreparationPromise = null;
|
||||||
let updateQuitPending = false;
|
let updateQuitPending = false;
|
||||||
let preparedUpdateLaunchStarted = false;
|
let preparedUpdateLaunchStarted = false;
|
||||||
|
let mcpUpdateHandoff = null;
|
||||||
|
let mcpUpdateResuming = false;
|
||||||
let updateCheckInterval = null;
|
let updateCheckInterval = null;
|
||||||
const updateAnnouncementState = createUpdateAnnouncementState();
|
const updateAnnouncementState = createUpdateAnnouncementState();
|
||||||
let _lastImportPath = null;
|
let _lastImportPath = null;
|
||||||
@@ -142,6 +149,54 @@ let dropTargetWindow = null;
|
|||||||
let tray = null;
|
let tray = null;
|
||||||
let _cachedLogSettings = null;
|
let _cachedLogSettings = null;
|
||||||
const configStore = new ConfigStore(app);
|
const configStore = new ConfigStore(app);
|
||||||
|
const mcpUpdate = new McpUpdate({
|
||||||
|
directory: app.getPath('userData'), version: () => app.getVersion(),
|
||||||
|
canUpdate: () => mcpService?.capabilities().includes('updates') === true,
|
||||||
|
supported: async () => app.isPackaged && process.platform === 'win32' && !process.env.PORTABLE_EXECUTABLE_FILE
|
||||||
|
&& await fs.promises.stat(path.join(path.dirname(process.execPath), 'Uninstall Multi-Hoster-Upload.exe')).then(stat => stat.isFile(), () => false),
|
||||||
|
check: () => checkForUpdate({ forceRefresh: true }),
|
||||||
|
prepare: (checkResult, progress) => prepareUpdate(progress, { checkResult }),
|
||||||
|
verify: verifyPreparedUpdate,
|
||||||
|
park: async () => {
|
||||||
|
const snapshot = await internalUpdateRenderer('update-park');
|
||||||
|
const resume = { ...snapshot, monitorRunning: folderMonitor.running };
|
||||||
|
return resume;
|
||||||
|
},
|
||||||
|
drain: async guard => {
|
||||||
|
uploadManager?.finishAfterActive();
|
||||||
|
await stopFolderMonitor();
|
||||||
|
const deadline = Date.now() + 2 * 60 * 60 * 1000;
|
||||||
|
for (;;) {
|
||||||
|
if (!uploadManager && !activeUploadProducerTrackers.size) break;
|
||||||
|
guard();
|
||||||
|
if (Date.now() > deadline) throw new McpAccessError('UPDATE_DRAIN_TIMEOUT');
|
||||||
|
await new Promise(resolve => setTimeout(resolve, 250));
|
||||||
|
}
|
||||||
|
await waitForConfigStoreWrites();
|
||||||
|
},
|
||||||
|
handoff: async prepared => {
|
||||||
|
if (!closeHandshakeReady || updatePreparationPromise || preparedUpdate) throw new McpAccessError('UPDATE_BUSY');
|
||||||
|
await new Promise((resolve, reject) => {
|
||||||
|
const timer = setTimeout(() => { rejectPendingUpdate(new Error('Update close timeout')); }, 15000);
|
||||||
|
mcpUpdateHandoff = { resolve: () => { clearTimeout(timer); resolve(); }, reject: error => { clearTimeout(timer); reject(error); } };
|
||||||
|
preparedUpdate = prepared;
|
||||||
|
updateQuitPending = true;
|
||||||
|
if (!requestClosePreparation()) rejectPendingUpdate(new Error('Update close unavailable'));
|
||||||
|
});
|
||||||
|
},
|
||||||
|
restore: async snapshot => {
|
||||||
|
mcpUpdateResuming = true;
|
||||||
|
try {
|
||||||
|
if (snapshot?.wasUploading && !configStore.load().globalSettings?.folderMonitor?.paused) await internalUpdateRenderer('update-resume', snapshot);
|
||||||
|
const settings = configStore.load().globalSettings?.folderMonitor;
|
||||||
|
if (snapshot?.monitorRunning && settings?.enabled && !settings.paused) await startFolderMonitor(settings);
|
||||||
|
} finally { mcpUpdateResuming = false; }
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
function internalUpdateRenderer(action, args = {}) {
|
||||||
|
return mcpRendererAction(action, args, { signal: new AbortController().signal, deadline: Date.now() + 120000, internalUpdate: true });
|
||||||
|
}
|
||||||
const cloudLogWrites = new Set();
|
const cloudLogWrites = new Set();
|
||||||
let cloudLogSettingsCache = null;
|
let cloudLogSettingsCache = null;
|
||||||
const cloudLogSync = new CloudLogSync({
|
const cloudLogSync = new CloudLogSync({
|
||||||
@@ -202,6 +257,7 @@ const activeUploadProducerTrackers = new Set();
|
|||||||
const settingsImportGate = createSettingsImportGate(() => !!(uploadManager && uploadManager.running));
|
const settingsImportGate = createSettingsImportGate(() => !!(uploadManager && uploadManager.running));
|
||||||
|
|
||||||
function assertConfigWriteAllowed() {
|
function assertConfigWriteAllowed() {
|
||||||
|
if (mcpUpdate.blocksTransfers() && !mcpUpdateResuming) throw new Error('MCP-Update wird vorbereitet');
|
||||||
if (!settingsImportGate.canStartUpload()) throw new Error('Einstellungen werden gerade importiert');
|
if (!settingsImportGate.canStartUpload()) throw new Error('Einstellungen werden gerade importiert');
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -314,6 +370,7 @@ function rejectPendingUpdate(error) {
|
|||||||
preparedUpdate = null;
|
preparedUpdate = null;
|
||||||
updateQuitPending = false;
|
updateQuitPending = false;
|
||||||
preparedUpdateLaunchStarted = false;
|
preparedUpdateLaunchStarted = false;
|
||||||
|
if (mcpUpdateHandoff) { const pending = mcpUpdateHandoff; mcpUpdateHandoff = null; pending.reject(error); }
|
||||||
safeSend('app:update-progress', {
|
safeSend('app:update-progress', {
|
||||||
stage: 'error',
|
stage: 'error',
|
||||||
error: error && error.message ? error.message : String(error || 'Einstellungen konnten vor dem Update nicht gespeichert werden')
|
error: error && error.message ? error.message : String(error || 'Einstellungen konnten vor dem Update nicht gespeichert werden')
|
||||||
@@ -1757,6 +1814,7 @@ function createWindow() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
mainWindow.webContents.on('render-process-gone', async (_event, details) => {
|
mainWindow.webContents.on('render-process-gone', async (_event, details) => {
|
||||||
|
runtimePerformance.event('renderer-crashed', { reason: String(details.reason || '').slice(0, 40) });
|
||||||
startupDiagnostics.write('renderer-gone', { reason: details.reason, exitCode: details.exitCode, initialized: closeHandshakeReady });
|
startupDiagnostics.write('renderer-gone', { reason: details.reason, exitCode: details.exitCode, initialized: closeHandshakeReady });
|
||||||
recordStartupIncident('renderer-crashed');
|
recordStartupIncident('renderer-crashed');
|
||||||
folderMonitorRendererReadyGeneration = null;
|
folderMonitorRendererReadyGeneration = null;
|
||||||
@@ -1794,6 +1852,7 @@ function createWindow() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
mainWindow.webContents.on('unresponsive', () => {
|
mainWindow.webContents.on('unresponsive', () => {
|
||||||
|
runtimePerformance.event('renderer-unresponsive');
|
||||||
startupDiagnostics.write('renderer-unresponsive', { initialized: closeHandshakeReady });
|
startupDiagnostics.write('renderer-unresponsive', { initialized: closeHandshakeReady });
|
||||||
_writeCrashLog('RENDERER UNRESPONSIVE', new Error('webContents unresponsive'));
|
_writeCrashLog('RENDERER UNRESPONSIVE', new Error('webContents unresponsive'));
|
||||||
debugLog('RENDERER UNRESPONSIVE');
|
debugLog('RENDERER UNRESPONSIVE');
|
||||||
@@ -1875,6 +1934,7 @@ async function runAutomaticUpdateCheck(forceRefresh) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
app.whenReady().then(async () => {
|
app.whenReady().then(async () => {
|
||||||
|
await mcpUpdate.load().catch(() => logError('MCP update state unavailable'));
|
||||||
if (!_hasSingleInstanceLock) return;
|
if (!_hasSingleInstanceLock) return;
|
||||||
startupDiagnostics.write('application-ready', { hardwareAcceleration: app.isHardwareAccelerationEnabled(), gpuFeatures: app.getGPUFeatureStatus() });
|
startupDiagnostics.write('application-ready', { hardwareAcceleration: app.isHardwareAccelerationEnabled(), gpuFeatures: app.getGPUFeatureStatus() });
|
||||||
void app.getGPUInfo('basic').then(info => {
|
void app.getGPUInfo('basic').then(info => {
|
||||||
@@ -1920,6 +1980,8 @@ app.whenReady().then(async () => {
|
|||||||
}
|
}
|
||||||
createWindow();
|
createWindow();
|
||||||
createTray();
|
createTray();
|
||||||
|
runtimePerformance.start({ version: app.getVersion(), getTransfers: () => uploadManager?.getDiagnostics() || null,
|
||||||
|
pingRenderer: id => closeHandshakeReady && safeSend('performance:ping', id) });
|
||||||
startupDiagnostics.write('window-load-dispatched');
|
startupDiagnostics.write('window-load-dispatched');
|
||||||
void cloudLogSync.start();
|
void cloudLogSync.start();
|
||||||
void startMcpService();
|
void startMcpService();
|
||||||
@@ -1932,7 +1994,7 @@ app.whenReady().then(async () => {
|
|||||||
try {
|
try {
|
||||||
const launchConfig = configStore.load();
|
const launchConfig = configStore.load();
|
||||||
const fm = launchConfig.globalSettings && launchConfig.globalSettings.folderMonitor;
|
const fm = launchConfig.globalSettings && launchConfig.globalSettings.folderMonitor;
|
||||||
if (fm && fm.enabled && fm.folderPath) {
|
if (fm && fm.enabled && fm.folderPath && !mcpUpdate.blocksTransfers()) {
|
||||||
await startFolderMonitor(fm, { deferStartupReconcile: true });
|
await startFolderMonitor(fm, { deferStartupReconcile: true });
|
||||||
}
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
@@ -2019,7 +2081,7 @@ ipcMain.handle('debug-log', (_event, msg) => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
ipcMain.handle('get-config', () => {
|
ipcMain.handle('get-config', () => {
|
||||||
return configStore.load();
|
return { ...configStore.load(), mcpUpdatePending: mcpUpdate.blocksTransfers() };
|
||||||
});
|
});
|
||||||
|
|
||||||
ipcMain.handle('cloud-log:status', event => {
|
ipcMain.handle('cloud-log:status', event => {
|
||||||
@@ -2392,6 +2454,7 @@ async function rejectPreparedUploadStart(manager, producerTracker, error, clearR
|
|||||||
}
|
}
|
||||||
|
|
||||||
function preparedUploadStartGate(manager) {
|
function preparedUploadStartGate(manager) {
|
||||||
|
if (mcpUpdate.blocksTransfers() && !mcpUpdateResuming) return 'MCP-Update wird vorbereitet';
|
||||||
if (uploadManager !== manager) return 'Upload-Start wurde verworfen';
|
if (uploadManager !== manager) return 'Upload-Start wurde verworfen';
|
||||||
if (closeFlushRequested) return 'Die Anwendung wird gerade beendet';
|
if (closeFlushRequested) return 'Die Anwendung wird gerade beendet';
|
||||||
if (configStore.load().globalSettings?.folderMonitor?.paused === true) return 'Automatik ist pausiert';
|
if (configStore.load().globalSettings?.folderMonitor?.paused === true) return 'Automatik ist pausiert';
|
||||||
@@ -2468,6 +2531,7 @@ function startPreparedUploadBatch({ manager, tasks, producerTracker, recovery, i
|
|||||||
}
|
}
|
||||||
|
|
||||||
ipcMain.handle('start-upload', async (_event, payload) => {
|
ipcMain.handle('start-upload', async (_event, payload) => {
|
||||||
|
if (mcpUpdate.blocksTransfers() && !mcpUpdateResuming) return { error: 'MCP-Update wird vorbereitet' };
|
||||||
if (configStore.load().globalSettings?.folderMonitor?.paused === true) {
|
if (configStore.load().globalSettings?.folderMonitor?.paused === true) {
|
||||||
return { error: 'Automatik ist pausiert' };
|
return { error: 'Automatik ist pausiert' };
|
||||||
}
|
}
|
||||||
@@ -2879,6 +2943,7 @@ ipcMain.handle('cancel-selected-jobs', (_event, jobIds) => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
ipcMain.handle('add-jobs-to-batch', async (_event, payload) => {
|
ipcMain.handle('add-jobs-to-batch', async (_event, payload) => {
|
||||||
|
if (mcpUpdate.blocksTransfers() && !mcpUpdateResuming) return { error: 'MCP-Update wird vorbereitet' };
|
||||||
if (configStore.load().globalSettings?.folderMonitor?.paused === true) {
|
if (configStore.load().globalSettings?.folderMonitor?.paused === true) {
|
||||||
return { error: 'Automatik ist pausiert' };
|
return { error: 'Automatik ist pausiert' };
|
||||||
}
|
}
|
||||||
@@ -3469,6 +3534,7 @@ ipcMain.handle('app:check-updates', async (_event, options) => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
ipcMain.handle('app:install-update', async event => {
|
ipcMain.handle('app:install-update', async event => {
|
||||||
|
if (mcpUpdate.blocksTransfers()) return { started: false, error: 'MCP-Update wird vorbereitet' };
|
||||||
if (updatePreparationPromise || preparedUpdate || updateQuitPending) {
|
if (updatePreparationPromise || preparedUpdate || updateQuitPending) {
|
||||||
return { started: false, error: 'Ein Update wird bereits vorbereitet' };
|
return { started: false, error: 'Ein Update wird bereits vorbereitet' };
|
||||||
}
|
}
|
||||||
@@ -3528,9 +3594,14 @@ ipcMain.on('app:startup-phase', (event, phase) => {
|
|||||||
if (phase === 'initialization-failed') recordStartupIncident('initialization-failed');
|
if (phase === 'initialization-failed') recordStartupIncident('initialization-failed');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
ipcMain.on('performance:pong', (event, id) => {
|
||||||
|
if (mainWindow && !mainWindow.isDestroyed() && event.sender === mainWindow.webContents && Number.isSafeInteger(id)) runtimePerformance.rendererReply(id);
|
||||||
|
});
|
||||||
|
|
||||||
ipcMain.on('app:close-handshake-ready', (event) => {
|
ipcMain.on('app:close-handshake-ready', (event) => {
|
||||||
if (mainWindow && !mainWindow.isDestroyed() && event.sender === mainWindow.webContents) {
|
if (mainWindow && !mainWindow.isDestroyed() && event.sender === mainWindow.webContents) {
|
||||||
closeHandshakeReady = true;
|
closeHandshakeReady = true;
|
||||||
|
void mcpUpdate.recover({ rendererReady: true, connected: mcpService?.connection === 'online' });
|
||||||
startupDiagnostics.write('application-initialized', { generation: folderMonitorRendererGeneration });
|
startupDiagnostics.write('application-initialized', { generation: folderMonitorRendererGeneration });
|
||||||
void checkForUpdate().then(announceAvailableUpdate).catch((error) => {
|
void checkForUpdate().then(announceAvailableUpdate).catch((error) => {
|
||||||
logError('update-check failed', error);
|
logError('update-check failed', error);
|
||||||
@@ -3574,6 +3645,13 @@ ipcMain.handle('app:finish-close', async (event, payload = true) => {
|
|||||||
await waitForCloseOperation(configStore.savePendingQueue(payload.pendingQueue, { allowDuringQuiesce: true }), 1000);
|
await waitForCloseOperation(configStore.savePendingQueue(payload.pendingQueue, { allowDuringQuiesce: true }), 1000);
|
||||||
}
|
}
|
||||||
if (!isClosePreparationActive(attempt)) return false;
|
if (!isClosePreparationActive(attempt)) return false;
|
||||||
|
if (mcpUpdateHandoff) {
|
||||||
|
await mcpUpdate.markLaunching();
|
||||||
|
await launchVerifiedUpdate(preparedUpdate, path.dirname(process.execPath));
|
||||||
|
preparedUpdateLaunchStarted = true;
|
||||||
|
mcpUpdateHandoff.resolve();
|
||||||
|
mcpUpdateHandoff = null;
|
||||||
|
}
|
||||||
closeFlushApproved = true;
|
closeFlushApproved = true;
|
||||||
approved = true;
|
approved = true;
|
||||||
setImmediate(() => {
|
setImmediate(() => {
|
||||||
@@ -3581,6 +3659,7 @@ ipcMain.handle('app:finish-close', async (event, payload = true) => {
|
|||||||
});
|
});
|
||||||
return true;
|
return true;
|
||||||
} catch {
|
} catch {
|
||||||
|
if (mcpUpdateHandoff) await mcpUpdate.launchFailed().catch(() => {});
|
||||||
restoreClosePreparation(attempt);
|
restoreClosePreparation(attempt);
|
||||||
return false;
|
return false;
|
||||||
} finally {
|
} finally {
|
||||||
@@ -4049,6 +4128,8 @@ async function startMcpService() {
|
|||||||
return mcpLocalHandlers.get(channel)(event, ...args);
|
return mcpLocalHandlers.get(channel)(event, ...args);
|
||||||
};
|
};
|
||||||
const handlers = createMcpApp({ loadConfig: () => configStore.load(), invoke, invokeGuarded, renderer: mcpRendererAction, collectors: createAppCollectors(),
|
const handlers = createMcpApp({ loadConfig: () => configStore.load(), invoke, invokeGuarded, renderer: mcpRendererAction, collectors: createAppCollectors(),
|
||||||
|
updates: mcpUpdate,
|
||||||
|
getPerformance: () => runtimePerformance.snapshot(),
|
||||||
getGrants: () => mcpService?.store.value.grants || [], trashFile: file => require('electron').shell.trashItem(file), canWrite: assertConfigWriteAllowed,
|
getGrants: () => mcpService?.store.value.grants || [], trashFile: file => require('electron').shell.trashItem(file), canWrite: assertConfigWriteAllowed,
|
||||||
getCapabilities: () => mcpService?.capabilities() || [],
|
getCapabilities: () => mcpService?.capabilities() || [],
|
||||||
getProtectedPaths: () => [app.getPath('userData'), configStore.filePath, configStore.historyPath, configStore.automationCompletionPath],
|
getProtectedPaths: () => [app.getPath('userData'), configStore.filePath, configStore.historyPath, configStore.automationCompletionPath],
|
||||||
@@ -4065,7 +4146,10 @@ async function startMcpService() {
|
|||||||
] });
|
] });
|
||||||
mcpService = new McpService({ directory: app.getPath('userData'), encrypt: secretStore.encryptField, decrypt: secretStore.decryptField,
|
mcpService = new McpService({ directory: app.getPath('userData'), encrypt: secretStore.encryptField, decrypt: secretStore.decryptField,
|
||||||
handlers, version: app.getVersion(), loadConfig: () => configStore.load(), dialog, getWindow: () => mainWindow,
|
handlers, version: app.getVersion(), loadConfig: () => configStore.load(), dialog, getWindow: () => mainWindow,
|
||||||
onStatus: status => safeSend('mcp:status', status),
|
onStatus: status => {
|
||||||
|
safeSend('mcp:status', status);
|
||||||
|
void mcpUpdate.recover({ rendererReady: closeHandshakeReady, connected: status.connection === 'online' });
|
||||||
|
},
|
||||||
requiresConfirmation: name => {
|
requiresConfirmation: name => {
|
||||||
if (!['mhu_queue_start', 'mhu_queue_retry', 'mhu_queue_resume', 'mhu_automation_start', 'mhu_automation_reconcile'].includes(name)) return false;
|
if (!['mhu_queue_start', 'mhu_queue_retry', 'mhu_queue_resume', 'mhu_automation_start', 'mhu_automation_reconcile'].includes(name)) return false;
|
||||||
const settings = configStore.load().globalSettings;
|
const settings = configStore.load().globalSettings;
|
||||||
@@ -4079,7 +4163,7 @@ async function startMcpService() {
|
|||||||
ipcMain.handle('mcp:status', event => isTrustedOnlineBackupIpcEvent(event) ? mcpService?.state() || { available: false, connection: 'starting' } : null);
|
ipcMain.handle('mcp:status', event => isTrustedOnlineBackupIpcEvent(event) ? mcpService?.state() || { available: false, connection: 'starting' } : null);
|
||||||
ipcMain.handle('mcp:check', (event, id) => {
|
ipcMain.handle('mcp:check', (event, id) => {
|
||||||
const pending = mcpRendererRequests.get(id);
|
const pending = mcpRendererRequests.get(id);
|
||||||
return !!(isTrustedOnlineBackupIpcEvent(event) && closeHandshakeReady && pending && !pending.context.signal?.aborted && Date.now() < pending.context.deadline && mcpService?.active);
|
return !!(isTrustedOnlineBackupIpcEvent(event) && closeHandshakeReady && pending && !pending.context.signal?.aborted && Date.now() < pending.context.deadline && (pending.context.internalUpdate === true || mcpService?.active));
|
||||||
});
|
});
|
||||||
ipcMain.on('mcp:reply', (event, payload) => {
|
ipcMain.on('mcp:reply', (event, payload) => {
|
||||||
if (!isTrustedOnlineBackupIpcEvent(event) || typeof payload?.id !== 'string') return;
|
if (!isTrustedOnlineBackupIpcEvent(event) || typeof payload?.id !== 'string') return;
|
||||||
@@ -4089,7 +4173,7 @@ ipcMain.on('mcp:reply', (event, payload) => {
|
|||||||
});
|
});
|
||||||
ipcMain.handle('mcp:configure', async (event, args) => {
|
ipcMain.handle('mcp:configure', async (event, args) => {
|
||||||
if (!isTrustedOnlineBackupIpcEvent(event) || !mcpService) throw new Error('MCP_ACCESS_DENIED');
|
if (!isTrustedOnlineBackupIpcEvent(event) || !mcpService) throw new Error('MCP_ACCESS_DENIED');
|
||||||
if (args?.enabled && (args.capabilities?.includes('secrets') || !mcpService.active)) {
|
if (args?.enabled && (args.capabilities?.includes('secrets') || (args.capabilities?.includes('updates') && !mcpService.capabilities().includes('updates')) || !mcpService.active)) {
|
||||||
const result = await dialog.showMessageBox(mainWindow, { type: 'warning', title: 'MCP-Zugriff / MCP access', message: 'MCP-Zugriff mit diesen Berechtigungen aktivieren? / Enable MCP with these capabilities?',
|
const result = await dialog.showMessageBox(mainWindow, { type: 'warning', title: 'MCP-Zugriff / MCP access', message: 'MCP-Zugriff mit diesen Berechtigungen aktivieren? / Enable MCP with these capabilities?',
|
||||||
detail: String(args.capabilities?.join(', ') || '').slice(0, 100), buttons: ['Abbrechen / Cancel', 'Aktivieren / Enable'], defaultId: 0, cancelId: 0, noLink: true });
|
detail: String(args.capabilities?.join(', ') || '').slice(0, 100), buttons: ['Abbrechen / Cancel', 'Aktivieren / Enable'], defaultId: 0, cancelId: 0, noLink: true });
|
||||||
if (result.response !== 1) return mcpService.state();
|
if (result.response !== 1) return mcpService.state();
|
||||||
@@ -4238,6 +4322,7 @@ ipcMain.handle('cancel-shutdown', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
function handleShutdownAfterFinish() {
|
function handleShutdownAfterFinish() {
|
||||||
|
if (mcpUpdate.blocksTransfers()) return;
|
||||||
if (shutdownMode === 'nothing') return;
|
if (shutdownMode === 'nothing') return;
|
||||||
|
|
||||||
const { exec } = require('child_process');
|
const { exec } = require('child_process');
|
||||||
|
|||||||
Generated
+2
-2
@@ -1,12 +1,12 @@
|
|||||||
{
|
{
|
||||||
"name": "multi-hoster-uploader",
|
"name": "multi-hoster-uploader",
|
||||||
"version": "2.1.64",
|
"version": "2.1.65",
|
||||||
"lockfileVersion": 3,
|
"lockfileVersion": 3,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"packages": {
|
"packages": {
|
||||||
"": {
|
"": {
|
||||||
"name": "multi-hoster-uploader",
|
"name": "multi-hoster-uploader",
|
||||||
"version": "2.1.64",
|
"version": "2.1.65",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"chokidar": "^4.0.3",
|
"chokidar": "^4.0.3",
|
||||||
"undici": "7.29.1",
|
"undici": "7.29.1",
|
||||||
|
|||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "multi-hoster-uploader",
|
"name": "multi-hoster-uploader",
|
||||||
"version": "2.1.64",
|
"version": "2.1.65",
|
||||||
"description": "Upload files to doodstream, voe, vidmoly, byse simultaneously",
|
"description": "Upload files to doodstream, voe, vidmoly, byse simultaneously",
|
||||||
"main": "main.js",
|
"main": "main.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
|||||||
@@ -1,4 +1,7 @@
|
|||||||
const { contextBridge, ipcRenderer, webUtils } = require('electron');
|
const { contextBridge, ipcRenderer, webUtils } = require('electron');
|
||||||
|
ipcRenderer.on('performance:ping', (_event, id) => {
|
||||||
|
if (Number.isSafeInteger(id)) ipcRenderer.send('performance:pong', id);
|
||||||
|
});
|
||||||
|
|
||||||
const reportStartupPhase = phase => ipcRenderer.send('app:startup-phase', phase);
|
const reportStartupPhase = phase => ipcRenderer.send('app:startup-phase', phase);
|
||||||
reportStartupPhase('preload-started');
|
reportStartupPhase('preload-started');
|
||||||
|
|||||||
+2
-1
@@ -2327,7 +2327,7 @@ function normalizeRestoredJobStatus(status) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function restoreQueueStateFromConfig() {
|
function restoreQueueStateFromConfig() {
|
||||||
if (config?.globalSettings?.resumeQueueOnLaunch === false) return;
|
if (config?.globalSettings?.resumeQueueOnLaunch === false && !config?.mcpUpdatePending) return;
|
||||||
const pending = config?.globalSettings?.pendingQueue;
|
const pending = config?.globalSettings?.pendingQueue;
|
||||||
if (!pending || typeof pending !== 'object') return;
|
if (!pending || typeof pending !== 'object') return;
|
||||||
|
|
||||||
@@ -2941,6 +2941,7 @@ async function startRestoredQueueAfterChecks(jobIds) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function scheduleRestoredQueueAutoStart() {
|
function scheduleRestoredQueueAutoStart() {
|
||||||
|
if (config?.mcpUpdatePending) return;
|
||||||
if (!_startupQueueEvidenceAvailable || config?.globalSettings?.autoStartRestoredQueue !== true || !window.AutoResume) return;
|
if (!_startupQueueEvidenceAvailable || config?.globalSettings?.autoStartRestoredQueue !== true || !window.AutoResume) return;
|
||||||
const jobs = window.AutoResume.getAutoResumeJobs(queueJobs);
|
const jobs = window.AutoResume.getAutoResumeJobs(queueJobs);
|
||||||
if (!jobs.length) return;
|
if (!jobs.length) return;
|
||||||
|
|||||||
@@ -5,6 +5,12 @@
|
|||||||
})(typeof window !== 'undefined' ? window : globalThis, function () {
|
})(typeof window !== 'undefined' ? window : globalThis, function () {
|
||||||
const pairs = [
|
const pairs = [
|
||||||
['MCP-Fernzugriff', 'MCP remote access'],
|
['MCP-Fernzugriff', 'MCP remote access'],
|
||||||
|
['Offizielle App-Updates ohne erneute Bestätigung erlauben', 'Allow official app updates without another confirmation'],
|
||||||
|
['Standardmäßig aus. Gilt nur für geprüfte Installer einer exakt angeforderten Version. Laufende Uploads werden abgeschlossen und die Warteschlange nach dem Neustart wieder aufgenommen. Portable-Versionen werden nicht unterstützt.', 'Disabled by default. Limited to verified installers of the exact requested version. Running uploads finish and the queue resumes after restart. Portable versions are not supported.'],
|
||||||
|
['MCP-Update wird vorbereitet', 'MCP update is being prepared'],
|
||||||
|
['Update-Prüfsumme fehlt', 'Update checksum is missing'],
|
||||||
|
['Update-Datei wurde verändert', 'Update file has changed'],
|
||||||
|
['Update-Datei wurde ausgetauscht', 'Update file was replaced'],
|
||||||
['App-Funktionen über einen freigegebenen MCP-Client steuern.', 'Control app functions through an authorized MCP client.'],
|
['App-Funktionen über einen freigegebenen MCP-Client steuern.', 'Control app functions through an authorized MCP client.'],
|
||||||
['Strukturierter Fernzugriff über HTTPS. Nur bei laufender Anwendung; keine Portfreigabe erforderlich. Berechtigungen werden ausschließlich hier vergeben.', 'Structured remote access over HTTPS. Available while the app is running; no inbound port required. Permissions can only be granted here.'],
|
['Strukturierter Fernzugriff über HTTPS. Nur bei laufender Anwendung; keine Portfreigabe erforderlich. Berechtigungen werden ausschließlich hier vergeben.', 'Structured remote access over HTTPS. Available while the app is running; no inbound port required. Permissions can only be granted here.'],
|
||||||
['Installationsname', 'Installation name'],
|
['Installationsname', 'Installation name'],
|
||||||
|
|||||||
@@ -12,3 +12,5 @@
|
|||||||
.mcp-state.connected { color: #a2edc1; background: #193829; border-color: #46735b; }
|
.mcp-state.connected { color: #a2edc1; background: #193829; border-color: #46735b; }
|
||||||
.mcp-grant { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; padding: 12px 0; border-bottom: 1px solid var(--border, #424242); }
|
.mcp-grant { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; padding: 12px 0; border-bottom: 1px solid var(--border, #424242); }
|
||||||
.mcp-grant > span { flex: 1 1 220px; overflow-wrap: anywhere; }
|
.mcp-grant > span { flex: 1 1 220px; overflow-wrap: anywhere; }
|
||||||
|
.mcp-update-permission { display: flex; align-items: flex-start; gap: 8px; margin-top: 20px; font-size: 13px; line-height: 1.6; }
|
||||||
|
.mcp-update-permission input { flex: 0 0 auto; margin-top: 4px; }
|
||||||
+28
-3
@@ -21,6 +21,25 @@
|
|||||||
const handlers = {
|
const handlers = {
|
||||||
state: async () => ({ source: 'live', stale: false, uploading, queueCount: queueJobs.length, selectedFileCount: selectedFiles.length, selectedHosters: getSelectedHosters(), counts: queueJobs.reduce((out, job) => { out[job.status] = (out[job.status] || 0) + 1; return out; }, {}) }),
|
state: async () => ({ source: 'live', stale: false, uploading, queueCount: queueJobs.length, selectedFileCount: selectedFiles.length, selectedHosters: getSelectedHosters(), counts: queueJobs.reduce((out, job) => { out[job.status] = (out[job.status] || 0) + 1; return out; }, {}) }),
|
||||||
refresh,
|
refresh,
|
||||||
|
'update-park': async () => {
|
||||||
|
cancelStartupQueueAutoStart();
|
||||||
|
_cancelAutoRetry(true);
|
||||||
|
const jobIds = queueJobs.filter(job => !['done', 'error', 'skipped', 'aborted'].includes(job.status)).map(job => job.id);
|
||||||
|
if (jobIds.length > 50000) throw new Error('UPDATE_QUEUE_TOO_LARGE');
|
||||||
|
await persistQueueStateNow();
|
||||||
|
return { wasUploading: uploading, jobIds };
|
||||||
|
},
|
||||||
|
'update-resume': async (args, guard) => {
|
||||||
|
await guard();
|
||||||
|
const ids = new Set(args.jobIds || []);
|
||||||
|
const jobs = queueJobs.filter(job => ids.has(job.id) && !['done', 'error', 'skipped'].includes(job.status));
|
||||||
|
for (const job of jobs) if (job.status === 'aborted') Object.assign(job, { status: 'preview', error: null });
|
||||||
|
redraw();
|
||||||
|
if (!jobs.length) return { started: false, reason: 'NO_ELIGIBLE_JOBS' };
|
||||||
|
const result = await startSelectedUpload(jobs, { guard });
|
||||||
|
if (result?.ok !== true) throw new Error('UPDATE_RESUME_FAILED');
|
||||||
|
return { resumed: true };
|
||||||
|
},
|
||||||
'account-results': async args => { for (const row of args.results) { if (findAccountById(row.accountId)) accountStatuses[row.accountId] = { status: row.status, message: row.message, storage: row.storage, checkedAt: row.checkedAt || new Date().toISOString() }; } renderAccounts(); return { updated: args.results.length }; },
|
'account-results': async args => { for (const row of args.results) { if (findAccountById(row.accountId)) accountStatuses[row.accountId] = { status: row.status, message: row.message, storage: row.storage, checkedAt: row.checkedAt || new Date().toISOString() }; } renderAccounts(); return { updated: args.results.length }; },
|
||||||
'queue-list': async args => page(queueJobs.filter(job => !args.status || job.status === args.status).map(job => ({ id: job.id, file: job.file, fileName: job.fileName, hoster: job.hoster, status: job.status, bytesUploaded: job.bytesUploaded, bytesTotal: job.bytesTotal, speedKbs: job.speedKbs, error: job.error, result: job.result, attempt: job.attempt })), args),
|
'queue-list': async args => page(queueJobs.filter(job => !args.status || job.status === args.status).map(job => ({ id: job.id, file: job.file, fileName: job.fileName, hoster: job.hoster, status: job.status, bytesUploaded: job.bytesUploaded, bytesTotal: job.bytesTotal, speedKbs: job.speedKbs, error: job.error, result: job.result, attempt: job.attempt })), args),
|
||||||
'queue-add': async (args, guard) => {
|
'queue-add': async (args, guard) => {
|
||||||
@@ -105,9 +124,12 @@
|
|||||||
row.append(name, label, transferLabel, remove); return row;
|
row.append(name, label, transferLabel, remove); return row;
|
||||||
}));
|
}));
|
||||||
};
|
};
|
||||||
|
const syncPermissions = state => {
|
||||||
|
for (const input of document.querySelectorAll('#mcpControls .mcp-permissions input, #mcpControls [data-mcp-updates]')) input.checked = state?.capabilities?.includes(input.value) === true;
|
||||||
|
};
|
||||||
const act = async action => {
|
const act = async action => {
|
||||||
try { const state = await action(); if (state && typeof state === 'object') renderStatus(state); }
|
try { const state = await action(); if (state && typeof state === 'object') { renderStatus(state); syncPermissions(state); } }
|
||||||
catch { showCopyToast(text('MCP-Aktion fehlgeschlagen. Verbindung und lokale Berechtigungen prüfen.', 'MCP action failed. Check connection and local permissions.'), 6000, 'error'); if (current) renderStatus(current); }
|
catch { showCopyToast(text('MCP-Aktion fehlgeschlagen. Verbindung und lokale Berechtigungen prüfen.', 'MCP action failed. Check connection and local permissions.'), 6000, 'error'); if (current) { renderStatus(current); syncPermissions(current); } }
|
||||||
};
|
};
|
||||||
window.renderMcpSettings = () => `<section id="mcpControls" class="mcp-controls">
|
window.renderMcpSettings = () => `<section id="mcpControls" class="mcp-controls">
|
||||||
<div class="settings-section-label">MCP</div>
|
<div class="settings-section-label">MCP</div>
|
||||||
@@ -119,6 +141,8 @@
|
|||||||
<p>${text('Der Verbindungscode ist ein Zugangsschlüssel. Er wird weder im Backup gespeichert noch auf andere Installationen übertragen. Löschungen und andere gefährliche Aktionen verlangen eine lokale Bestätigung.', 'The connection code is a credential. It is not stored in backups or transferred to other installations. Deletions and other dangerous actions require local confirmation.')}</p>
|
<p>${text('Der Verbindungscode ist ein Zugangsschlüssel. Er wird weder im Backup gespeichert noch auf andere Installationen übertragen. Löschungen und andere gefährliche Aktionen verlangen eine lokale Bestätigung.', 'The connection code is a credential. It is not stored in backups or transferred to other installations. Deletions and other dangerous actions require local confirmation.')}</p>
|
||||||
<div class="mcp-actions"><button class="btn btn-sm btn-secondary" data-mcp-action="grant">${text('Ordner freigeben','Grant directory')}</button></div>
|
<div class="mcp-actions"><button class="btn btn-sm btn-secondary" data-mcp-action="grant">${text('Ordner freigeben','Grant directory')}</button></div>
|
||||||
<p>${text('Dateiinhalte werden nur nach zusätzlicher Freigabe pro Ordner übertragen. Bestehende Ordnerfreigaben erlauben dies nicht automatisch.', 'File contents are transferred only after additional permission for each directory. Existing directory grants do not allow this automatically.')}</p><div data-mcp-grants></div>
|
<p>${text('Dateiinhalte werden nur nach zusätzlicher Freigabe pro Ordner übertragen. Bestehende Ordnerfreigaben erlauben dies nicht automatisch.', 'File contents are transferred only after additional permission for each directory. Existing directory grants do not allow this automatically.')}</p><div data-mcp-grants></div>
|
||||||
|
<label class="mcp-update-permission"><input type="checkbox" value="updates" data-mcp-updates> ${text('Offizielle App-Updates ohne erneute Bestätigung erlauben', 'Allow official app updates without another confirmation')}</label>
|
||||||
|
<p>${text('Standardmäßig aus. Gilt nur für geprüfte Installer einer exakt angeforderten Version. Laufende Uploads werden abgeschlossen und die Warteschlange nach dem Neustart wieder aufgenommen. Portable-Versionen werden nicht unterstützt.', 'Disabled by default. Limited to verified installers of the exact requested version. Running uploads finish and the queue resumes after restart. Portable versions are not supported.')}</p>
|
||||||
</section>`;
|
</section>`;
|
||||||
window.bindMcpSettings = async () => {
|
window.bindMcpSettings = async () => {
|
||||||
const area = document.getElementById('mcpControls'); if (!area) return;
|
const area = document.getElementById('mcpControls'); if (!area) return;
|
||||||
@@ -126,7 +150,8 @@
|
|||||||
renderStatus(state);
|
renderStatus(state);
|
||||||
area.querySelector('#mcpName').value = state.name || 'Multi-Hoster-Uploader';
|
area.querySelector('#mcpName').value = state.name || 'Multi-Hoster-Uploader';
|
||||||
for (const input of area.querySelectorAll('.mcp-permissions input')) input.checked = state.capabilities?.includes(input.value) === true;
|
for (const input of area.querySelectorAll('.mcp-permissions input')) input.checked = state.capabilities?.includes(input.value) === true;
|
||||||
const configuration = enabled => ({ enabled, name: area.querySelector('#mcpName').value.trim(), capabilities: [...area.querySelectorAll('.mcp-permissions input:checked')].map(input => input.value) });
|
area.querySelector('[data-mcp-updates]').checked = state.capabilities?.includes('updates') === true;
|
||||||
|
const configuration = enabled => ({ enabled, name: area.querySelector('#mcpName').value.trim(), capabilities: [...area.querySelectorAll('.mcp-permissions input:checked, [data-mcp-updates]:checked')].map(input => input.value) });
|
||||||
area.querySelector('[data-mcp-action="enable"]').onclick = () => act(() => window.api.mcpConfigure(configuration(true)));
|
area.querySelector('[data-mcp-action="enable"]').onclick = () => act(() => window.api.mcpConfigure(configuration(true)));
|
||||||
area.querySelector('[data-mcp-action="disable"]').onclick = () => act(() => window.api.mcpConfigure(configuration(false)));
|
area.querySelector('[data-mcp-action="disable"]').onclick = () => act(() => window.api.mcpConfigure(configuration(false)));
|
||||||
area.querySelector('[data-mcp-action="rotate"]').onclick = () => act(() => window.api.mcpRotate());
|
area.querySelector('[data-mcp-action="rotate"]').onclick = () => act(() => window.api.mcpRotate());
|
||||||
|
|||||||
@@ -49,6 +49,9 @@ const sourceFiles = [
|
|||||||
'lib/mcp-store.js',
|
'lib/mcp-store.js',
|
||||||
'lib/mcp-tools.js',
|
'lib/mcp-tools.js',
|
||||||
'lib/mcp-transfers.js',
|
'lib/mcp-transfers.js',
|
||||||
|
'lib/mcp-update.js',
|
||||||
|
'lib/performance-monitor.js',
|
||||||
|
'lib/upload-file-io.js',
|
||||||
'lib/online-backup.js',
|
'lib/online-backup.js',
|
||||||
'lib/online-backup-keyring.js',
|
'lib/online-backup-keyring.js',
|
||||||
'lib/online-backup-manager.js',
|
'lib/online-backup-manager.js',
|
||||||
|
|||||||
Reference in new issue
Block a user