fix: setup 迁移完成

This commit is contained in:
Tim
2025-08-13 17:59:38 +08:00
parent 0034839e8d
commit 902fce5174
11 changed files with 769 additions and 853 deletions

View File

@@ -1,4 +1,3 @@
import { API_BASE_URL } from '~/main'
import { reactive } from 'vue'
const TOKEN_KEY = 'token'
@@ -65,6 +64,8 @@ export function clearUserInfo() {
}
export async function fetchCurrentUser() {
const config = useRuntimeConfig()
const API_BASE_URL = config.public.apiBaseUrl
const token = getToken()
if (!token) return null
try {
@@ -91,6 +92,8 @@ export function isLogin() {
}
export async function checkToken() {
const config = useRuntimeConfig()
const API_BASE_URL = config.public.apiBaseUrl
const token = getToken()
if (!token) return false
try {

View File

@@ -1,4 +1,4 @@
import { API_BASE_URL, DISCORD_CLIENT_ID, toast } from '../main'
import { DISCORD_CLIENT_ID, toast } from '../main'
import { WEBSITE_BASE_URL } from '../constants'
import { setToken, loadCurrentUser } from './auth'
import { registerPush } from './push'
@@ -15,6 +15,8 @@ export function discordAuthorize(state = '') {
export async function discordExchange(code, state, reason) {
try {
const config = useRuntimeConfig()
const API_BASE_URL = config.public.apiBaseUrl
const res = await fetch(`${API_BASE_URL}/api/auth/discord`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },

View File

@@ -1,4 +1,4 @@
import { API_BASE_URL, GITHUB_CLIENT_ID, toast } from '../main'
import { GITHUB_CLIENT_ID, toast } from '../main'
import { setToken, loadCurrentUser } from './auth'
import { WEBSITE_BASE_URL } from '../constants'
import { registerPush } from './push'
@@ -15,6 +15,8 @@ export function githubAuthorize(state = '') {
export async function githubExchange(code, state, reason) {
try {
const config = useRuntimeConfig()
const API_BASE_URL = config.public.apiBaseUrl
const res = await fetch(`${API_BASE_URL}/api/auth/github`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },

View File

@@ -1,4 +1,4 @@
import { API_BASE_URL, GOOGLE_CLIENT_ID, toast } from '../main'
import { GOOGLE_CLIENT_ID, toast } from '../main'
import { setToken, loadCurrentUser } from './auth'
import { registerPush } from './push'
import { WEBSITE_BASE_URL } from '../constants'
@@ -32,6 +32,8 @@ export function googleAuthorize() {
export async function googleAuthWithToken(idToken, redirect_success, redirect_not_approved) {
try {
const config = useRuntimeConfig()
const API_BASE_URL = config.public.apiBaseUrl
const res = await fetch(`${API_BASE_URL}/api/auth/google`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },

View File

@@ -1,4 +1,3 @@
import { API_BASE_URL } from '~/main'
import { getToken } from './auth'
import { reactive } from 'vue'
@@ -7,6 +6,8 @@ export const notificationState = reactive({
})
export async function fetchUnreadCount() {
const config = useRuntimeConfig()
const API_BASE_URL = config.public.apiBaseUrl
try {
const token = getToken()
if (!token) {
@@ -31,6 +32,9 @@ export async function fetchUnreadCount() {
export async function markNotificationsRead(ids) {
try {
const config = useRuntimeConfig()
const API_BASE_URL = config.public.apiBaseUrl
const token = getToken()
if (!token || !ids || ids.length === 0) return false
const res = await fetch(`${API_BASE_URL}/api/notifications/read`, {
@@ -49,6 +53,9 @@ export async function markNotificationsRead(ids) {
export async function fetchNotificationPreferences() {
try {
const config = useRuntimeConfig()
const API_BASE_URL = config.public.apiBaseUrl
const token = getToken()
if (!token) return []
const res = await fetch(`${API_BASE_URL}/api/notifications/prefs`, {
@@ -63,6 +70,8 @@ export async function fetchNotificationPreferences() {
export async function updateNotificationPreference(type, enabled) {
try {
const config = useRuntimeConfig()
const API_BASE_URL = config.public.apiBaseUrl
const token = getToken()
if (!token) return false
const res = await fetch(`${API_BASE_URL}/api/notifications/prefs`, {

View File

@@ -1,4 +1,3 @@
import { API_BASE_URL } from '../main'
import { getToken } from './auth'
function urlBase64ToUint8Array(base64String) {
@@ -21,6 +20,8 @@ function arrayBufferToBase64(buffer) {
export async function registerPush() {
if (!('serviceWorker' in navigator) || !('PushManager' in window)) return
const config = useRuntimeConfig()
const API_BASE_URL = config.public.apiBaseUrl
try {
const reg = await navigator.serviceWorker.register('/notifications-sw.js')
const res = await fetch(`${API_BASE_URL}/api/push/public-key`)

View File

@@ -1,4 +1,4 @@
import { API_BASE_URL, TWITTER_CLIENT_ID, toast } from '../main'
import { TWITTER_CLIENT_ID, toast } from '../main'
import { WEBSITE_BASE_URL } from '../constants'
import { setToken, loadCurrentUser } from './auth'
import { registerPush } from './push'
@@ -42,6 +42,8 @@ export async function twitterAuthorize(state = '') {
export async function twitterExchange(code, state, reason) {
try {
const config = useRuntimeConfig()
const API_BASE_URL = config.public.apiBaseUrl
const codeVerifier = sessionStorage.getItem('twitter_code_verifier')
sessionStorage.removeItem('twitter_code_verifier')
const res = await fetch(`${API_BASE_URL}/api/auth/twitter`, {

View File

@@ -1,7 +1,7 @@
import { API_BASE_URL } from '../main'
export async function fetchFollowings(username) {
if (!username) return []
const config = useRuntimeConfig()
const API_BASE_URL = config.public.apiBaseUrl
try {
const res = await fetch(`${API_BASE_URL}/api/users/${username}/following`)
return res.ok ? await res.json() : []
@@ -11,6 +11,8 @@ export async function fetchFollowings(username) {
}
export async function fetchAdmins() {
const config = useRuntimeConfig()
const API_BASE_URL = config.public.apiBaseUrl
try {
const res = await fetch(`${API_BASE_URL}/api/users/admins`)
return res.ok ? await res.json() : []
@@ -21,6 +23,8 @@ export async function fetchAdmins() {
export async function searchUsers(keyword) {
if (!keyword) return []
const config = useRuntimeConfig()
const API_BASE_URL = config.public.apiBaseUrl
try {
const res = await fetch(
`${API_BASE_URL}/api/search/users?keyword=${encodeURIComponent(keyword)}`,

View File

@@ -1,5 +1,4 @@
import Vditor from 'vditor'
import { API_BASE_URL } from '../main'
import { getToken, authState } from './auth'
import { searchUsers, fetchFollowings, fetchAdmins } from './user'
import { tiebaEmoji } from './tiebaEmoji'
@@ -14,6 +13,8 @@ export function getPreviewTheme() {
export function createVditor(editorId, options = {}) {
const { placeholder = '', preview = {}, input, after } = options
const config = useRuntimeConfig()
const API_BASE_URL = config.public.apiBaseUrl
const fetchMentions = async (value) => {
if (!value) {