replay timestamps in filenamess

This commit is contained in:
legop3
2026-07-21 16:29:10 -04:00
parent 0ecee03f64
commit 358aa0b1d6
4 changed files with 49 additions and 10 deletions
@@ -45,8 +45,9 @@ function describeSource(source) {
}
function sanitizeReplayTitleForFilename(title) {
// Discord attachment names should be readable and filesystem-safe.
// The title may originate from chat/web input, so strip separators and cap length before upload.
// Replay filenames are exposed by both Discord and the server-hosted fallback.
// The title may originate from chat/web input, so strip separators and cap its
// length before it is used in an attachment name, URL, or local filesystem path.
const cleaned = String(title || '')
.replace(/[\\/:*?"<>|]+/g, ' ')
.replace(/\s+/g, ' ')
@@ -55,6 +56,21 @@ function sanitizeReplayTitleForFilename(title) {
return cleaned || 'replay';
}
function buildReplayFilename(job = {}) {
const title = sanitizeReplayTitleForFilename(job.title);
const createdAt = Number(job.createdAt);
// The job creation time is shared by every delivery path. Using it instead
// of the later upload/hosting time guarantees that a Discord upload and its
// local fallback describe the same replay with the same readable filename.
// Date.now() is retained only as a defensive fallback for older callers that
// construct a minimal job object without going through createReplayJob().
const timestamp = Number.isFinite(createdAt) && createdAt > 0
? Math.trunc(createdAt)
: Date.now();
return `${title} ${timestamp}.mp4`;
}
function buildReplayTitle({ explicitTitle = '', sources = [] } = {}) {
const trimmed = normalizeText(explicitTitle).slice(0, 120);
if (trimmed) return trimmed;
@@ -379,6 +395,7 @@ module.exports = {
createReplayCaptionBuilder,
startDiscordTypingLoop,
sanitizeReplayTitleForFilename,
buildReplayFilename,
firstAttachmentFromMessage,
buildDiscordReplayMediaPayload,
buildAcceptedMessage,