Move favorites to local library and keep confirmed task heads in cloud
This commit is contained in:
@@ -84,6 +84,34 @@ class Assets:
|
||||
)
|
||||
return self.info(asset_id)
|
||||
|
||||
def record_origin(self, asset_id, operation):
|
||||
job = self.db.one(
|
||||
"SELECT jobs.id,jobs.payload FROM job_runs JOIN jobs ON jobs.id=job_runs.job_id WHERE operation_id=?",
|
||||
(operation["id"],),
|
||||
)
|
||||
import json
|
||||
|
||||
payload = json.loads(operation["payload"])
|
||||
content = payload.get("content", payload)
|
||||
origin = (
|
||||
"task"
|
||||
if job
|
||||
else "template"
|
||||
if content.get("type") == "template"
|
||||
else "manual"
|
||||
if operation["client_id"].startswith("user:")
|
||||
else "external"
|
||||
)
|
||||
self.db.execute(
|
||||
"INSERT OR IGNORE INTO asset_metadata(asset_id,origin,job_id,job_name) VALUES(?,?,?,?)",
|
||||
(
|
||||
asset_id,
|
||||
origin,
|
||||
job["id"] if job else None,
|
||||
json.loads(job["payload"])["name"] if job else None,
|
||||
),
|
||||
)
|
||||
|
||||
def promote(self, asset_id):
|
||||
row = self.db.one("SELECT * FROM assets WHERE id=?", (asset_id,))
|
||||
if row and row["kind"] == "cache":
|
||||
@@ -96,7 +124,12 @@ class Assets:
|
||||
row = self.db.one("SELECT * FROM assets WHERE id=?", (asset_id,))
|
||||
if not row:
|
||||
raise FlowError(E.NOT_FOUND, "Asset not found", 404)
|
||||
meta = self.db.one("SELECT * FROM asset_metadata WHERE asset_id=?", (asset_id,))
|
||||
return {
|
||||
"starred": bool(meta and meta["starred"]),
|
||||
"origin": meta["origin"] if meta else "unknown",
|
||||
"job_id": meta["job_id"] if meta else None,
|
||||
"job_name": meta["job_name"] if meta else None,
|
||||
"asset_id": row["id"],
|
||||
"source": "generated" if row["kind"] == "generated" else "uploaded",
|
||||
"name": row["name"],
|
||||
|
||||
Reference in New Issue
Block a user