优化导出

This commit is contained in:
IndieKKY
2024-10-10 09:23:42 +08:00
parent b481b8a55a
commit 5a0a123af9
8 changed files with 76 additions and 12 deletions

View File

@@ -24,6 +24,7 @@
"ahooks": "^3.7.1",
"classnames": "^2.3.2",
"daisyui": "^2.42.1",
"dayjs": "^1.11.13",
"js-search": "^2.0.0",
"less": "^4.1.3",
"lodash-es": "^4.17.21",

13
pnpm-lock.yaml generated
View File

@@ -41,6 +41,9 @@ importers:
daisyui:
specifier: ^2.42.1
version: 2.42.1(autoprefixer@10.4.13(postcss@8.4.19))(postcss@8.4.19)
dayjs:
specifier: ^1.11.13
version: 1.11.13
js-search:
specifier: ^2.0.0
version: 2.0.0
@@ -856,8 +859,8 @@ packages:
autoprefixer: ^10.0.2
postcss: ^8.1.6
dayjs@1.11.5:
resolution: {integrity: sha512-CAdX5Q3YW3Gclyo5Vpqkgpj8fSdLQcRuzfX6mC6Phy0nfJ0eGYOeS7m4mt2plDWLAtA4TqTakvbboHvUxfe4iA==}
dayjs@1.11.13:
resolution: {integrity: sha512-oaMBel6gjolK862uaPQOVTA7q3TZhuSvuMQAAglQDOWYO9A91IrAOUJEyKVlqJlHE0vq5p5UXxzdPfMH/x6xNg==}
debug@2.6.9:
resolution: {integrity: sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA==}
@@ -3114,7 +3117,7 @@ snapshots:
dependencies:
'@types/js-cookie': 2.2.7
ahooks-v3-count: 1.0.0
dayjs: 1.11.5
dayjs: 1.11.13
intersection-observer: 0.12.2
js-cookie: 2.2.1
lodash: 4.17.21
@@ -3126,7 +3129,7 @@ snapshots:
dependencies:
'@types/js-cookie': 2.2.7
ahooks-v3-count: 1.0.0
dayjs: 1.11.5
dayjs: 1.11.13
intersection-observer: 0.12.2
js-cookie: 2.2.1
lodash: 4.17.21
@@ -3385,7 +3388,7 @@ snapshots:
transitivePeerDependencies:
- ts-node
dayjs@1.11.5: {}
dayjs@1.11.13: {}
debug@2.6.9:
dependencies:

View File

