add post, fix profile err

This commit is contained in:
2025-08-09 11:23:05 +09:00
parent 55745ff051
commit c3cb3db680
5 changed files with 1880 additions and 10 deletions

View File

@@ -83,11 +83,14 @@ export const atproto = {
return await request(`${apiEndpoint}/xrpc/${ENDPOINTS.getProfile}?actor=${actor}`)
},
async getRecords(pds, repo, collection, limit = 10, cursor = null) {
async getRecords(pds, repo, collection, limit = 10, cursor = null, reverse = false) {
let url = `${pds}/xrpc/${ENDPOINTS.listRecords}?repo=${repo}&collection=${collection}&limit=${limit}`
if (cursor) {
url += `&cursor=${cursor}`
}
if (reverse) {
url += `&reverse=true`
}
const res = await request(url)
return {
records: res.records || [],
@@ -151,7 +154,7 @@ export const collections = {
const cached = dataCache.get(cacheKey)
if (cached) return cached
const data = await atproto.getRecords(pds, repo, `${collection}.chat.comment`, limit)
const data = await atproto.getRecords(pds, repo, `${collection}.chat.comment`, limit, null, true) // reverse=true for chronological order
// Extract records array for backward compatibility
const records = data.records || data
dataCache.set(cacheKey, records)
@@ -161,7 +164,7 @@ export const collections = {
async getChat(pds, repo, collection, limit = 10, cursor = null) {
// Don't use cache for pagination requests
if (cursor) {
const result = await atproto.getRecords(pds, repo, `${collection}.chat`, limit, cursor)
const result = await atproto.getRecords(pds, repo, `${collection}.chat`, limit, cursor, true) // reverse=true for chronological order
return result
}
@@ -172,7 +175,7 @@ export const collections = {
return Array.isArray(cached) ? { records: cached, cursor: null } : cached
}
const data = await atproto.getRecords(pds, repo, `${collection}.chat`, limit)
const data = await atproto.getRecords(pds, repo, `${collection}.chat`, limit, null, true) // reverse=true for chronological order
// Cache only the records array for backward compatibility
dataCache.set(cacheKey, data.records || data)
return data