feat: outbox model for the following feed

This commit is contained in:
codytseng
2025-03-27 22:37:06 +08:00
parent df4eb10802
commit d24e208f0b
22 changed files with 642 additions and 517 deletions

View File

@@ -4,31 +4,34 @@ import DataLoader from 'dataloader'
class WebService {
static instance: WebService
private webMetadataDataLoader = new DataLoader<string, TWebMetadata>(async (urls) => {
return await Promise.all(
urls.map(async (url) => {
try {
const res = await fetch(url)
const html = await res.text()
const parser = new DOMParser()
const doc = parser.parseFromString(html, 'text/html')
private webMetadataDataLoader = new DataLoader<string, TWebMetadata>(
async (urls) => {
return await Promise.all(
urls.map(async (url) => {
try {
const res = await fetch(url)
const html = await res.text()
const parser = new DOMParser()
const doc = parser.parseFromString(html, 'text/html')
const title =
doc.querySelector('meta[property="og:title"]')?.getAttribute('content') ||
doc.querySelector('title')?.textContent
const description =
doc.querySelector('meta[property="og:description"]')?.getAttribute('content') ||
(doc.querySelector('meta[name="description"]') as HTMLMetaElement | null)?.content
const image = (doc.querySelector('meta[property="og:image"]') as HTMLMetaElement | null)
?.content
const title =
doc.querySelector('meta[property="og:title"]')?.getAttribute('content') ||
doc.querySelector('title')?.textContent
const description =
doc.querySelector('meta[property="og:description"]')?.getAttribute('content') ||
(doc.querySelector('meta[name="description"]') as HTMLMetaElement | null)?.content
const image = (doc.querySelector('meta[property="og:image"]') as HTMLMetaElement | null)
?.content
return { title, description, image }
} catch {
return {}
}
})
)
})
return { title, description, image }
} catch {
return {}
}
})
)
},
{ maxBatchSize: 1 }
)
constructor() {
if (!WebService.instance) {