1
0
mirror of https://github.com/ZeroCatDev/Classworks.git synced 2026-05-13 19:35:07 +00:00

Add Hitokoto API category customization support

Agent-Logs-Url: https://github.com/ZeroCatDev/Classworks/sessions/6de2bd3a-dd64-4f26-a5a5-0f7fed081fdc

Co-authored-by: Sunwuyuan <88357633+Sunwuyuan@users.noreply.github.com>
This commit is contained in:
copilot-swe-agent[bot] 2026-04-11 13:38:31 +00:00 committed by GitHub
parent 3e2b9e993a
commit 6f697d0fd0
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 48 additions and 5 deletions

View File

@ -61,7 +61,8 @@ export default {
refreshInterval: 60,
kvConfig: {
sources: ['zhaoyu'],
sensitiveWords: []
sensitiveWords: [],
hitokotoCategories: []
},
sentence: '',
author: '',
@ -125,7 +126,8 @@ export default {
this.kvConfig = {
sources: Array.isArray(data.sources) && data.sources.length > 0 ? data.sources : ['zhaoyu'],
sensitiveWords: data.sensitiveWords ? data.sensitiveWords.split(/[,]/).map(w => w.trim()).filter(w => w) : [],
jinrishiciToken: data.jinrishiciToken
jinrishiciToken: data.jinrishiciToken,
hitokotoCategories: Array.isArray(data.hitokotoCategories) ? data.hitokotoCategories : []
}
}
} catch (e) {
@ -155,7 +157,13 @@ export default {
let origin = ''
if (source === 'hitokoto') {
const res = await axios.get('https://v1.hitokoto.cn/')
const params = new URLSearchParams()
const categories = this.kvConfig.hitokotoCategories
if (Array.isArray(categories) && categories.length > 0) {
categories.forEach(cat => params.append('c', cat))
}
const url = 'https://v1.hitokoto.cn/' + (params.toString() ? '?' + params.toString() : '')
const res = await axios.get(url)
data = res.data
content = data.hitokoto
author = data.from_who

View File

@ -47,6 +47,25 @@
</div>
</v-list-item>
<v-list-item v-if="kvConfig.sources.includes('hitokoto')">
<v-list-item-title class="mb-2">一言句子类型</v-list-item-title>
<div class="text-caption text-grey mb-2">不选则返回所有类型可多选</div>
<div class="d-flex flex-wrap gap-2">
<v-checkbox
v-for="cat in hitokotoCategories"
:key="cat.value"
v-model="kvConfig.hitokotoCategories"
:label="cat.label"
:value="cat.value"
hide-details
density="compact"
class="mr-4"
:disabled="loading"
@update:model-value="saveKvSettings"
/>
</div>
</v-list-item>
<v-list-item v-if="kvConfig.sources.includes('jinrishici')">
<v-text-field
v-model="kvConfig.jinrishiciToken"
@ -278,8 +297,23 @@ export default {
kvConfig: {
sources: ['zhaoyu'],
sensitiveWords: '',
jinrishiciToken: null
jinrishiciToken: null,
hitokotoCategories: []
},
hitokotoCategories: [
{ value: 'a', label: '动画' },
{ value: 'b', label: '漫画' },
{ value: 'c', label: '游戏' },
{ value: 'd', label: '文学' },
{ value: 'e', label: '原创' },
{ value: 'f', label: '来自网络' },
{ value: 'g', label: '其他' },
{ value: 'h', label: '影视' },
{ value: 'i', label: '诗词' },
{ value: 'j', label: '网易云' },
{ value: 'k', label: '哲学' },
{ value: 'l', label: '抖机灵' },
],
loading: false,
testLoading: false,
testMessage: '',
@ -306,7 +340,8 @@ export default {
this.kvConfig = {
sources: Array.isArray(data.sources) ? data.sources : ['zhaoyu'],
sensitiveWords: data.sensitiveWords || '',
jinrishiciToken: data.jinrishiciToken
jinrishiciToken: data.jinrishiciToken,
hitokotoCategories: Array.isArray(data.hitokotoCategories) ? data.hitokotoCategories : []
}
}
} catch (e) {