Fix cheese url (fix #4484)

This commit is contained in:
the1812 2023-11-16 23:19:58 +08:00
parent 59e61330b7
commit 3b55128e71
2 changed files with 44 additions and 15 deletions

View File

@ -106,7 +106,7 @@
</template> </template>
<script lang="ts"> <script lang="ts">
import { bilibiliApi, getJsonWithCredentials, postTextWithCredentials } from '@/core/ajax' import { bilibiliApi, getJsonWithCredentials, postTextWithCredentials } from '@/core/ajax'
import { formData, getCsrf } from '@/core/utils' import { getCsrf } from '@/core/utils'
import { descendingSort } from '@/core/utils/sort' import { descendingSort } from '@/core/utils/sort'
import { import {
VButton, VButton,
@ -119,7 +119,14 @@ import {
DpiImage, DpiImage,
} from '@/ui' } from '@/ui'
import { popperMixin } from '../mixins' import { popperMixin } from '../mixins'
import { types, TypeFilter, HistoryItem, getHistoryItems, group, HistoryType } from './types' import {
navbarFilterTypes,
TypeFilter,
HistoryItem,
getHistoryItems,
group,
HistoryType,
} from './types'
export default Vue.extend({ export default Vue.extend({
components: { components: {
@ -135,7 +142,7 @@ export default Vue.extend({
mixins: [popperMixin], mixins: [popperMixin],
data() { data() {
return { return {
types, types: navbarFilterTypes,
search: '', search: '',
viewTime: 0, viewTime: 0,
cards: [], cards: [],
@ -164,10 +171,11 @@ export default Vue.extend({
}, },
methods: { methods: {
toggleTypeFilter(typeFilter: TypeFilter) { toggleTypeFilter(typeFilter: TypeFilter) {
types.forEach(t => (t.checked = t.name === typeFilter.name)) navbarFilterTypes.forEach(t => (t.checked = t.name === typeFilter.name))
this.reloadHistoryItems() this.reloadHistoryItems()
}, },
async reloadHistoryItems() { async reloadHistoryItems() {
this.cards = []
this.viewTime = 0 this.viewTime = 0
this.hasMorePage = true this.hasMorePage = true
this.loading = true this.loading = true
@ -178,8 +186,8 @@ export default Vue.extend({
} }
}, },
filterFunc(item: HistoryItem) { filterFunc(item: HistoryItem) {
const isAllType = types.find(it => it.name === HistoryType.All).checked const isAllType = navbarFilterTypes.find(it => it.name === HistoryType.All).checked
if (!isAllType && types.some(t => t.name === item.type && !t.checked)) { if (!isAllType && navbarFilterTypes.some(t => t.name === item.type && !t.checked)) {
return false return false
} }
if ( if (
@ -196,7 +204,7 @@ export default Vue.extend({
async nextPage() { async nextPage() {
const items = await getHistoryItems( const items = await getHistoryItems(
this.viewTime, this.viewTime,
types.find(t => t.checked), navbarFilterTypes.find(t => t.checked),
) )
const cards: HistoryItem[] = lodash.uniqBy( const cards: HistoryItem[] = lodash.uniqBy(
this.cards.concat(items).sort(descendingSort((item: HistoryItem) => item.viewAt)), this.cards.concat(items).sort(descendingSort((item: HistoryItem) => item.viewAt)),
@ -228,10 +236,10 @@ export default Vue.extend({
this.paused = targetState this.paused = targetState
await postTextWithCredentials( await postTextWithCredentials(
'https://api.bilibili.com/x/v2/history/shadow/set', 'https://api.bilibili.com/x/v2/history/shadow/set',
formData({ new URLSearchParams({
csrf: getCsrf(), csrf: getCsrf(),
switch: targetState, switch: targetState.toString(),
}), }).toString(),
) )
} catch (error) { } catch (error) {
this.paused = !targetState this.paused = !targetState

View File

@ -9,6 +9,7 @@ export enum HistoryType {
Live = 'live', Live = 'live',
Article = 'article', Article = 'article',
Bangumi = 'pgc', Bangumi = 'pgc',
Cheese = 'cheese',
} }
export interface HistoryItem { export interface HistoryItem {
id: string | number id: string | number
@ -51,8 +52,8 @@ export interface TypeFilter {
checked: boolean checked: boolean
apiType: string apiType: string
} }
/** 所有的历史记录类型 */ /** 顶栏可筛选的历史记录类型 */
export const types = [ export const navbarFilterTypes = [
{ {
name: HistoryType.All, name: HistoryType.All,
displayName: '全部', displayName: '全部',
@ -72,6 +73,7 @@ export const types = [
displayName: '番剧', displayName: '番剧',
icon: 'mdi-television-classic', icon: 'mdi-television-classic',
checked: false, checked: false,
// b 站的历史不区分视频和番剧, 只能混着拿然后过滤
apiType: 'archive', apiType: 'archive',
}, },
{ {
@ -122,14 +124,14 @@ const formatTime = (date: Date) => {
.padStart(2, '0')}` .padStart(2, '0')}`
} }
const parseHistoryItem = (item: any): HistoryItem => { const parseHistoryItem = (item: any): HistoryItem => {
if (item.history.business === 'article') { if (item.history.business === HistoryType.Article) {
item.history.cid = item.history.oid item.history.cid = item.history.oid
} }
const { const {
epid, // 番剧 ep号 epid, // 番剧 ep号
bvid, // 视频 bv号 bvid, // 视频 bv号
cid, // 专栏 cv号 cid, // 专栏 cv号
oid, // 直播 房间号 / 专栏 cv 号 oid, // 直播 房间号 / 专栏 cv 号 / 课程神秘标识符
} = item.history } = item.history
const progressParam = item.progress > 0 ? `t=${item.progress}` : 't=0' const progressParam = item.progress > 0 ? `t=${item.progress}` : 't=0'
const progress = item.progress === -1 ? 1 : item.progress / item.duration const progress = item.progress === -1 ? 1 : item.progress / item.duration
@ -159,6 +161,17 @@ const parseHistoryItem = (item: any): HistoryItem => {
upFaceUrl: https(item.author_face), upFaceUrl: https(item.author_face),
upID: item.author_mid, upID: item.author_mid,
} }
if (item.history.business === HistoryType.Cheese) {
return {
...commonInfo,
id: oid,
upName: item.title,
title: item.show_title,
url: item.uri,
/** 特殊处理: 展示上分类仍归类到视频 */
type: HistoryType.Video,
}
}
if (epid) { if (epid) {
return { return {
...commonInfo, ...commonInfo,
@ -215,7 +228,15 @@ export const getHistoryItems = async (viewTime?: number, type?: TypeFilter) => {
if (!Array.isArray(list)) { if (!Array.isArray(list)) {
return [] return []
} }
return (list as any[]).map(parseHistoryItem) return (list as any[]).map(parseHistoryItem).filter(it => {
if (it === null) {
return false
}
if (type && type.name !== HistoryType.All) {
return it.type === type.name
}
return true
})
} }
/** /**
* , `今天`, `昨天`, `本周`, `更早` * , `今天`, `昨天`, `本周`, `更早`