@@ -152,6 +152,15 @@ const resolveEpisodeEditors = (actor: AuditActor, fallback: unknown = []) => {
152152 return getEditors ( fallback ) ;
153153} ;
154154
155+ const resolveStoredEpisodeEditors = ( currentEditors : unknown , actor : AuditActor , fallback : unknown = [ ] ) => {
156+ const persistedEditors = getEditors ( currentEditors ) ;
157+ if ( persistedEditors . length > 0 ) {
158+ return persistedEditors ;
159+ }
160+
161+ return resolveEpisodeEditors ( actor , fallback ) ;
162+ } ;
163+
155164const coerceDate = ( value : Date | string | null | undefined ) => {
156165 const date = value instanceof Date ? value : value ? new Date ( value ) : new Date ( ) ;
157166 return Number . isNaN ( date . getTime ( ) ) ? new Date ( ) : date ;
@@ -222,6 +231,11 @@ interface ListAdminGeekDailyEpisodesInput extends PaginationInput {
222231 status ?: ContentStatus ;
223232}
224233
234+ interface ListPublicGeekDailyArchiveInput extends PaginationInput {
235+ year ?: number ;
236+ tag ?: string ;
237+ }
238+
225239const countItemsByEpisodeIds = async ( episodeIds : string [ ] ) => {
226240 const db = getDb ( ) ;
227241 if ( episodeIds . length === 0 ) {
@@ -282,6 +296,7 @@ export const listAdminGeekDailyEpisodes = async (
282296 slug : getGeekDailyEpisodeSlug ( row . episodeNumber ) ,
283297 episodeNumber : row . episodeNumber ,
284298 title : row . title ,
299+ editors : getEditors ( row . editorsJson ) ,
285300 status : row . status ,
286301 publishedAt : toIsoString ( row . publishedAt ) ?? new Date ( ) . toISOString ( ) ,
287302 itemCount : itemCounts . get ( row . id ) ?? 0 ,
@@ -344,7 +359,7 @@ export const updateAdminGeekDailyEpisode = async (id: string, input: GeekDailyEp
344359 }
345360
346361 await ensureEpisodeNumberAvailable ( input . episodeNumber , id ) ;
347- const editors = resolveEpisodeEditors ( actor , current . editors ) ;
362+ const editors = resolveStoredEpisodeEditors ( current . editors , actor , input . editors ) ;
348363
349364 await db
350365 . update ( geekdailyEpisodes )
@@ -383,7 +398,7 @@ export const publishAdminGeekDailyEpisode = async (id: string, actor: AuditActor
383398 if ( ! current ) {
384399 throw notFound ( 'GeekDaily episode not found' ) ;
385400 }
386- const editors = resolveEpisodeEditors ( actor , current . editors ) ;
401+ const editors = resolveStoredEpisodeEditors ( current . editors , actor ) ;
387402
388403 await db
389404 . update ( geekdailyEpisodes )
@@ -489,6 +504,58 @@ export const listPublicGeekDailyEpisodePreviews = async (limit = -1) => {
489504 } ) ;
490505} ;
491506
507+ export const listPublicGeekDailyArchivePage = async ( input : ListPublicGeekDailyArchiveInput = { } ) => {
508+ const normalizedYear = Number . isFinite ( input . year ) && ( input . year ?? 0 ) > 0 ? Math . floor ( input . year as number ) : undefined ;
509+ const normalizedTag = input . tag ?. trim ( ) ?? '' ;
510+ const requestedPageSize = Number . isFinite ( input . pageSize ) && ( input . pageSize ?? 0 ) > 0 ? Math . floor ( input . pageSize as number ) : 18 ;
511+
512+ return withPublicGeekDailyCache (
513+ `archive:${ input . page ?? 1 } :${ requestedPageSize } :${ normalizedYear ?? 'all' } :${ normalizedTag || 'all' } ` ,
514+ async ( ) => {
515+ const db = getDb ( ) ;
516+ const where = combineFilters ( [
517+ eq ( geekdailyEpisodes . status , 'published' ) ,
518+ normalizedYear ? sql `extract(year from ${ geekdailyEpisodes . publishedAt } )::int = ${ normalizedYear } ` : undefined ,
519+ normalizedTag ? sql `${ geekdailyEpisodes . tagsJson } @> ${ JSON . stringify ( [ normalizedTag ] ) } ::jsonb` : undefined ,
520+ ] ) ;
521+
522+ const countRow = await db . select ( { value : count ( ) } ) . from ( geekdailyEpisodes ) . where ( where ) ;
523+ const totalItems = countRow [ 0 ] ?. value ?? 0 ;
524+ const pagination = resolvePagination (
525+ {
526+ page : input . page ,
527+ pageSize : requestedPageSize ,
528+ } ,
529+ totalItems ,
530+ ) ;
531+ const rows =
532+ totalItems === 0
533+ ? [ ]
534+ : await db
535+ . select ( {
536+ id : geekdailyEpisodes . id ,
537+ episodeNumber : geekdailyEpisodes . episodeNumber ,
538+ title : geekdailyEpisodes . title ,
539+ summary : geekdailyEpisodes . summary ,
540+ editorsJson : geekdailyEpisodes . editorsJson ,
541+ tagsJson : geekdailyEpisodes . tagsJson ,
542+ publishedAt : geekdailyEpisodes . publishedAt ,
543+ } )
544+ . from ( geekdailyEpisodes )
545+ . where ( where )
546+ . orderBy ( desc ( geekdailyEpisodes . episodeNumber ) )
547+ . limit ( pagination . pageSize )
548+ . offset ( pagination . offset ) ;
549+ const itemsByEpisode = await loadItemsByEpisodeIds ( rows . map ( ( row ) => row . id ) ) ;
550+
551+ return {
552+ items : rows . map ( ( row ) => mapPublicEpisodePreview ( row , itemsByEpisode . get ( row . id ) ?? [ ] ) ) ,
553+ meta : buildPaginatedMeta ( pagination ) ,
554+ } ;
555+ } ,
556+ ) ;
557+ } ;
558+
492559export const getPublicGeekDailyEpisodeBySlug = async ( slug : string ) => {
493560 return withPublicGeekDailyCache ( `episode:${ slug } ` , async ( ) => {
494561 const row = await getEpisodeRecordBySlug ( slug ) ;
@@ -542,6 +609,7 @@ export const getGeekDailySearchDocuments = async () => {
542609 episodeNumber : geekdailyEpisodes . episodeNumber ,
543610 title : geekdailyEpisodes . title ,
544611 summary : geekdailyEpisodes . summary ,
612+ editorsJson : geekdailyEpisodes . editorsJson ,
545613 tagsJson : geekdailyEpisodes . tagsJson ,
546614 publishedAt : geekdailyEpisodes . publishedAt ,
547615 } )
@@ -558,6 +626,7 @@ export const getGeekDailySearchDocuments = async () => {
558626 episodeNumber : row . episodeNumber ,
559627 title : row . title ,
560628 summary : row . summary ,
629+ editors : getEditors ( row . editorsJson ) ,
561630 tags : getTags ( row . tagsJson ) ,
562631 publishedAt,
563632 year : String ( new Date ( publishedAt ) . getUTCFullYear ( ) ) ,
0 commit comments