Skip to content

[清除下载历史] 支持通过 PID 删除指定作品和通过 UserID 删除该用户的所有作品 #72

@Erhai-lake

Description

@Erhai-lake

目前历史记录页面只提供了清空全部历史的功能, 希望能提供多两种清除方式.

  1. 通过userId删除该用户的所有作品下载记录.
  2. 通过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);

你的脚本很好用, 感谢您维护它!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions