Preserve releasedAt timestamps during admin content sanitize
This commit is contained in:
+13
-3
@@ -226,10 +226,19 @@ function sanitizeArchivedSeriesNotes(value) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function sanitizeColossiansStudySections(value) {
|
function sanitizeColossiansStudySections(value) {
|
||||||
|
function normalizeReleasedAt(value) {
|
||||||
|
if (typeof value !== 'string' || !value.trim()) return ''
|
||||||
|
const parsed = Date.parse(value.trim())
|
||||||
|
if (!Number.isFinite(parsed)) return ''
|
||||||
|
return new Date(parsed).toISOString().replace('.000Z', 'Z')
|
||||||
|
}
|
||||||
|
|
||||||
const source = Array.isArray(value) ? value : []
|
const source = Array.isArray(value) ? value : []
|
||||||
return source
|
return source
|
||||||
.filter(item => item && typeof item === 'object')
|
.filter(item => item && typeof item === 'object')
|
||||||
.map(item => ({
|
.map(item => {
|
||||||
|
const releasedAt = normalizeReleasedAt(item.releasedAt)
|
||||||
|
return {
|
||||||
id: typeof item.id === 'string' && item.id.trim() ? item.id.trim() : randomUUID(),
|
id: typeof item.id === 'string' && item.id.trim() ? item.id.trim() : randomUUID(),
|
||||||
chapter: Number.isInteger(item.chapter) && item.chapter >= 1 && item.chapter <= 999 ? item.chapter : 1,
|
chapter: Number.isInteger(item.chapter) && item.chapter >= 1 && item.chapter <= 999 ? item.chapter : 1,
|
||||||
reference: typeof item.reference === 'string' ? item.reference.trim().slice(0, 40) : '',
|
reference: typeof item.reference === 'string' ? item.reference.trim().slice(0, 40) : '',
|
||||||
@@ -244,8 +253,9 @@ function sanitizeColossiansStudySections(value) {
|
|||||||
studyQuestions: Array.isArray(item.studyQuestions)
|
studyQuestions: Array.isArray(item.studyQuestions)
|
||||||
? item.studyQuestions.filter(question => typeof question === 'string').map(question => question.trim()).filter(Boolean).slice(0, 20)
|
? item.studyQuestions.filter(question => typeof question === 'string').map(question => question.trim()).filter(Boolean).slice(0, 20)
|
||||||
: [],
|
: [],
|
||||||
...(typeof item.releasedAt === 'string' && /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}Z$/.test(item.releasedAt) ? { releasedAt: item.releasedAt } : {}),
|
...(releasedAt ? { releasedAt } : {}),
|
||||||
}))
|
}
|
||||||
|
})
|
||||||
.filter(item => item.title || item.summary || item.commentary || item.greekNotes.length > 0 || item.studyQuestions.length > 0 || item.passageText)
|
.filter(item => item.title || item.summary || item.commentary || item.greekNotes.length > 0 || item.studyQuestions.length > 0 || item.passageText)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user