27 lines
1.0 KiB
TypeScript
27 lines
1.0 KiB
TypeScript
import type { Series } from '@/types/nostr'
|
|
import { objectCache } from './objectCache'
|
|
import { getCachedObjectById } from './helpers/queryHelpers'
|
|
|
|
export async function getSeriesByAuthor(authorPubkey: string, _timeoutMs: number = 5000): Promise<Series[]> {
|
|
// Read only from IndexedDB cache
|
|
const allSeries = await objectCache.getAll('series')
|
|
const series = allSeries as Series[]
|
|
|
|
// Filter by author pubkey
|
|
const authorSeries = series.filter((s) => s.pubkey === authorPubkey)
|
|
|
|
// Sort by hash (newest first - hash contains timestamp information)
|
|
// Since Series doesn't have createdAt, we sort by id which contains version/index
|
|
return authorSeries.sort((a, b) => {
|
|
// Sort by version descending, then by index descending
|
|
if (b.version !== a.version) {
|
|
return b.version - a.version
|
|
}
|
|
return b.index - a.index
|
|
})
|
|
}
|
|
|
|
export async function getSeriesById(seriesId: string, _timeoutMs: number = 2000): Promise<Series | null> {
|
|
return getCachedObjectById<Series>('series', seriesId)
|
|
}
|