update url, improve queue and songrequest

This commit is contained in:
2023-12-15 16:29:08 +08:00
parent 82a0e72122
commit c530c3b126
36 changed files with 411 additions and 141 deletions

View File

@@ -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<string>(`${ACCOUNT_API_URL()}refresh-token`).then((data) => {
QueryPostAPI<string>(`${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<APIRoot<string>> {
return QueryPostAPI<string>(`${ACCOUNT_API_URL()}register`, {
return QueryPostAPI<string>(`${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<APIRoot<string>> {
return QueryPostAPI<string>(`${ACCOUNT_API_URL()}login`, {
return QueryPostAPI<string>(`${ACCOUNT_API_URL}login`, {
nameOrEmail,
password,
})
}
export async function Self(): Promise<APIRoot<AccountInfo>> {
return QueryPostAPI<AccountInfo>(`${ACCOUNT_API_URL()}self`)
return QueryPostAPI<AccountInfo>(`${ACCOUNT_API_URL}self`)
}
export async function AddBiliBlackList(id: number, name: string): Promise<APIRoot<unknown>> {
return QueryGetAPI<AccountInfo>(`${ACCOUNT_API_URL}black-list/add-bili`, {
id: id,
name: name,
})
}
export async function DelBiliBlackList(id: number): Promise<APIRoot<unknown>> {
return QueryGetAPI<AccountInfo>(`${ACCOUNT_API_URL}black-list/del-bili`, {
id: id,
})
}

View File

@@ -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 {

View File

@@ -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<UserInfo>(`${USER_API_URL()}info`, {
const result = await QueryGetAPI<UserInfo>(`${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<APIRoot<UserInfo>> {
return QueryGetAPI<UserInfo>(`${USER_API_URL()}info`, {
return QueryGetAPI<UserInfo>(`${USER_API_URL}info`, {
id: id,
})
}