import fs from "node:fs"; import path from "node:path"; import type { ReplyPayload } from "../../auto-reply/types.js"; import { resolveStateDir } from "../../config/paths.js"; import type { ReplyToMode } from "../../config/types.js"; import { generateSecureUuid } from "../secure-random.js"; import type { OutboundDeliveryFormattingOptions } from "./formatting.js"; import type { OutboundMirror } from "./mirror.js"; import type { OutboundSessionContext } from "./session-context.js"; import type { OutboundChannel } from "./targets.js";
/** Load a single pending delivery entry by ID from the queue directory. */
export async function loadPendingDelivery(
id: string,
stateDir?: string,
): Promise<QueuedDelivery | null> { const { jsonPath } = resolveQueueEntryPaths(id, stateDir); try { const stat = await fs.promises.stat(jsonPath); if (!stat.isFile()) { returnnull;
} const { entry, migrated } = normalizeLegacyQueuedDeliveryEntry(await readQueueEntry(jsonPath)); if (migrated) {
await writeQueueEntry(jsonPath, entry);
} return entry;
} catch (err) { if (getErrnoCode(err) === "ENOENT") { returnnull;
} throw err;
}
}
/** Load all pending delivery entries from the queue directory. */
export async function loadPendingDeliveries(stateDir?: string): Promise<QueuedDelivery[]> { const queueDir = resolveQueueDir(stateDir);
let files: string[]; try {
files = await fs.promises.readdir(queueDir);
} catch (err) { const code = getErrnoCode(err); if (code === "ENOENT") { return [];
} throw err;
}
// Clean up .delivered markers left by ackDelivery if the process crashed // between the rename and the unlink. for (const file of files) { if (file.endsWith(".delivered")) {
await unlinkBestEffort(path.join(queueDir, file));
}
}
const entries: QueuedDelivery[] = []; for (const file of files) { if (!file.endsWith(".json")) { continue;
} const filePath = path.join(queueDir, file); try { const stat = await fs.promises.stat(filePath); if (!stat.isFile()) { continue;
} const { entry, migrated } = normalizeLegacyQueuedDeliveryEntry(
await readQueueEntry(filePath),
); if (migrated) {
await writeQueueEntry(filePath, entry);
}
entries.push(entry);
} catch { // Skip malformed or inaccessible entries.
}
} return entries;
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.