Keep manual redisplays separate from random task cloud heads

This commit is contained in:
Pigway
2026-10-06 09:34:05 +08:00
parent 180b6ae100
commit 60f42fb58c
2 changed files with 40 additions and 2 deletions
+16 -2
View File
@@ -12,14 +12,28 @@ class CloudLibrary:
self.checked = 0.0 self.checked = 0.0
def register(self, device_id, image_id, asset_id, operation_id): def register(self, device_id, image_id, asset_id, operation_id):
meta = self.service.assets.info(asset_id) operation = self.db.one(
"SELECT payload FROM operations WHERE id=?", (operation_id,)
)
payload = json.loads(operation["payload"])
content = payload.get("content", {})
job = self.db.one(
"SELECT job_id FROM job_runs WHERE operation_id=?", (operation_id,)
)
job_id = (
job["job_id"]
if job
and content.get("type") == "photo_source"
and content.get("item_id") is None
else None
)
self.db.execute( self.db.execute(
"INSERT INTO managed_cloud_uploads VALUES(?,?,?,?,?,?,NULL,NULL)", "INSERT INTO managed_cloud_uploads VALUES(?,?,?,?,?,?,NULL,NULL)",
( (
device_id, device_id,
image_id, image_id,
asset_id, asset_id,
meta.get("job_id"), job_id,
operation_id, operation_id,
datetime.now(UTC).isoformat(), datetime.now(UTC).isoformat(),
), ),
+24
View File
@@ -144,3 +144,27 @@ def test_clear_cloud_requires_confirmation_and_clears_current(client, service):
for _ in range(before): for _ in range(before):
assert service.process_one() assert service.process_one()
assert not service.registry.get("living-room").images() assert not service.registry.get("living-room").images()
def test_manual_display_does_not_replace_task_head(client, service, settings):
setup_photos(service, settings)
job = make_job(client, "A")
first, asset = run(client, service, job)
second, _ = run(client, service, job)
client.put(f"/api/v1/assets/{asset}/star", json={"starred": True})
response = client.post(
"/api/v1/display", json={"content": {"type": "image", "asset_id": asset}}
)
service.process_one()
service.sync()
op = client.get("/api/v1/operations/" + response.json()["operation_id"]).json()
row = service.db.one(
"SELECT job_id FROM managed_cloud_uploads WHERE image_id=?",
(op["result"]["image_id"],),
)
assert row["job_id"] is None
assert service.cloud_library.retained(
service.db.one(
"SELECT * FROM managed_cloud_uploads WHERE image_id=?", (second,)
)
)