目前历史记录页面只提供了清空全部历史的功能, 希望能提供多两种清除方式.
- 通过
userId删除该用户的所有作品下载记录.
- 通过
pid删除指定作品的下载记录.
// src/lib/components/Modal/Config/Panels/DownloadHistory.svelte
async function deleteByUserId(userId: number) {
if (isNaN(userId)) throw new Error('用户 ID 必须是数字');
const isConfirm = confirm(t('setting.history.text.confirm_clear_history'));
if (!isConfirm) return;
const records = await historyDb.history.where('userId').equals(userId).toArray();
if (records.length === 0) return 0;
await historyDb.history.where('userId').equals(userId).delete();
return records.length;
}
async function deleteByPid(pid: number) {
if (isNaN(pid)) throw new Error('作品 ID 必须是数字');
const isConfirm = confirm(t('setting.history.text.confirm_clear_history'));
if (!isConfirm) return;
const record = await historyDb.history.where('pid').equals(pid).first();
if (!record) return 0;
await historyDb.history.where('pid').equals(pid).delete();
return 1;
}
const { store: deletePending, wrapFn: wrapDeleteByUserId } = usePendingButton(deleteByUserId);
const { wrapFn: wrapDeleteByPid } = usePendingButton(deleteByPid);
你的脚本很好用, 感谢您维护它!