chore: fedi -> bsky
This commit is contained in:
parent
aaa0e20f3d
commit
3fc79cd768
5 changed files with 67 additions and 73 deletions
|
@ -15,8 +15,8 @@
|
|||
"@astrojs/check": "^0.9.1",
|
||||
"@astrojs/node": "^8.3.2",
|
||||
"@astrojs/solid-js": "^4.4.0",
|
||||
"@fuman/fetch": "https://pkg.pr.new/teidesu/fuman/@fuman/fetch@b0c74cb",
|
||||
"@fuman/utils": "https://pkg.pr.new/teidesu/fuman/@fuman/utils@b0c74cb",
|
||||
"@fuman/fetch": "https://pkg.pr.new/teidesu/fuman/@fuman/fetch@781fbba",
|
||||
"@fuman/utils": "https://pkg.pr.new/teidesu/fuman/@fuman/utils@781fbba",
|
||||
"@mtcute/dispatcher": "^0.16.0",
|
||||
"@mtcute/node": "^0.16.3",
|
||||
"@tanstack/solid-query": "^5.51.21",
|
||||
|
|
|
@ -18,11 +18,11 @@ importers:
|
|||
specifier: ^4.4.0
|
||||
version: 4.4.0(solid-js@1.8.19)(vite@5.3.5(@types/node@22.0.2)(sugarss@4.0.1(postcss@8.4.40)))
|
||||
'@fuman/fetch':
|
||||
specifier: https://pkg.pr.new/teidesu/fuman/@fuman/fetch@b0c74cb
|
||||
version: https://pkg.pr.new/teidesu/fuman/@fuman/fetch@b0c74cb(zod@3.23.8)
|
||||
specifier: https://pkg.pr.new/teidesu/fuman/@fuman/fetch@781fbba
|
||||
version: https://pkg.pr.new/teidesu/fuman/@fuman/fetch@781fbba(zod@3.23.8)
|
||||
'@fuman/utils':
|
||||
specifier: https://pkg.pr.new/teidesu/fuman/@fuman/utils@b0c74cb
|
||||
version: https://pkg.pr.new/teidesu/fuman/@fuman/utils@b0c74cb
|
||||
specifier: https://pkg.pr.new/teidesu/fuman/@fuman/utils@781fbba
|
||||
version: https://pkg.pr.new/teidesu/fuman/@fuman/utils@781fbba
|
||||
'@mtcute/dispatcher':
|
||||
specifier: ^0.16.0
|
||||
version: 0.16.0
|
||||
|
@ -825,8 +825,8 @@ packages:
|
|||
resolution: {integrity: sha512-BsWiH1yFGjXXS2yvrf5LyuoSIIbPrGUWob917o+BTKuZ7qJdxX8aJLRxs1fS9n6r7vESrq1OUqb68dANcFXuQQ==}
|
||||
engines: {node: ^18.18.0 || ^20.9.0 || >=21.1.0}
|
||||
|
||||
'@fuman/fetch@https://pkg.pr.new/teidesu/fuman/@fuman/fetch@b0c74cb':
|
||||
resolution: {tarball: https://pkg.pr.new/teidesu/fuman/@fuman/fetch@b0c74cb}
|
||||
'@fuman/fetch@https://pkg.pr.new/teidesu/fuman/@fuman/fetch@781fbba':
|
||||
resolution: {tarball: https://pkg.pr.new/teidesu/fuman/@fuman/fetch@781fbba}
|
||||
version: 0.0.1
|
||||
peerDependencies:
|
||||
tough-cookie: ^5.0.0 || ^4.0.0
|
||||
|
@ -843,8 +843,8 @@ packages:
|
|||
zod:
|
||||
optional: true
|
||||
|
||||
'@fuman/utils@https://pkg.pr.new/teidesu/fuman/@fuman/utils@b0c74cb':
|
||||
resolution: {tarball: https://pkg.pr.new/teidesu/fuman/@fuman/utils@b0c74cb}
|
||||
'@fuman/utils@https://pkg.pr.new/teidesu/fuman/@fuman/utils@781fbba':
|
||||
resolution: {tarball: https://pkg.pr.new/teidesu/fuman/@fuman/utils@781fbba}
|
||||
version: 0.0.1
|
||||
|
||||
'@humanwhocodes/module-importer@1.0.1':
|
||||
|
@ -4466,13 +4466,13 @@ snapshots:
|
|||
|
||||
'@eslint/object-schema@2.1.4': {}
|
||||
|
||||
'@fuman/fetch@https://pkg.pr.new/teidesu/fuman/@fuman/fetch@b0c74cb(zod@3.23.8)':
|
||||
'@fuman/fetch@https://pkg.pr.new/teidesu/fuman/@fuman/fetch@781fbba(zod@3.23.8)':
|
||||
dependencies:
|
||||
'@fuman/utils': https://pkg.pr.new/teidesu/fuman/@fuman/utils@b0c74cb
|
||||
'@fuman/utils': https://pkg.pr.new/teidesu/fuman/@fuman/utils@781fbba
|
||||
optionalDependencies:
|
||||
zod: 3.23.8
|
||||
|
||||
'@fuman/utils@https://pkg.pr.new/teidesu/fuman/@fuman/utils@b0c74cb': {}
|
||||
'@fuman/utils@https://pkg.pr.new/teidesu/fuman/@fuman/utils@781fbba': {}
|
||||
|
||||
'@humanwhocodes/module-importer@1.0.1': {}
|
||||
|
||||
|
|
39
src/backend/service/last-seen/bsky.ts
Normal file
39
src/backend/service/last-seen/bsky.ts
Normal file
|
@ -0,0 +1,39 @@
|
|||
import { AsyncResource } from '@fuman/utils'
|
||||
import { z } from 'zod'
|
||||
|
||||
import { ffetch } from '../../utils/fetch.ts'
|
||||
|
||||
const ENDPOINT = 'https://public.api.bsky.app/xrpc/app.bsky.feed.getAuthorFeed'
|
||||
const TTL = 3 * 60 * 60 * 1000 // 3 hours
|
||||
const STALE_TTL = 8 * 60 * 60 * 1000 // 8 hours
|
||||
|
||||
const schema = z.object({
|
||||
uri: z.string(),
|
||||
record: z.object({
|
||||
text: z.string(),
|
||||
createdAt: z.string(),
|
||||
}),
|
||||
})
|
||||
|
||||
export const bskyLastSeen = new AsyncResource<z.infer<typeof schema>>({
|
||||
async fetcher() {
|
||||
const res = await ffetch(ENDPOINT, {
|
||||
query: {
|
||||
actor: 'did:web:tei.su',
|
||||
filter: 'posts_and_author_threads',
|
||||
limit: 1,
|
||||
},
|
||||
}).parsedJson(z.object({
|
||||
feed: z.array(z.object({
|
||||
post: schema,
|
||||
})),
|
||||
}))
|
||||
|
||||
return {
|
||||
data: res.feed[0].post,
|
||||
expiresIn: TTL,
|
||||
}
|
||||
},
|
||||
swr: true,
|
||||
swrValidator: ({ currentFetchedAt }) => Date.now() - currentFetchedAt < STALE_TTL,
|
||||
})
|
|
@ -1,49 +0,0 @@
|
|||
// import { z } from 'zod'
|
||||
|
||||
// import { Reloadable } from '~/backend/utils/reloadable'
|
||||
// import { zodValidate } from '~/utils/zod'
|
||||
|
||||
// const ENDPOINT = 'https://very.stupid.fish/api/users/notes'
|
||||
// const TTL = 3 * 60 * 60 * 1000 // 3 hours
|
||||
// const STALE_TTL = 8 * 60 * 60 * 1000 // 8 hours
|
||||
// const BODY = {
|
||||
// userId: '9o5tqc3ok6pf5hjx',
|
||||
// withRenotes: false,
|
||||
// withReplies: false,
|
||||
// withChannelNotes: false,
|
||||
// withFiles: false,
|
||||
// limit: 1,
|
||||
// allowPartial: true,
|
||||
// }
|
||||
|
||||
// const schema = z.object({
|
||||
// id: z.string(),
|
||||
// createdAt: z.string(),
|
||||
// updatedAt: z.string().nullable().optional(),
|
||||
// text: z.nullable(z.string()),
|
||||
// })
|
||||
|
||||
// export const fediLastSeen = new Reloadable<z.infer<typeof schema>>({
|
||||
// name: 'fedi-last-seen',
|
||||
// async fetch() {
|
||||
// const res = await fetch(ENDPOINT, {
|
||||
// method: 'POST',
|
||||
// body: JSON.stringify(BODY),
|
||||
// headers: {
|
||||
// 'Content-Type': 'application/json',
|
||||
// },
|
||||
// })
|
||||
|
||||
// if (!res.ok) {
|
||||
// throw new Error(`Failed to fetch fedi last seen: ${res.status} ${await res.text()}`)
|
||||
// }
|
||||
|
||||
// const data = await zodValidate(z.array(schema), await res.json())
|
||||
|
||||
// return data[0]
|
||||
// },
|
||||
// expiresIn: () => TTL,
|
||||
// lazy: true,
|
||||
// swr: true,
|
||||
// swrValidator: (_data, time) => Date.now() - time < STALE_TTL,
|
||||
// })
|
|
@ -1,3 +1,6 @@
|
|||
import { assertMatches } from '@fuman/utils'
|
||||
|
||||
import { bskyLastSeen } from './bsky.ts'
|
||||
import { githubLastSeen } from './github'
|
||||
import { lastfm } from './lastfm'
|
||||
import { shikimoriLastSeen } from './shikimori'
|
||||
|
@ -14,12 +17,12 @@ export interface LastSeenItem {
|
|||
export async function fetchLastSeen() {
|
||||
const [
|
||||
lastfmData,
|
||||
// fediData,
|
||||
bskyData,
|
||||
shikimoriData,
|
||||
githubData,
|
||||
] = await Promise.all([
|
||||
lastfm.get(),
|
||||
// fediLastSeen.get(),
|
||||
bskyLastSeen.get(),
|
||||
shikimoriLastSeen.get(),
|
||||
githubLastSeen.get(),
|
||||
])
|
||||
|
@ -36,15 +39,16 @@ export async function fetchLastSeen() {
|
|||
})
|
||||
}
|
||||
|
||||
// if (fediData) {
|
||||
// res.push({
|
||||
// source: 'fedi',
|
||||
// sourceLink: 'https://very.stupid.fish/@teidesu',
|
||||
// time: new Date(fediData.updatedAt ?? fediData.createdAt).getTime(),
|
||||
// text: fediData.text?.slice(0, 40) || '[no text]',
|
||||
// link: `https://very.stupid.fish/notes/${fediData.id}`,
|
||||
// })
|
||||
// }
|
||||
if (bskyData) {
|
||||
const postId = assertMatches(bskyData.uri, /at:\/\/did:web:tei.su\/app\.bsky\.feed\.post\/([a-zA-Z0-9]+)/)
|
||||
res.push({
|
||||
source: 'bsky',
|
||||
sourceLink: 'https://bsky.app/profile/did:web:tei.su',
|
||||
time: new Date(bskyData.record.createdAt).getTime(),
|
||||
text: bskyData.record.text.slice(0, 40) || '[no text]',
|
||||
link: `https://bsky.app/profile/did:web:tei.su/post/${postId[0]}`,
|
||||
})
|
||||
}
|
||||
|
||||
if (shikimoriData) {
|
||||
// thx morr for this fucking awesome api
|
||||
|
|
Loading…
Reference in a new issue