+60
-1
src/lib/services/atproto/fetch.ts
+60
-1
src/lib/services/atproto/fetch.ts
···
1
import { PUBLIC_ATPROTO_DID } from '$env/static/public';
2
import { cache } from './cache';
3
import { withFallback, resolveIdentity } from './agents';
4
-
import type { ProfileData, StatusData, SiteInfoData, LinkData, MusicStatusData } from './types';
5
import { buildPdsBlobUrl } from './media';
6
import { findArtwork } from './musicbrainz';
7
···
339
return null;
340
}
341
}
···
1
import { PUBLIC_ATPROTO_DID } from '$env/static/public';
2
import { cache } from './cache';
3
import { withFallback, resolveIdentity } from './agents';
4
+
import type {
5
+
ProfileData,
6
+
StatusData,
7
+
SiteInfoData,
8
+
LinkData,
9
+
MusicStatusData,
10
+
KibunStatusData
11
+
} from './types';
12
import { buildPdsBlobUrl } from './media';
13
import { findArtwork } from './musicbrainz';
14
···
346
return null;
347
}
348
}
349
+
350
+
/**
351
+
* Fetches Kibun status from social.kibun.status collection
352
+
*/
353
+
export async function fetchKibunStatus(fetchFn?: typeof fetch): Promise<KibunStatusData | null> {
354
+
console.info('[KibunStatus] Fetching kibun status data');
355
+
const cacheKey = `kibun-status:${PUBLIC_ATPROTO_DID}`;
356
+
const cached = cache.get<KibunStatusData>(cacheKey);
357
+
if (cached) {
358
+
console.debug('[KibunStatus] Returning cached kibun status data');
359
+
return cached;
360
+
}
361
+
362
+
try {
363
+
console.info('[KibunStatus] Cache miss, fetching from network');
364
+
365
+
const statusRecords = await withFallback(
366
+
PUBLIC_ATPROTO_DID,
367
+
async (agent) => {
368
+
const response = await agent.com.atproto.repo.listRecords({
369
+
repo: PUBLIC_ATPROTO_DID,
370
+
collection: 'social.kibun.status',
371
+
limit: 1
372
+
});
373
+
return response.data.records;
374
+
},
375
+
true,
376
+
fetchFn
377
+
);
378
+
379
+
if (statusRecords && statusRecords.length > 0) {
380
+
const record = statusRecords[0];
381
+
const value = record.value as any;
382
+
383
+
const data: KibunStatusData = {
384
+
text: value.text,
385
+
emoji: value.emoji,
386
+
createdAt: value.createdAt,
387
+
$type: 'social.kibun.status'
388
+
};
389
+
390
+
console.info('[KibunStatus] Successfully fetched kibun status');
391
+
cache.set(cacheKey, data);
392
+
return data;
393
+
}
394
+
395
+
return null;
396
+
} catch (error) {
397
+
console.error('[KibunStatus] Failed to fetch kibun status from all sources:', error);
398
+
return null;
399
+
}
400
+
}
+9
-2
src/lib/services/atproto/index.ts
+9
-2
src/lib/services/atproto/index.ts
···
29
ResolvedIdentity,
30
CacheEntry,
31
MusicStatusData,
32
-
MusicArtist
33
} from './types';
34
35
export type { TangledRepo, TangledReposData } from './tangled';
36
37
// Export fetch functions
38
-
export { fetchProfile, fetchSiteInfo, fetchLinks, fetchMusicStatus } from './fetch';
39
40
export { fetchTangledRepos } from './tangled';
41
···
29
ResolvedIdentity,
30
CacheEntry,
31
MusicStatusData,
32
+
MusicArtist,
33
+
KibunStatusData
34
} from './types';
35
36
export type { TangledRepo, TangledReposData } from './tangled';
37
38
// Export fetch functions
39
+
export {
40
+
fetchProfile,
41
+
fetchSiteInfo,
42
+
fetchLinks,
43
+
fetchMusicStatus,
44
+
fetchKibunStatus
45
+
} from './fetch';
46
47
export { fetchTangledRepos } from './tangled';
48
+7
src/lib/services/atproto/types.ts
+7
src/lib/services/atproto/types.ts