@@ -19,6 +19,8 @@ import {downloadText, openUrl} from '@kky002/kky-util'
import toast from 'react-hot-toast'
import {getSummarize} from '../utils/bizUtil'
import { useMessage } from '@/hooks/message'
import dayjs from 'dayjs';
interface Props {
placement: Placement
}
@@ -68,6 +70,8 @@ const MoreBtn = (props: Props) => {
const segments = useAppSelector(state => state.env.segments)
const url = useAppSelector(state => state.env.url)
const title = useAppSelector(state => state.env.title)
const ctime = useAppSelector(state => state.env.ctime) //时间戳单位s
const author = useAppSelector(state => state.env.author)
const curSummaryType = useAppSelector(state => state.env.tempData.curSummaryType)
const {sendInject} = useMessage()
@@ -79,20 +83,21 @@ const MoreBtn = (props: Props) => {
let fileName = title
let s, suffix
let time = ctime ? dayjs(ctime * 1000).format('YYYY-MM-DD HH:mm:ss') : '' // 2024-05-01 12:00:00
if (!downloadType || downloadType === 'text') {
s = `${title??'无标题'}\n${url??'无链接'}\n\n`
s = `${title??'无标题'}\n${url??'无链接'}\n${author??'无作者'} ${time}\n\n`
for (const item of data.body) {
s += item.content + '\n'
}
suffix = 'txt'
} else if (downloadType === 'textWithTime') {
s = `${title??'无标题'}\n${url??'无链接'}\n\n`
s = `${title??'无标题'}\n${url??'无链接'}\n${author??'无作者'} ${time}\n\n`
for (const item of data.body) {
s += formatTime(item.from) + ' ' + item.content + '\n'
}
suffix = 'txt'
} else if (downloadType === 'article') {
s = `${title??'无标题'}\n${url??'无链接'}\n\n`
s = `${title??'无标题'}\n${url??'无链接'}\n${author??'无作者'} ${time}\n\n`
for (const item of data.body) {
s += item.content + ', '
}
@@ -142,7 +147,7 @@ const MoreBtn = (props: Props) => {
s = JSON.stringify(data)
suffix = 'json'
} else if (downloadType === 'summarize') {
s = `${title??'无标题'}\n${url??'无链接'}\n\n`
s = `${title??'无标题'}\n${url??'无链接'}\n${author??'无作者'} ${time}\n\n`
const [success, content] = getSummarize(title, segments, curSummaryType)
if (!success) return
s += content

View File

@@ -291,6 +291,9 @@ for (const model of MODELS) {
export const LANGUAGES = [{
code: 'en',
name: 'English',
}, {
code: 'ja',
name: '日本語',
}, {
code: 'ena',
name: 'American English',
@@ -324,6 +327,39 @@ export const LANGUAGES = [{
}, {
code: 'Italian',
name: 'Italiano',
}, {
code: 'ko',
name: '한국어',
}, {
code: 'hi',
name: 'हिन्दी',
}, {
code: 'tr',
name: 'Türkçe',
}, {
code: 'nl',
name: 'Nederlands',
}, {
code: 'pl',
name: 'Polski',
}, {
code: 'sv',
name: 'Svenska',
}, {
code: 'vi',
name: 'Tiếng Việt',
}, {
code: 'th',
name: 'ไทย',
}, {
code: 'id',
name: 'Bahasa Indonesia',
}, {
code: 'el',
name: 'Ελληνικά',
}, {
code: 'he',
name: 'עברית',
}]
export const LANGUAGES_MAP: {[key: string]: typeof LANGUAGES[number]} = {}
for (const language of LANGUAGES) {

View File

@@ -1,4 +1,4 @@
import { setCurFetched, setCurInfo, setData, setInfos, setTitle, setUrl } from '@/redux/envReducer'
import { setAuthor, setCtime, setCurFetched, setCurInfo, setData, setInfos, setTitle, setUrl } from '@/redux/envReducer'
import { useMemo } from 'react'
import { useAppDispatch } from './redux'
import useMessagingService from '@/messaging/layer2/useMessagingService'
@@ -20,6 +20,8 @@ const useMessageService = () => {
dispatch(setInfos(params.infos))
dispatch(setUrl(params.url))
dispatch(setTitle(params.title))
dispatch(setCtime(params.ctime))
dispatch(setAuthor(params.author))
console.debug('video title: ', params.title)
},
}), [dispatch])

View File

@@ -120,6 +120,8 @@ const debug = (...args: any[]) => {
}
let aid: number | null = null
let ctime: number | null = null
let author: string | undefined
let title = ''
let pages: any[] = []
let pagesMap: Record<string, any> = {}
@@ -162,6 +164,8 @@ const debug = (...args: any[]) => {
aid = parseInt(aidOrBvid.slice(2))
pages = await fetch(`https://api.bilibili.com/x/player/pagelist?aid=${aid}`, { credentials: 'include' }).then(res => res.json()).then(res => res.data)
cid = pages[0].cid
ctime = pages[0].ctime
author = pages[0].owner?.name
title = pages[0].part
await fetch(`https://api.bilibili.com/x/player/v2?aid=${aid}&cid=${cid}`, { credentials: 'include' }).then(res => res.json()).then(res => {
subtitles = res.data.subtitle.subtitles
@@ -171,6 +175,8 @@ const debug = (...args: any[]) => {
title = res.data.title
aid = res.data.aid
cid = res.data.cid
ctime = res.data.ctime
author = res.data.owner?.name
pages = res.data.pages
})
await fetch(`https://api.bilibili.com/x/player/v2?aid=${aid}&cid=${cid}`, { credentials: 'include' }).then(res => res.json()).then(res => {
@@ -191,6 +197,8 @@ const debug = (...args: any[]) => {
url: location.origin + location.pathname,
title,
aid,
ctime,
author,
pages,
infos: subtitles,
})

View File

@@ -80,7 +80,7 @@ interface ExtensionCloseSidePanelMessage extends ExtensionMessage {
method: 'SET_INFOS';
}
interface AppSetVideoInfoMessage extends AppMessage<{ url: string, title: string, aid: number | null, pages: any, infos: any }> {
interface AppSetVideoInfoMessage extends AppMessage<{ url: string, title: string, aid: number | null, ctime: number | null, author?: string, pages: any, infos: any }> {
method: 'SET_VIDEO_INFO';
}

View File

@@ -32,7 +32,8 @@ interface EnvState {
segments?: Segment[]
url?: string
title?: string
ctime?: number | null
author?: string
taskIds?: string[]
transResults: { [key: number]: TransResult }
lastTransTime?: number
@@ -271,6 +272,12 @@ export const slice = createSlice({
setTitle: (state, action: PayloadAction<string | undefined>) => {
state.title = action.payload
},
setCtime: (state, action: PayloadAction<number | null | undefined>) => {
state.ctime = action.payload
},
setAuthor: (state, action: PayloadAction<string | undefined>) => {
state.author = action.payload
},
setInfos: (state, action: PayloadAction<any[]>) => {
state.infos = action.payload
},
@@ -342,6 +349,8 @@ export const {
addAskInfo,
delAskInfo,
mergeAskInfo,
setCtime,
setAuthor,
} = slice.actions
export default slice.reducer