fix e621 api compliance bugs

This commit is contained in:
Luna 2022-09-18 16:20:33 -03:00
parent ee4ba47831
commit 019c5ad1b5
1 changed files with 3 additions and 4 deletions

View File

@ -84,6 +84,7 @@ class Post:
} }
post.pop("up_score") post.pop("up_score")
post.pop("down_score") post.pop("down_score")
post["file"] = {"md5": post.pop("md5")}
post["flags"] = { post["flags"] = {
"pending": post.pop("is_pending"), "pending": post.pop("is_pending"),
"flagged": post.pop("is_flagged"), "flagged": post.pop("is_flagged"),
@ -109,7 +110,7 @@ class TagCategory(enum.IntEnum):
self.ARTIST: "artist", self.ARTIST: "artist",
self.COPYRIGHT: "copyright", self.COPYRIGHT: "copyright",
self.CHARACTER: "character", self.CHARACTER: "character",
self.METADATA: "metadata", self.METADATA: "meta",
self.DEPRECATED: "deprecated", self.DEPRECATED: "deprecated",
self.SPECIES: "species", self.SPECIES: "species",
self.LORE: "lore", self.LORE: "lore",
@ -164,15 +165,13 @@ async def posts_json():
post = Post(**rows[0]) post = Post(**rows[0])
post_json = post.to_json() post_json = post.to_json()
post_json["tags"] = {} post_json["tags"] = {category.to_string(): [] for category in TagCategory}
for tag in post.tag_string.split(" "): for tag in post.tag_string.split(" "):
tag_rows = await app.db.execute_fetchall( tag_rows = await app.db.execute_fetchall(
"select category from tags where name = ?", (tag,) "select category from tags where name = ?", (tag,)
) )
category = TagCategory(tag_rows[0][0]) category = TagCategory(tag_rows[0][0])
category_str = category.to_string() category_str = category.to_string()
if category_str not in post_json["tags"]:
post_json["tags"][category_str] = []
post_json["tags"][category_str].append(tag) post_json["tags"][category_str].append(tag)
return {"posts": [post_json]} return {"posts": [post_json]}