Keep fetching library pages after the first 50 so the whole folder is reachable.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
Towsty
2026-09-30 00:28:22 -05:00
co-authored by Cursor
parent 17bb42bea4
commit 9481791ac5
4 changed files with 89 additions and 45 deletions
+6 -1
View File
@@ -737,7 +737,12 @@ const sourceSlot=computed(()=>{const clip=clips.value.find((a:any)=>a.id===form.
const pickerAssets=computed(()=>picker.value==='startClipId'?clips.value.map((a:any)=>({...a,kind:'clip'})):stills.value.map((a:any)=>({...a,kind:'still'})))
const inputStill=computed(()=>stills.value.find((s:any)=>s.id===form.imageAId))
const family=computed(()=>folderAssets(library.value,jobs.value,form.folderId))
const familyStillCount=computed(()=>family.value.filter((a:any)=>a.kind==='still').length)
const familyStillCount=computed(()=>{
const folder=(library.value.folders||[]).find((f:any)=>f.id===form.folderId)
const fromFolder=Number(folder?.imageCount||0)
if(fromFolder>0) return fromFolder
return family.value.filter((a:any)=>a.kind==='still').length
})
const sourceAsset=computed(()=>form.startClipId?clips.value.find((c:any)=>c.id===form.startClipId):stills.value.find((s:any)=>s.id===(form.imageAId||form.identityStillId||form.photos?.[0]?.stillId)))
const sourceSize=computed(()=>measured[sourceAsset.value?.id] || sourceAsset.value)
const resolvedSize=computed(()=>resolveSize(form.settings.aspect,sourceSize.value,undefined,form.engine))
+17 -7
View File
@@ -286,7 +286,7 @@ function applyLibraryPage(data: any, replace: boolean) {
fetchedAt.value = Date.now()
}
async function fetchLibraryPage(cursor: string | null, replace: boolean) {
async function fetchLibraryPage(cursor: string | null) {
const folder = activeFolderId.value && activeFolderId.value !== 'all' ? activeFolderId.value : ''
const type = filter.value === 'all' ? 'all' : filter.value === 'images' ? 'images' : filter.value === 'videos' ? 'videos' : 'music'
const qs = new URLSearchParams({ limit: '50' })
@@ -296,28 +296,33 @@ async function fetchLibraryPage(cursor: string | null, replace: boolean) {
return await $fetch<any>(`/api/library?${qs.toString()}`)
}
let fetchGen = 0
async function fetchLibrary(force = false) {
if (loading.value) return
const stale = !fetchedAt.value || Date.now() - fetchedAt.value > 15_000
const empty = !stills.value.length && !clips.value.length && !tracks.value.length
if (!force && !empty && !stale) return
const gen = ++fetchGen
loading.value = true
loadError.value = ''
liveThumbs.value = new Set()
try {
const first = await fetchLibraryPage(null, true)
const first = await fetchLibraryPage(null)
if (gen !== fetchGen) return
applyLibraryPage(first, true)
loading.value = false
nextTick(() => observeThumbs())
// Pull remaining pages in the background — first paint already has ≤50 items
// Keep fetching until the folder is exhausted — 50 is a page size, not a cap
let cursor = first?.nextCursor || null
while (cursor) {
const more = await fetchLibraryPage(cursor, false)
while (cursor && gen === fetchGen) {
const more = await fetchLibraryPage(cursor)
if (gen !== fetchGen) return
applyLibraryPage(more, false)
cursor = more?.nextCursor || null
nextTick(() => observeThumbs())
}
} catch (e: any) {
if (gen !== fetchGen) return
loadError.value = e?.data?.statusMessage || e?.message || 'Could not load library'
loading.value = false
}
@@ -354,7 +359,7 @@ async function fetchMore() {
if (!nextCursor.value || loading.value) return
loading.value = true
try {
const more = await fetchLibraryPage(nextCursor.value, false)
const more = await fetchLibraryPage(nextCursor.value)
applyLibraryPage(more, false)
nextTick(() => observeThumbs())
} catch { /* keep what we have */ }
@@ -404,6 +409,11 @@ watch(() => props.open, (on) => {
watch(entries, () => nextTick(() => observeThumbs()))
watch([filter, activeFolderId], () => {
if (!props.open) return
void fetchLibrary(true)
})
onBeforeUnmount(() => {
if (import.meta.client) {
document.body.style.overflow = ''