Skip to content

Add Hitokoto API category filter support#50

Merged
Sunwuyuan merged 3 commits into
mainfrom
copilot/add-custom-parameters-for-api
Apr 11, 2026
Merged

Add Hitokoto API category filter support#50
Sunwuyuan merged 3 commits into
mainfrom
copilot/add-custom-parameters-for-api

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 11, 2026

The Hitokoto (一言) source had no way to filter by sentence type — every request returned a random sentence from all categories. This adds per-category selection, stored in cloud KV config so it applies across all devices in a classroom.

Changes

HitokotoSettings.vue

  • Added "一言句子类型" section (visible only when Hitokoto source is enabled) with checkboxes for all 12 API categories (a–l: 动画, 漫画, 游戏, 文学, 原创, 来自网络, 其他, 影视, 诗词, 网易云, 哲学, 抖机灵)
  • Persists selection as hitokotoCategories: string[] in the existing sentence-info KV config
  • Leaving all unchecked preserves existing behavior (all categories)

HitokotoCard.vue

  • Builds the Hitokoto request URL with ?c=a&c=c&... params from stored hitokotoCategories when categories are selected
const params = new URLSearchParams()
categories.forEach(cat => params.append('c', cat))
const url = 'https://v1.hitokoto.cn/' + (params.toString() ? '?' + params.toString() : '')

Copilot AI self-assigned this Apr 11, 2026
Copilot AI linked an issue Apr 11, 2026 that may be closed by this pull request
Agent-Logs-Url: https://github.com/ZeroCatDev/Classworks/sessions/6de2bd3a-dd64-4f26-a5a5-0f7fed081fdc

Co-authored-by: Sunwuyuan <88357633+Sunwuyuan@users.noreply.github.com>
@cloudflare-workers-and-pages
Copy link
Copy Markdown

cloudflare-workers-and-pages Bot commented Apr 11, 2026

Deploying classworks with  Cloudflare Pages  Cloudflare Pages

Latest commit: 91169b0
Status: ✅  Deploy successful!
Preview URL: https://a305e701.classworks.pages.dev
Branch Preview URL: https://copilot-add-custom-parameter.classworks.pages.dev

View logs

Copilot AI changed the title [WIP] Add custom parameters for Hitokoto API Add Hitokoto API category filter support Apr 11, 2026
Copilot AI requested a review from Sunwuyuan April 11, 2026 13:39
@Sunwuyuan Sunwuyuan merged commit e437f05 into main Apr 11, 2026
4 of 6 checks passed
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds category filtering support for the Hitokoto (一言) sentence source by persisting selected API categories to the shared sentence-info cloud KV config and applying them when building the Hitokoto request URL.

Changes:

  • Added a “一言句子类型” multi-select UI (a–l) in HitokotoSettings.vue, persisted as hitokotoCategories: string[] in KV.
  • Extended both settings/card KV load defaults to include hitokotoCategories.
  • Updated HitokotoCard.vue to append repeated c query params (?c=a&c=c...) when categories are selected.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
src/components/HitokotoSettings.vue Adds category checkbox UI and KV persistence/loading for hitokotoCategories.
src/components/HitokotoCard.vue Builds Hitokoto API URL with optional category query params sourced from KV.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +55 to +59
v-for="cat in hitokotoCategories"
:key="cat.value"
v-model="kvConfig.hitokotoCategories"
:label="cat.label"
:value="cat.value"
Comment on lines +53 to +65
<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"
/>
Comment on lines +160 to +165
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() : '')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

【功能建议】为一言加入api自定义参数

2 participants