Peach: Local-first video metadata scraper and media manager.
fix(activity): 已消失的作品不能移入或移出回收站
longmeidao0f9c4f884547
diff --git a/src/peach/web_activity.py b/src/peach/web_activity.pyindex d1b2f0e7e..84ee6e11a 100644--- a/src/peach/web_activity.py+++ b/src/peach/web_activity.py@@ -4,6 +4,7 @@ from __future__ import annotationsimport timefrom typing import Protocol+from .personal_records import VANISHEDDEFAULT_PROFILE_ID = "local-default"@@ -68,6 +69,9 @@ def w_feedback(contract: ActivityContract, body):current = connection.execute("SELECT disposal FROM asset WHERE id=?", (aid,),).fetchone()["disposal"]+ # 已消失的行文件不在盘上:切进回收站再切出来就成了在库(ADR-0087),整行不动。+ if current == VANISHED:+ raise ValueError("vanished assets cannot be moved to the recycle bin")connection.execute("UPDATE asset SET disposal=?, feedback_at=? WHERE id=?",(None if current == "trash" else "trash", time.time(), aid),diff --git a/src/peach/web_batch.py b/src/peach/web_batch.pyindex 58a64ed19..ccbd9d145 100644--- a/src/peach/web_batch.py+++ b/src/peach/web_batch.py@@ -622,6 +622,9 @@ def _reject_ineligible_targets(operation: str, rows) -> None:"""选中集合与操作对不上就拒绝整批,不做部分生效。"""if operation in {"restore", "delete"} and any(row["disposal"] not in DISPOSED for row in rows):raise ValueError("restore/delete is only allowed for recycle-bin or vanished assets")+ # 已消失的行文件不在盘上:进回收站再还原就成了在库,只能在孤儿记录里接回或彻底删除。+ if operation == "dispose" and any(row["disposal"] == VANISHED for row in rows):+ raise ValueError("vanished assets cannot be moved to the recycle bin")if operation in {"dismiss-junk", "reconsider-junk"} and any(row["location"] not in {"local", "115", "pikpak"}or row["disposal"] is not None for row in rows):diff --git a/tests/test_rm_web.py b/tests/test_rm_web.pyindex 16b9048d4..884a1c8dd 100644--- a/tests/test_rm_web.py+++ b/tests/test_rm_web.py@@ -812,6 +812,17 @@ class WebDataTests(unittest.TestCase):)["feedback"])self.assertEqual(self.row()["disposal"], "trash")+ def test_a_vanished_asset_refuses_the_recycle_bin_toggle_and_stays_vanished(self):+ """已消失的行切进回收站再切出来就成了在库:单条切换与批量移入回收站都拒绝。"""+ with self.contract.write_transaction() as connection:+ connection.execute("UPDATE asset SET disposal='vanished' WHERE id=1")+ with self.assertRaisesRegex(ValueError, "vanished"):+ rm_web.w_feedback(self.contract, {"id": 1, "kind": "dispose"})+ self.assertEqual(self.row()["disposal"], "vanished")+ with self.assertRaisesRegex(ValueError, "vanished"):+ rm_web.w_batch(self.contract, {"ids": [1, 2], "operation": "dispose"})+ self.assertEqual((self.row()["disposal"], self.row(2)["disposal"]), ("vanished", None))+def test_a_star_writes_twenty_points_and_taking_it_back_writes_null(self):"""评分这一列是 0–100,五颗星走 20 的倍数;撤销回 NULL,不是 0。