Fix blocking upload logging and recover DoodStream socket failures; release 2.1.67
CI / verify (push) Canceled after 0s

This commit is contained in:
Sucukdeluxe committed 2026-10-18 01:34:05 +02:00
1 parent 5a0cad0ca5
commit 9b06b4f852
10 files changed
+254 -114

No files matched your search

+29 -5
View File
@@ -12,7 +12,7 @@ function createInternalLogPathResolver(options) {
const directories = [path.join(userDataPath, 'logs'), path.join(userDataPath, 'internal-logs')];
return function resolveInternalLogPath(fileName, excludedPaths = new Set()) {
function resolveInternalLogPath(fileName, excludedPaths = new Set()) {
if (typeof fileName !== 'string' || !fileName || path.basename(fileName) !== fileName) return null;
const excluded = excludedPaths instanceof Set
? excludedPaths
@@ -26,7 +26,21 @@ function createInternalLogPathResolver(options) {
} catch {}
}
return null;
}
resolveInternalLogPath.async = async (fileName, excludedPaths = new Set()) => {
if (typeof fileName !== 'string' || !fileName || path.basename(fileName) !== fileName) return null;
for (const directory of directories) {
const targetPath = path.join(directory, fileName);
if (excludedPaths.has(targetPath)) continue;
try {
await fs.promises.mkdir(directory, { recursive: true });
return targetPath;
} catch {}
}
return null;
};
return resolveInternalLogPath;
}
function createInternalLogWriter(options) {
@@ -36,26 +50,29 @@ function createInternalLogWriter(options) {
const fileName = source.fileName;
const resolveInternalLogPath = source.resolveInternalLogPath;
const rotateLogFile = typeof source.rotateLogFile === 'function' ? source.rotateLogFile : () => {};
const rotateLogFileAsync = typeof source.rotateLogFileAsync === 'function' ? source.rotateLogFileAsync : async () => {};
const resolveAsync = source.resolveInternalLogPathAsync || resolveInternalLogPath?.async;
const reportError = typeof source.reportError === 'function' ? source.reportError : () => {};
const retryDelays = Array.isArray(source.retryDelays) && source.retryDelays.length > 0 ? source.retryDelays : [0, 100, 250];
const maxBytes = Number.isFinite(source.maxBytes) ? source.maxBytes : 10 * 1024 * 1024;
const maxBackups = Number.isFinite(source.maxBackups) ? source.maxBackups : 2;
let activePath = null;
let pending = Promise.resolve();
if (!fs || !fs.promises || typeof fs.promises.appendFile !== 'function' || typeof fs.appendFileSync !== 'function' || typeof resolveInternalLogPath !== 'function' || typeof fileName !== 'string') {
throw new TypeError('createInternalLogWriter requires fs, fileName and resolveInternalLogPath');
}
async function append(line, label) {
async function write(line, label) {
const excludedPaths = new Set();
for (const delay of retryDelays) {
if (delay) await new Promise(resolve => setTimeout(resolve, delay));
const targetPath = resolveInternalLogPath(fileName, excludedPaths);
const targetPath = await resolveAsync(fileName, excludedPaths);
if (!targetPath) break;
excludedPaths.add(targetPath);
try {
fs.mkdirSync(path.dirname(targetPath), { recursive: true });
rotateLogFile(targetPath, maxBytes, maxBackups);
await fs.promises.mkdir(path.dirname(targetPath), { recursive: true });
await rotateLogFileAsync(targetPath, maxBytes, maxBackups);
await fs.promises.appendFile(targetPath, line, 'utf-8');
activePath = targetPath;
return true;
@@ -66,6 +83,12 @@ function createInternalLogWriter(options) {
return false;
}
function append(line, label) {
const operation = pending.then(() => write(line, label));
pending = operation.catch(() => {});
return operation;
}
function appendSync(line, label) {
const excludedPaths = new Set();
for (let attempt = 0; attempt < retryDelays.length; attempt++) {
@@ -96,6 +119,7 @@ function createInternalLogWriter(options) {
append,
appendSync,
flushSync,
drain: () => pending,
getActivePath: () => activePath,
getPath: () => activePath || resolveInternalLogPath(fileName)
};