From 569cd087e77d4099b0219462cab878b3c90c35fe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=90=B3=E5=85=83=E7=9A=93?= Date: Wed, 7 May 2025 10:53:14 +0800 Subject: [PATCH] Clean the awful code. --- README.md | 5 +- app.vue | 2 +- components/navigation.vue | 91 +++++++++++++------------- createDatabase.ts | 7 +- layouts/admin.vue | 3 +- pages/admin/login.vue | 16 ++--- pages/dailybriefing.vue | 4 +- pages/home.vue | 77 +++++++++++++--------- pages/newsOrgAbout/[slug].vue | 36 +++++----- pages/newsOrgs.vue | 4 +- pages/system/login.vue | 54 ++++++++------- server/api/auth/callback/github.get.ts | 9 +-- server/api/auth/github.get.ts | 26 ++++---- server/api/getData/fetchSidebarData.ts | 14 ++-- styles/main.css | 12 ++-- 15 files changed, 193 insertions(+), 167 deletions(-) diff --git a/README.md b/README.md index 54d612b..d4adb3c 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,7 @@ # 新聞解析 / News Analyze -## Stack: +## Stack: + - Postgres - Passport.js - Tailwind @@ -10,4 +11,4 @@ - Zeabur - Minio S3 - Nuxt i18N -- BunJS \ No newline at end of file +- BunJS diff --git a/app.vue b/app.vue index b42a5b7..12c1703 100644 --- a/app.vue +++ b/app.vue @@ -2,7 +2,7 @@ import "bootstrap-icons/font/bootstrap-icons.css"; import "animate.css"; import "@fontsource/fira-sans"; -import '@fontsource-variable/noto-sans-tc'; +import "@fontsource-variable/noto-sans-tc"; const { t } = useI18n(); diff --git a/pages/newsOrgAbout/[slug].vue b/pages/newsOrgAbout/[slug].vue index 895c8c4..896b9ab 100644 --- a/pages/newsOrgAbout/[slug].vue +++ b/pages/newsOrgAbout/[slug].vue @@ -33,12 +33,12 @@ const { } = useFetch("/api/getData/fetchSidebarData", { method: "POST", headers: { - "Content-Type": "application/json" + "Content-Type": "application/json", }, body: { lang: locale, - } -}) + }, +}); watchEffect(() => { loading.value = pending.value; @@ -90,25 +90,31 @@ import { GlobeAltIcon } from "@heroicons/vue/24/outline"; > -
+

其他媒體

-
+
-

{{ data.title }}

- - ( - {{ data.lean }} - - - 文章分數: - {{ data.score }} - ) - +

{{ data.title }}

+ + ( + {{ data.lean }} + - + 文章分數: + {{ data.score }} + + ) +
- diff --git a/pages/newsOrgs.vue b/pages/newsOrgs.vue index 27e0f69..cc340bc 100644 --- a/pages/newsOrgs.vue +++ b/pages/newsOrgs.vue @@ -1,3 +1 @@ - \ No newline at end of file + diff --git a/pages/system/login.vue b/pages/system/login.vue index c079c0c..752307b 100644 --- a/pages/system/login.vue +++ b/pages/system/login.vue @@ -1,25 +1,33 @@ \ No newline at end of file +
+ diff --git a/server/api/auth/callback/github.get.ts b/server/api/auth/callback/github.get.ts index f473ee2..1fe33df 100644 --- a/server/api/auth/callback/github.get.ts +++ b/server/api/auth/callback/github.get.ts @@ -1,8 +1,5 @@ -export default defineEventHandler(async (event) => { - -}) +export default defineEventHandler(async (event) => {}); async function findUser(githubUser: any) { - console.log("Github User: " + githubUser); - -} \ No newline at end of file + console.log("Github User: " + githubUser); +} diff --git a/server/api/auth/github.get.ts b/server/api/auth/github.get.ts index 5efbefa..60f0ab3 100644 --- a/server/api/auth/github.get.ts +++ b/server/api/auth/github.get.ts @@ -1,16 +1,16 @@ -import crypto from "node:crypto" +import crypto from "node:crypto"; export default defineEventHandler(async (event) => { - const baseUrl = event.node.req.headers.host - const protocol = process.env.NODE_ENV === "production" ? "https": "http" - const clientId = process.env.NUXT_GITHUB_CLIENT_ID; - const callbackUrl = `${protocol}://${baseUrl}/api/auth/github/callback`; - const state = crypto.randomBytes(16).toString("hex"); - setCookie(event, 'oauth_state', state, { + const baseUrl = event.node.req.headers.host; + const protocol = process.env.NODE_ENV === "production" ? "https" : "http"; + const clientId = process.env.NUXT_GITHUB_CLIENT_ID; + const callbackUrl = `${protocol}://${baseUrl}/api/auth/github/callback`; + const state = crypto.randomBytes(16).toString("hex"); + setCookie(event, "oauth_state", state, { httpOnly: true, - secure: process.env.NODE_ENV === 'production', + secure: process.env.NODE_ENV === "production", maxAge: 60 * 10, - path: '/', - }) - const authorizationUrl = `https://github.com/login/oauth/authorize?client_id=${clientId}&redirect_uri=${encodeURIComponent(callbackUrl)}&scope=read:user,user:email&state=${state}` - await sendRedirect(event, authorizationUrl, 302) -}) \ No newline at end of file + path: "/", + }); + const authorizationUrl = `https://github.com/login/oauth/authorize?client_id=${clientId}&redirect_uri=${encodeURIComponent(callbackUrl)}&scope=read:user,user:email&state=${state}`; + await sendRedirect(event, authorizationUrl, 302); +}); diff --git a/server/api/getData/fetchSidebarData.ts b/server/api/getData/fetchSidebarData.ts index 62f1116..938b6c7 100644 --- a/server/api/getData/fetchSidebarData.ts +++ b/server/api/getData/fetchSidebarData.ts @@ -2,12 +2,12 @@ export default defineEventHandler(async (event) => { const body = await readBody(event); return { 0: { - id: "1", - image: "whatever", - tags: [], - title: "三立新聞", - lean: "left", - score: "40" - } + id: "1", + image: "whatever", + tags: [], + title: "三立新聞", + lean: "left", + score: "40", + }, }; }); diff --git a/styles/main.css b/styles/main.css index 7b0efeb..bf53037 100644 --- a/styles/main.css +++ b/styles/main.css @@ -9,15 +9,17 @@ body { @apply bg-black m-0 p-0 min-h-screen text-white; } - html,body { - font-family: 'Noto Sans TC Variable', "Fira Sans", sans-serif; + html, + body { + font-family: "Noto Sans TC Variable", "Fira Sans", sans-serif; } } @font-face { - font-family: 'Noto Sans TC Variable'; + font-family: "Noto Sans TC Variable"; font-style: normal; font-display: auto; font-weight: 100 900; - src: url(@fontsource-variable/noto-sans-tc/files/noto-sans-tc-chinese-traditional-wght-normal.woff2) format('woff2-variations'); -} \ No newline at end of file + src: url(@fontsource-variable/noto-sans-tc/files/noto-sans-tc-chinese-traditional-wght-normal.woff2) + format("woff2-variations"); +}