From c530c3b126f7ec0594ac21e965af17097d8de379 Mon Sep 17 00:00:00 2001 From: Megghy Date: Fri, 15 Dec 2023 16:29:08 +0800 Subject: [PATCH] update url, improve queue and songrequest --- src/api/account.ts | 34 ++++++-- src/api/api-models.ts | 29 ++++++- src/api/user.ts | 4 +- src/components/RegisterAndLogin.vue | 4 +- src/components/SongList.vue | 4 +- src/components/SongPlayer.vue | 2 +- src/data/DanmakuClient.ts | 4 +- src/data/constants.ts | 32 ++++---- src/data/notifactions.ts | 2 +- src/main.ts | 3 +- src/views/ChangePasswordView.vue | 2 +- src/views/FeedbackManage.vue | 43 ++++++++-- src/views/ManageLayout.vue | 2 +- src/views/VerifyView.vue | 2 +- src/views/VideoCollectListView.vue | 2 +- src/views/VideoCollectPublic.vue | 4 +- src/views/manage/BiliVerifyView.vue | 4 +- src/views/manage/DashboardView.vue | 14 ++-- src/views/manage/HistoryView.vue | 6 +- src/views/manage/LiveDetailManage.vue | 2 +- src/views/manage/LiveManager.vue | 2 +- src/views/manage/QuestionBoxManageView.vue | 16 ++-- src/views/manage/ScheduleManageView.vue | 8 +- src/views/manage/SettingsManageView.vue | 77 +++++++++++++++--- src/views/manage/SongListManageView.vue | 4 +- src/views/manage/VideoCollectDetailView.vue | 10 +-- src/views/manage/VideoCollectManageView.vue | 4 +- src/views/obs/LiveLotteryOBS.vue | 2 +- src/views/obs/QueueOBS.vue | 25 ++++-- src/views/obs/SongRequestOBS.vue | 21 ++++- src/views/open_live/MusicRequest.vue | 88 +++++++++++++++++---- src/views/open_live/OpenLottery.vue | 4 +- src/views/open_live/OpenQueue.vue | 82 +++++++++++++++---- src/views/view/QuestionBoxView.vue | 2 +- src/views/view/ScheduleView.vue | 2 +- src/views/view/SongListView.vue | 6 +- 36 files changed, 411 insertions(+), 141 deletions(-) diff --git a/src/api/account.ts b/src/api/account.ts index 04e385e..b3d256e 100644 --- a/src/api/account.ts +++ b/src/api/account.ts @@ -1,6 +1,6 @@ import { ACCOUNT_API_URL, BASE_API } from '@/data/constants' import { APIRoot, AccountInfo, FunctionTypes } from './api-models' -import { QueryPostAPI } from '@/api/query' +import { QueryGetAPI, QueryPostAPI } from '@/api/query' import { ref } from 'vue' import { useLocalStorage } from '@vueuse/core' import { createDiscreteApi } from 'naive-ui' @@ -19,7 +19,7 @@ export async function GetSelfAccount() { if (result.code == 200) { ACCOUNT.value = result.data isLoadingAccount.value = false - console.log('[vtsuru] 已获取账户信息') + //console.log('[vtsuru] 已获取账户信息') if (!isSameDay(new Date(), cookieRefreshDate.value)) { refreshCookie() } @@ -38,8 +38,15 @@ export async function GetSelfAccount() { } isLoadingAccount.value = false } +export function UpdateAccountLoop() { + setInterval(() => { + if (ACCOUNT.value) { + GetSelfAccount() + } + }, 60 * 1000) +} function refreshCookie() { - QueryPostAPI(`${ACCOUNT_API_URL()}refresh-token`).then((data) => { + QueryPostAPI(`${ACCOUNT_API_URL}refresh-token`).then((data) => { if (data.code == 200) { cookie.value = data.data cookieRefreshDate.value = Date.now() @@ -48,17 +55,17 @@ function refreshCookie() { }) } export async function SaveAccountSettings() { - return await QueryPostAPI(ACCOUNT_API_URL() + 'update-setting', ACCOUNT.value?.settings) + return await QueryPostAPI(ACCOUNT_API_URL + 'update-setting', ACCOUNT.value?.settings) } export async function SaveEnableFunctions(functions: FunctionTypes[]) { - return await QueryPostAPI(ACCOUNT_API_URL() + 'update-enable-functions', functions) + return await QueryPostAPI(ACCOUNT_API_URL + 'update-enable-functions', functions) } export function useAccount() { return ACCOUNT } export async function Register(name: string, email: string, password: string, token: string): Promise> { - return QueryPostAPI(`${ACCOUNT_API_URL()}register`, { + return QueryPostAPI(`${ACCOUNT_API_URL}register`, { name, email, password, @@ -67,11 +74,22 @@ export async function Register(name: string, email: string, password: string, to } export async function Login(nameOrEmail: string, password: string): Promise> { - return QueryPostAPI(`${ACCOUNT_API_URL()}login`, { + return QueryPostAPI(`${ACCOUNT_API_URL}login`, { nameOrEmail, password, }) } export async function Self(): Promise> { - return QueryPostAPI(`${ACCOUNT_API_URL()}self`) + return QueryPostAPI(`${ACCOUNT_API_URL}self`) +} +export async function AddBiliBlackList(id: number, name: string): Promise> { + return QueryGetAPI(`${ACCOUNT_API_URL}black-list/add-bili`, { + id: id, + name: name, + }) +} +export async function DelBiliBlackList(id: number): Promise> { + return QueryGetAPI(`${ACCOUNT_API_URL}black-list/del-bili`, { + id: id, + }) } diff --git a/src/api/api-models.ts b/src/api/api-models.ts index 0dc47f2..261d935 100644 --- a/src/api/api-models.ts +++ b/src/api/api-models.ts @@ -44,7 +44,28 @@ export interface AccountInfo extends UserInfo { eventFetcherStatus: string nextSendEmailTime?: number - isServerFetcherOnline:boolean + isServerFetcherOnline: boolean + blackList: number[] + biliBlackList: { [key: number]: string } + streamerInfo?: StreamerModel +} +export interface StreamerModel{ + name: string; + uId: number; + roomId: number; + faceUrl: string; + title: string; + coverUrl: string; + frameUrl: string; + area: string; + parentArea: string; + lastStreamAt: number; + totalDanmakuCount: number; + totalIncome: number; + totalStreamCount: number; + totalStreamTime: number; + lastDanmakuCount: number; + isStreaming: boolean; } export enum BiliAuthCodeStatusType { NotBind, @@ -72,6 +93,7 @@ export interface UserSetting { } export interface Setting_SongRequest { orderPrefix: string + enableOnStreaming: boolean onlyAllowSongList: boolean queueMaxSize: number allowAllDanmaku: boolean @@ -90,9 +112,12 @@ export interface Setting_SongRequest { zongduCooldownSecond: number tiduCooldownSecond: number jianzhangCooldownSecond: number + + showRequireInfo: boolean } export interface Setting_Queue { keyword: string + enableOnStreaming: boolean matchType: KeywordMatchType sortType?: QueueSortType queueMaxSize: number @@ -116,6 +141,8 @@ export interface Setting_Queue { zongduCooldownSecond: number tiduCooldownSecond: number jianzhangCooldownSecond: number + + showRequireInfo: boolean } export enum KeywordMatchType { diff --git a/src/api/user.ts b/src/api/user.ts index f34e338..9c48771 100644 --- a/src/api/user.ts +++ b/src/api/user.ts @@ -30,7 +30,7 @@ export async function useUser(id: string | undefined = undefined) { } export async function useUserWithUId(id: number) { if (!USERS.value[id.toString()]) { - const result = await QueryGetAPI(`${USER_API_URL()}info`, { + const result = await QueryGetAPI(`${USER_API_URL}info`, { uId: id, }) if (result.code == 200) { @@ -41,7 +41,7 @@ export async function useUserWithUId(id: number) { } export async function GetInfo(id: string): Promise> { - return QueryGetAPI(`${USER_API_URL()}info`, { + return QueryGetAPI(`${USER_API_URL}info`, { id: id, }) } diff --git a/src/components/RegisterAndLogin.vue b/src/components/RegisterAndLogin.vue index 9151acb..ca08f10 100644 --- a/src/components/RegisterAndLogin.vue +++ b/src/components/RegisterAndLogin.vue @@ -155,7 +155,7 @@ function onLoginButtonClick() { await QueryPostAPI<{ account: AccountInfo token: string - }>(ACCOUNT_API_URL() + 'login', { + }>(ACCOUNT_API_URL + 'login', { nameOrEmail: loginModel.value.account, password: loginModel.value.password, }) @@ -180,7 +180,7 @@ function onLoginButtonClick() { } async function onForgetPassword() { canSendForgetPassword.value = false - await QueryGetAPI(ACCOUNT_API_URL() + 'reset-password', { email: inputForgetPasswordValue.value }, [['Turnstile', token.value]]) + await QueryGetAPI(ACCOUNT_API_URL + 'reset-password', { email: inputForgetPasswordValue.value }, [['Turnstile', token.value]]) .then(async (data) => { if (data.code == 200) { message.success('已发送密码重置链接到你的邮箱, 请检查') diff --git a/src/components/SongList.vue b/src/components/SongList.vue index d0a4c78..542ad84 100644 --- a/src/components/SongList.vue +++ b/src/components/SongList.vue @@ -393,7 +393,7 @@ function renderCell(value: string | number) { } async function updateSong() { - await QueryPostAPI(SONG_API_URL() + 'update', { + await QueryPostAPI(SONG_API_URL + 'update', { key: updateSongModel.value.key, song: updateSongModel.value, }).then((data) => { @@ -407,7 +407,7 @@ async function updateSong() { }) } async function delSong(song: SongsInfo) { - await QueryGetAPI(SONG_API_URL() + 'del', { + await QueryGetAPI(SONG_API_URL + 'del', { key: song.key, }).then((data) => { if (data.code == 200) { diff --git a/src/components/SongPlayer.vue b/src/components/SongPlayer.vue index 00fc60d..b6f6982 100644 --- a/src/components/SongPlayer.vue +++ b/src/components/SongPlayer.vue @@ -43,7 +43,7 @@ function OnPlayMusic(song: SongsInfo) { } async function GetLyric(song: SongsInfo) { emits('update:isLrcLoading', song.key) - QueryGetAPI<{ lyric: string; tlyric: string }>(SONG_API_URL() + 'get-netease-lyric', { id: song.id }) + QueryGetAPI<{ lyric: string; tlyric: string }>(SONG_API_URL + 'get-netease-lyric', { id: song.id }) .then((data) => { console.log(mergeLyrics(data.data.lyric, data.data.tlyric)) if (data.code == 200) { diff --git a/src/data/DanmakuClient.ts b/src/data/DanmakuClient.ts index 1bb4b49..39d0ee8 100644 --- a/src/data/DanmakuClient.ts +++ b/src/data/DanmakuClient.ts @@ -197,7 +197,7 @@ export default class DanmakuClient { } private sendHeartbeat() { if (this.client) { - const query = this.authInfo ? QueryPostAPI(OPEN_LIVE_API_URL() + 'heartbeat', this.authInfo) : QueryGetAPI(OPEN_LIVE_API_URL() + 'heartbeat-internal') + const query = this.authInfo ? QueryPostAPI(OPEN_LIVE_API_URL + 'heartbeat', this.authInfo) : QueryGetAPI(OPEN_LIVE_API_URL + 'heartbeat-internal') query.then((data) => { if (data.code != 200) { console.error('[OPEN-LIVE] 心跳失败') @@ -267,7 +267,7 @@ export default class DanmakuClient { } private async getAuthInfo(): Promise<{ data: OpenLiveInfo | null; message: string }> { try { - const data = await QueryPostAPI(OPEN_LIVE_API_URL() + 'start', this.authInfo?.Code ? this.authInfo : undefined) + const data = await QueryPostAPI(OPEN_LIVE_API_URL + 'start', this.authInfo?.Code ? this.authInfo : undefined) if (data.code == 200) { console.log('[OPEN-LIVE] 已获取场次信息') return { diff --git a/src/data/constants.ts b/src/data/constants.ts index 786cf6b..bb93674 100644 --- a/src/data/constants.ts +++ b/src/data/constants.ts @@ -14,22 +14,22 @@ export const FETCH_API = 'https://fetch.vtsuru.live/' export const TURNSTILE_KEY = '0x4AAAAAAAETUSAKbds019h0' -export const USER_API_URL = () => `${BASE_API()}user/` -export const ACCOUNT_API_URL = () => `${BASE_API()}account/` -export const BILI_API_URL = () => `${BASE_API()}bili/` -export const SONG_API_URL = () => `${BASE_API()}song-list/` -export const NOTIFACTION_API_URL = () => `${BASE_API()}notifaction/` -export const QUESTION_API_URL = () => `${BASE_API()}qa/` -export const LOTTERY_API_URL = () => `${BASE_API()}lottery/` -export const HISTORY_API_URL = () => `${BASE_API()}history/` -export const SCHEDULE_API_URL = () => `${BASE_API()}schedule/` -export const VIDEO_COLLECT_API_URL = () => `${BASE_API()}video-collect/` -export const OPEN_LIVE_API_URL = () => `${BASE_API()}open-live/` -export const SONG_REQUEST_API_URL = () => `${BASE_API()}song-request/` -export const QUEUE_API_URL = () => `${BASE_API()}queue/` -export const EVENT_API_URL = () => `${BASE_API()}event/` -export const LIVE_API_URL = () => `${BASE_API()}live/` -export const FEEDBACK_API_URL = () => `${BASE_API()}feedback/` +export const USER_API_URL = { toString: () => `${BASE_API()}user/` } +export const ACCOUNT_API_URL = { toString: () => `${BASE_API()}account/` } +export const BILI_API_URL = { toString: () => `${BASE_API()}bili/` } +export const SONG_API_URL = { toString: () => `${BASE_API()}song-list/` } +export const NOTIFACTION_API_URL = { toString: () => `${BASE_API()}notifaction/` } +export const QUESTION_API_URL = { toString: () => `${BASE_API()}qa/` } +export const LOTTERY_API_URL = { toString: () => `${BASE_API()}lottery/` } +export const HISTORY_API_URL = { toString: () => `${BASE_API()}history/` } +export const SCHEDULE_API_URL = { toString: () => `${BASE_API()}schedule/` } +export const VIDEO_COLLECT_API_URL = { toString: () => `${BASE_API()}video-collect/` } +export const OPEN_LIVE_API_URL = { toString: () => `${BASE_API()}open-live/` } +export const SONG_REQUEST_API_URL = { toString: () => `${BASE_API()}song-request/` } +export const QUEUE_API_URL = { toString: () => `${BASE_API()}queue/` } +export const EVENT_API_URL = { toString: () => `${BASE_API()}event/` } +export const LIVE_API_URL = { toString: () => `${BASE_API()}live/` } +export const FEEDBACK_API_URL = { toString: () => `${BASE_API()}feedback/` } export const ScheduleTemplateMap = { '': { name: '默认', compoent: defineAsyncComponent(() => import('@/views/view/scheduleTemplate/DefaultScheduleTemplate.vue')) }, diff --git a/src/data/notifactions.ts b/src/data/notifactions.ts index 58808c9..21eba69 100644 --- a/src/data/notifactions.ts +++ b/src/data/notifactions.ts @@ -10,7 +10,7 @@ const n = ref() let isLoading = false function get() { if (isLoading) return - QueryGetAPI(SONG_REQUEST_API_URL() + 'get-active') + QueryGetAPI(SONG_REQUEST_API_URL + 'get-active') .then((data) => { if (data.code == 200) { n.value = data.data diff --git a/src/main.ts b/src/main.ts index 3383fd0..ff08578 100644 --- a/src/main.ts +++ b/src/main.ts @@ -3,7 +3,7 @@ import { BASE_API, apiFail } from '@/data/constants' import { createApp, h } from 'vue' import App from './App.vue' import router from './router' -import { GetSelfAccount } from './api/account' +import { GetSelfAccount, UpdateAccountLoop } from './api/account' import { GetNotifactions } from './data/notifactions' import { NText, createDiscreteApi } from 'naive-ui' @@ -38,4 +38,5 @@ QueryGetAPI(BASE_API() + 'vtsuru/version') //加载其他数据 GetSelfAccount() GetNotifactions() + UpdateAccountLoop() }) diff --git a/src/views/ChangePasswordView.vue b/src/views/ChangePasswordView.vue index 8b2aefc..c51e42e 100644 --- a/src/views/ChangePasswordView.vue +++ b/src/views/ChangePasswordView.vue @@ -21,7 +21,7 @@ function changePassword() { return } isLoading.value = true - QueryGetAPI(ACCOUNT_API_URL() + 'verify/reset-password', { + QueryGetAPI(ACCOUNT_API_URL + 'verify/reset-password', { key: key.value, password: password.value, }) diff --git a/src/views/FeedbackManage.vue b/src/views/FeedbackManage.vue index 1229c59..a9dea2b 100644 --- a/src/views/FeedbackManage.vue +++ b/src/views/FeedbackManage.vue @@ -4,7 +4,28 @@ import { FeedbackStatus, FeedbackType, ResponseFeedbackModel } from '@/api/api-m import { QueryGetAPI, QueryPostAPI } from '@/api/query' import { FEEDBACK_API_URL } from '@/data/constants' import { List } from 'linqts' -import { NButton, NCard, NCheckbox, NDivider, NEllipsis, NEmpty, NForm, NGrid, NGridItem, NInput, NModal, NRadioButton, NRadioGroup, NSpace, NSpin, NTag, NText, NTooltip, useMessage } from 'naive-ui' +import { + NButton, + NCard, + NCheckbox, + NDivider, + NEllipsis, + NEmpty, + NForm, + NGrid, + NGridItem, + NInput, + NModal, + NRadioButton, + NRadioGroup, + NSpace, + NSpin, + NTag, + NText, + NTime, + NTooltip, + useMessage, +} from 'naive-ui' import { computed, ref } from 'vue' interface FeedbackModel { @@ -43,7 +64,7 @@ const newFeedback = ref({ async function get() { try { - const data = await QueryGetAPI(FEEDBACK_API_URL() + 'get') + const data = await QueryGetAPI(FEEDBACK_API_URL + 'get') if (data.code == 200) { return new List(data.data).OrderByDescending((s) => s.createAt).ToArray() } else { @@ -60,7 +81,7 @@ async function add() { message.error('反馈内容不能为空') return } - await QueryPostAPI(FEEDBACK_API_URL() + 'add', newFeedback.value) + await QueryPostAPI(FEEDBACK_API_URL + 'add', newFeedback.value) .then((data) => { if (data.code == 200) { message.success('发送成功, 感谢你的反馈!') @@ -78,8 +99,11 @@ async function add() {