mirror of
https://github.com/dergigi/boris.git
synced 2025-12-18 15:14:20 +01:00
- Move ogStore, ogHtml, and articleMeta from src/services/ to api/services/ - Update imports in article-og.ts and article-og-refresh.ts - Update import paths in articleMeta.ts (lib/profile and src/config/relays) - Remove old files from src/services/ - Clean up ESLint config to only reference api/**/*.ts This fixes the ERR_MODULE_NOT_FOUND error on Vercel by ensuring serverless functions can access the service modules.
26 lines
784 B
TypeScript
26 lines
784 B
TypeScript
import { Redis } from '@upstash/redis'
|
|
|
|
const redisWrite = Redis.fromEnv()
|
|
const redisRead = process.env.KV_REST_API_READ_ONLY_TOKEN && process.env.KV_REST_API_URL
|
|
? new Redis({ url: process.env.KV_REST_API_URL!, token: process.env.KV_REST_API_READ_ONLY_TOKEN! })
|
|
: redisWrite
|
|
|
|
const keyOf = (naddr: string) => `og:${naddr}`
|
|
|
|
export type ArticleMetadata = {
|
|
title: string
|
|
summary: string
|
|
image: string
|
|
author: string
|
|
published?: number
|
|
}
|
|
|
|
export async function getArticleMeta(naddr: string): Promise<ArticleMetadata | null> {
|
|
return (await redisRead.get<ArticleMetadata>(keyOf(naddr))) || null
|
|
}
|
|
|
|
export async function setArticleMeta(naddr: string, meta: ArticleMetadata, ttlSec = 604800): Promise<void> {
|
|
await redisWrite.set(keyOf(naddr), meta, { ex: ttlSec })
|
|
}
|
|
|