feat: initial MVP - FastAPI backend + Vue3 frontend + docker-compose

- backend: FastAPI + SQLAlchemy 2.0(async) + asyncpg + Alembic
- 7 API routes: auth/me/articles/sources/bookmarks/subscriptions/admin
- models: User/Source/Article/Bookmark/Subscription/ApiToken
- services: RSS fetcher (feedparser) + Tencent TMT translator with quota + cache + local NLLB fallback
- workers: APScheduler + asyncio pipeline (fetch -> dedupe -> insert -> translate)
- seed scripts: create_user, seed_sources (5 RSS: Reuters/BBC/Al Jazeera/NHK/DW)
- frontend: Vue 3 + Vite + Naive UI + Pinia + vue-router
- pages: Login, Feed (24h), ArticleDetail, Sources, Bookmarks, AdminSources
- deploy: docker-compose (postgres/redis/api/worker/frontend/caddy)
- docs: README, DEPLOY, architecture, acceptance
This commit is contained in:
Mavis
2026-06-07 21:51:01 +08:00
commit 60b062daf2
81 changed files with 5540 additions and 0 deletions

View File

@@ -0,0 +1,111 @@
import { http } from './client'
export interface Source {
id: number
name: string
slug: string
kind: string
url: string
enabled: boolean
region?: string | null
language_src?: string | null
priority: number
fetch_interval_min: number
translate_to: string
last_fetched_at?: string | null
last_status?: string | null
consecutive_failures: number
}
export interface ArticleListItem {
id: number
source: { id: number; name: string; slug: string; region?: string | null }
title: string
title_zh?: string | null
summary_zh?: string | null
lang_src?: string | null
translation_status: string
category?: string | null
published_at?: string | null
fetched_at: string
image_url?: string | null
is_starred: boolean
}
export interface ArticleListResponse {
items: ArticleListItem[]
next_cursor: string | null
total: number | null
}
export interface ArticleDetail extends ArticleListItem {
url: string
body_html?: string | null
body_text: string
body_zh_html?: string | null
body_zh_text?: string | null
author?: string | null
translation_engine?: string | null
translated_at?: string | null
commentary?: string | null
entities?: Record<string, any> | null
sentiment?: number | null
duplicate_of?: number | null
}
export const articlesApi = {
list(params: Record<string, any> = {}) {
return http.get<ArticleListResponse>('/articles', { params }).then((r) => r.data)
},
get(id: number) {
return http.get<ArticleDetail>(`/articles/${id}`).then((r) => r.data)
},
}
export const sourcesApi = {
list() {
return http.get<Source[]>('/sources').then((r) => r.data)
},
}
export const meApi = {
me() {
return http.get('/me').then((r) => r.data)
},
usage() {
return http.get('/me/usage').then((r) => r.data)
},
}
export const bookmarksApi = {
list() {
return http.get<any[]>('/bookmarks').then((r) => r.data)
},
add(article_id: number, note?: string) {
return http.post('/bookmarks', { article_id, note }).then((r) => r.data)
},
remove(article_id: number) {
return http.delete(`/bookmarks/${article_id}`).then((r) => r.data)
},
}
export const adminApi = {
listSources() {
return http.get<Source[]>('/admin/sources').then((r) => r.data)
},
createSource(body: any) {
return http.post('/admin/sources', body).then((r) => r.data)
},
updateSource(id: number, body: any) {
return http.patch(`/admin/sources/${id}`, body).then((r) => r.data)
},
deleteSource(id: number) {
return http.delete(`/admin/sources/${id}`).then((r) => r.data)
},
refresh(id: number) {
return http.post(`/admin/refresh/${id}`).then((r) => r.data)
},
health() {
return http.get('/admin/health').then((r) => r.data)
},
}

View File

@@ -0,0 +1,37 @@
import axios, { AxiosError, type AxiosInstance } from 'axios'
import { useAuthStore } from '@/stores/auth'
const BASE = import.meta.env.VITE_API_BASE || '/api/v1'
export const http: AxiosInstance = axios.create({
baseURL: BASE,
timeout: 20000,
})
http.interceptors.request.use((cfg) => {
const auth = useAuthStore()
if (auth.accessToken) {
cfg.headers = cfg.headers ?? {}
cfg.headers.Authorization = `Bearer ${auth.accessToken}`
}
return cfg
})
http.interceptors.response.use(
(r) => r,
async (err: AxiosError) => {
const auth = useAuthStore()
const original: any = err.config
if (err.response?.status === 401 && !original?._retry && auth.refreshToken) {
original._retry = true
try {
await auth.refresh()
original.headers.Authorization = `Bearer ${auth.accessToken}`
return http(original)
} catch {
auth.logout()
}
}
return Promise.reject(err)
}
)