This commit is contained in:
1 parent
1e289ee49b
commit
8f5bcd94bf
5 files changed
+42
-31
No files matched your search
+26
-16
@@ -207,7 +207,7 @@ class ConfigStore {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
_readHistoryFile() {
|
_readHistoryFileSync() {
|
||||||
try {
|
try {
|
||||||
const raw = fs.readFileSync(this.historyPath, 'utf-8');
|
const raw = fs.readFileSync(this.historyPath, 'utf-8');
|
||||||
if (!raw || raw.trim().length < 2) return [];
|
if (!raw || raw.trim().length < 2) return [];
|
||||||
@@ -220,6 +220,24 @@ class ConfigStore {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async _readHistoryFile() {
|
||||||
|
let raw;
|
||||||
|
try {
|
||||||
|
raw = await fs.promises.readFile(this.historyPath, 'utf-8');
|
||||||
|
} catch (error) {
|
||||||
|
if (error.code === 'ENOENT') return [];
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
|
if (!raw || !raw.trim()) return [];
|
||||||
|
let parsed;
|
||||||
|
try { parsed = JSON.parse(raw); } catch {}
|
||||||
|
if (Array.isArray(parsed)) return parsed;
|
||||||
|
if (parsed && Array.isArray(parsed.history)) return parsed.history;
|
||||||
|
const error = new Error('Die Verlaufsdatei ist beschädigt und wurde nicht verändert');
|
||||||
|
error.code = 'HISTORY_CORRUPT';
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
|
|
||||||
_writeHistoryFileDurable(arr) {
|
_writeHistoryFileDurable(arr) {
|
||||||
const tmp = this.historyPath + '.tmp';
|
const tmp = this.historyPath + '.tmp';
|
||||||
const fd = fs.openSync(tmp, 'w');
|
const fd = fs.openSync(tmp, 'w');
|
||||||
@@ -267,14 +285,14 @@ class ConfigStore {
|
|||||||
_migrateHistory() {
|
_migrateHistory() {
|
||||||
try {
|
try {
|
||||||
if (fs.existsSync(this.historyPath)) {
|
if (fs.existsSync(this.historyPath)) {
|
||||||
this._historyMigrated = Array.isArray(this._readHistoryFile());
|
this._historyMigrated = Array.isArray(this._readHistoryFileSync());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
let cfg = null;
|
let cfg = null;
|
||||||
try { cfg = this._readAndParse(this.filePath); } catch {}
|
try { cfg = this._readAndParse(this.filePath); } catch {}
|
||||||
const hist = (cfg && Array.isArray(cfg.history)) ? cfg.history : [];
|
const hist = (cfg && Array.isArray(cfg.history)) ? cfg.history : [];
|
||||||
this._writeHistoryFileDurable(hist);
|
this._writeHistoryFileDurable(hist);
|
||||||
const check = this._readHistoryFile();
|
const check = this._readHistoryFileSync();
|
||||||
if (Array.isArray(check) && check.length === hist.length) {
|
if (Array.isArray(check) && check.length === hist.length) {
|
||||||
if (hist.length > 0) {
|
if (hist.length > 0) {
|
||||||
try { fs.copyFileSync(this.filePath, this.filePath + '.pre-history-split.bak'); } catch {}
|
try { fs.copyFileSync(this.filePath, this.filePath + '.pre-history-split.bak'); } catch {}
|
||||||
@@ -769,9 +787,9 @@ class ConfigStore {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
loadHistory() {
|
async loadHistory() {
|
||||||
if (this._historyMigrated) {
|
if (this._historyMigrated) {
|
||||||
return this._readHistoryFile() || [];
|
return this._readHistoryFile();
|
||||||
}
|
}
|
||||||
const config = this.load();
|
const config = this.load();
|
||||||
return config.history || [];
|
return config.history || [];
|
||||||
@@ -802,12 +820,8 @@ class ConfigStore {
|
|||||||
|
|
||||||
appendHistory(entry) {
|
appendHistory(entry) {
|
||||||
if (this._historyMigrated) {
|
if (this._historyMigrated) {
|
||||||
return this._enqueueHistoryWrite(() => {
|
return this._enqueueHistoryWrite(async () => {
|
||||||
const cur = this._readHistoryFile();
|
const arr = await this._readHistoryFile();
|
||||||
if (cur === null && fs.existsSync(this.historyPath)) {
|
|
||||||
throw new Error('Die Verlaufsdatei ist beschädigt und wurde nicht verändert');
|
|
||||||
}
|
|
||||||
const arr = cur || [];
|
|
||||||
arr.push(entry);
|
arr.push(entry);
|
||||||
const gs = this.load().globalSettings;
|
const gs = this.load().globalSettings;
|
||||||
const retention = (gs && gs.historyRetention) || 'all';
|
const retention = (gs && gs.historyRetention) || 'all';
|
||||||
@@ -828,11 +842,7 @@ class ConfigStore {
|
|||||||
const dryRun = !!opts.dryRun;
|
const dryRun = !!opts.dryRun;
|
||||||
if (this._historyMigrated) {
|
if (this._historyMigrated) {
|
||||||
return this._enqueueHistoryWrite(async () => {
|
return this._enqueueHistoryWrite(async () => {
|
||||||
const storedHistory = this._readHistoryFile();
|
const current = await this._readHistoryFile();
|
||||||
if (storedHistory === null && fs.existsSync(this.historyPath)) {
|
|
||||||
throw new Error('Die Verlaufsdatei ist beschädigt und wurde nicht verändert');
|
|
||||||
}
|
|
||||||
const current = storedHistory || [];
|
|
||||||
const beforeBatches = current.length;
|
const beforeBatches = current.length;
|
||||||
const beforeRows = countHistoryRows(current);
|
const beforeRows = countHistoryRows(current);
|
||||||
const pruned = applyHistoryRetention(current, retention, Date.now());
|
const pruned = applyHistoryRetention(current, retention, Date.now());
|
||||||
|
|||||||
@@ -169,10 +169,10 @@ function createCollectors(deps) {
|
|||||||
return { errors, byCategory };
|
return { errors, byCategory };
|
||||||
}
|
}
|
||||||
|
|
||||||
function listErrors(args) {
|
async function listErrors(args, historySnapshot) {
|
||||||
const a = args || {};
|
const a = args || {};
|
||||||
const cfg = loadConfig();
|
const cfg = loadConfig();
|
||||||
const history = typeof loadHistory === 'function' ? loadHistory() : cfg.history;
|
const history = historySnapshot ?? (typeof loadHistory === 'function' ? await loadHistory() : cfg.history);
|
||||||
const { errors, byCategory } = _historyErrors(history, a);
|
const { errors, byCategory } = _historyErrors(history, a);
|
||||||
const limit = Math.min(Math.max(Number(a.limit) || 100, 1), 1000);
|
const limit = Math.min(Math.max(Number(a.limit) || 100, 1), 1000);
|
||||||
const window = Number.isFinite(a.sinceMs) ? `since ${new Date(a.sinceMs).toISOString()}` : 'all history';
|
const window = Number.isFinite(a.sinceMs) ? `since ${new Date(a.sinceMs).toISOString()}` : 'all history';
|
||||||
@@ -208,11 +208,11 @@ function createCollectors(deps) {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
function getHistory(args) {
|
async function getHistory(args, historySnapshot) {
|
||||||
const a = args || {};
|
const a = args || {};
|
||||||
const history = typeof loadHistory === 'function'
|
const history = historySnapshot ?? (typeof loadHistory === 'function'
|
||||||
? (loadHistory() || [])
|
? (await loadHistory() || [])
|
||||||
: (Array.isArray(loadConfig().history) ? loadConfig().history : []);
|
: (Array.isArray(loadConfig().history) ? loadConfig().history : []));
|
||||||
const limit = Math.min(Math.max(Number(a.limit) || 20, 1), 200);
|
const limit = Math.min(Math.max(Number(a.limit) || 20, 1), 200);
|
||||||
const perHoster = stats.summarizePerHoster(history);
|
const perHoster = stats.summarizePerHoster(history);
|
||||||
const recent = [...history].slice(-limit).reverse();
|
const recent = [...history].slice(-limit).reverse();
|
||||||
@@ -254,9 +254,10 @@ function createCollectors(deps) {
|
|||||||
const a = args || {};
|
const a = args || {};
|
||||||
const errorLimit = Math.min(Math.max(Number(a.errorLimit) || 20, 1), 200);
|
const errorLimit = Math.min(Math.max(Number(a.errorLimit) || 20, 1), 200);
|
||||||
const errArgs = Number.isFinite(a.errorSinceMs) ? { sinceMs: a.errorSinceMs, limit: errorLimit } : { limit: errorLimit };
|
const errArgs = Number.isFinite(a.errorSinceMs) ? { sinceMs: a.errorSinceMs, limit: errorLimit } : { limit: errorLimit };
|
||||||
const errors = listErrors(errArgs);
|
const historySnapshot = typeof loadHistory === 'function' ? await loadHistory() : loadConfig().history;
|
||||||
|
const errors = await listErrors(errArgs, historySnapshot);
|
||||||
const queue = getQueueState({ includeJobs: false });
|
const queue = getQueueState({ includeJobs: false });
|
||||||
const history = getHistory({ limit: 5 });
|
const history = await getHistory({ limit: 5 }, historySnapshot);
|
||||||
const warnings = [];
|
const warnings = [];
|
||||||
if (queue.source === 'persisted' && queue.stale) warnings.push('queue state is from the persisted snapshot (may lag live state; UploadManager not introspected in this build).');
|
if (queue.source === 'persisted' && queue.stale) warnings.push('queue state is from the persisted snapshot (may lag live state; UploadManager not introspected in this build).');
|
||||||
if (errors.total > 0) warnings.push(`${errors.total} non-success result(s) in the error window.`);
|
if (errors.total > 0) warnings.push(`${errors.total} non-success result(s) in the error window.`);
|
||||||
|
|||||||
@@ -2208,13 +2208,13 @@ ipcMain.handle('save-text-file', async (_event, defaultName, content, filters) =
|
|||||||
filters: safeFilters
|
filters: safeFilters
|
||||||
});
|
});
|
||||||
if (canceled || !filePath) return { ok: false, canceled: true };
|
if (canceled || !filePath) return { ok: false, canceled: true };
|
||||||
fs.writeFileSync(filePath, String(content === null || content === undefined ? '' : content), 'utf-8');
|
await fs.promises.writeFile(filePath, String(content === null || content === undefined ? '' : content), 'utf-8');
|
||||||
return { ok: true, path: filePath };
|
return { ok: true, path: filePath };
|
||||||
});
|
});
|
||||||
|
|
||||||
ipcMain.handle('export-history', async (_event, format) => {
|
ipcMain.handle('export-history', async (_event, format) => {
|
||||||
const normalizedFormat = String(format || 'csv').toLowerCase() === 'json' ? 'json' : 'csv';
|
const normalizedFormat = String(format || 'csv').toLowerCase() === 'json' ? 'json' : 'csv';
|
||||||
const history = configStore.loadHistory();
|
const history = await configStore.loadHistory();
|
||||||
const rows = flattenHistoryForExport(history);
|
const rows = flattenHistoryForExport(history);
|
||||||
const datePrefix = new Date().toISOString().slice(0, 10);
|
const datePrefix = new Date().toISOString().slice(0, 10);
|
||||||
|
|
||||||
@@ -2235,9 +2235,9 @@ ipcMain.handle('export-history', async (_event, format) => {
|
|||||||
totalRows: rows.length,
|
totalRows: rows.length,
|
||||||
history
|
history
|
||||||
};
|
};
|
||||||
fs.writeFileSync(filePath, JSON.stringify(payload, null, 2), 'utf-8');
|
await fs.promises.writeFile(filePath, JSON.stringify(payload, null, 2), 'utf-8');
|
||||||
} else {
|
} else {
|
||||||
fs.writeFileSync(filePath, buildHistoryCsv(rows), 'utf-8');
|
await fs.promises.writeFile(filePath, buildHistoryCsv(rows), 'utf-8');
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
|||||||
Generated
+2
-2
@@ -1,12 +1,12 @@
|
|||||||
{
|
{
|
||||||
"name": "multi-hoster-uploader",
|
"name": "multi-hoster-uploader",
|
||||||
"version": "2.1.69",
|
"version": "2.1.70",
|
||||||
"lockfileVersion": 3,
|
"lockfileVersion": 3,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"packages": {
|
"packages": {
|
||||||
"": {
|
"": {
|
||||||
"name": "multi-hoster-uploader",
|
"name": "multi-hoster-uploader",
|
||||||
"version": "2.1.69",
|
"version": "2.1.70",
|
||||||
"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.69",
|
"version": "2.1.70",
|
||||||
"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": {
|
||||||
|
|||||||
Reference in new issue
Block a user