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:
39
frontend/src/router.ts
Normal file
39
frontend/src/router.ts
Normal file
@@ -0,0 +1,39 @@
|
||||
import { createRouter, createWebHistory, type RouteRecordRaw } from 'vue-router'
|
||||
import { useAuthStore } from '@/stores/auth'
|
||||
|
||||
const routes: RouteRecordRaw[] = [
|
||||
{ path: '/login', component: () => import('@/views/Login.vue'), meta: { layout: 'blank' } },
|
||||
{
|
||||
path: '/',
|
||||
component: () => import('@/components/AppLayout.vue'),
|
||||
meta: { requiresAuth: true },
|
||||
children: [
|
||||
{ path: '', component: () => import('@/views/Feed.vue') },
|
||||
{ path: 'article/:id', component: () => import('@/views/ArticleDetail.vue') },
|
||||
{ path: 'sources', component: () => import('@/views/Sources.vue') },
|
||||
{ path: 'bookmarks', component: () => import('@/views/Bookmarks.vue') },
|
||||
{ path: 'admin/sources', component: () => import('@/views/AdminSources.vue'), meta: { ownerOnly: true } },
|
||||
],
|
||||
},
|
||||
]
|
||||
|
||||
const router = createRouter({
|
||||
history: createWebHistory(),
|
||||
routes,
|
||||
})
|
||||
|
||||
router.beforeEach((to) => {
|
||||
const auth = useAuthStore()
|
||||
auth.restore()
|
||||
if (to.meta.requiresAuth && !auth.isLogged) {
|
||||
return { path: '/login', query: { next: to.fullPath } }
|
||||
}
|
||||
if (to.meta.ownerOnly && !auth.isOwner) {
|
||||
return { path: '/' }
|
||||
}
|
||||
if (to.path === '/login' && auth.isLogged) {
|
||||
return { path: '/' }
|
||||
}
|
||||
})
|
||||
|
||||
export default router
|
||||
Reference in New Issue
Block a user