diff --git a/API.md b/API.md index b230d75..56e5fe2 100644 --- a/API.md +++ b/API.md @@ -68,6 +68,7 @@ - [Tag category](#tag-category) - [Tag](#tag) - [Post](#post) + - [Micro post](#micro-post) - [Note](#note) - [Comment](#comment) - [Snapshot](#snapshot) @@ -1625,7 +1626,8 @@ One file together with its metadata posted to the site. - ``: various flags such as whether the post is looped, represented as array of plain strings. - ``: list of tag names the post is tagged with. -- ``: a list of related post IDs. Links to related posts are shown +- ``: a list of related posts, serialized as [micro post + resources](#micro-post). Links to related posts are shown to the user by the web client. - ``: a list of post annotations, serialized as list of [note resources](#note). @@ -1650,6 +1652,11 @@ One file together with its metadata posted to the site. earlier versions. - ``: a [comment resource](#comment) for given post. +## Micro post +**Description** + +A [post resource](#post) stripped down to `name` and `thumbnailUrl` fields. + ## Note **Description** diff --git a/server/szurubooru/func/posts.py b/server/szurubooru/func/posts.py index 2e38857..1f1429a 100644 --- a/server/szurubooru/func/posts.py +++ b/server/szurubooru/func/posts.py @@ -90,7 +90,15 @@ def serialize_post(post, authenticated_user, options=None): tag.category.name, tag.names[0].name) )], - 'relations': lambda: [rel.post_id for rel in post.relations], + 'relations': lambda: sorted( + { + post['id']: + post for post in [ + serialize_micro_post(rel) \ + for rel in post.related_by + post.relating_to + ] + }.values(), + key=lambda post: post['id']), 'user': lambda: users.serialize_micro_user(post.user), 'score': lambda: post.score, 'ownScore': lambda: scores.get_score(post, authenticated_user), @@ -120,6 +128,12 @@ def serialize_post(post, authenticated_user, options=None): }, options) +def serialize_micro_post(post): + return serialize_post( + post, + authenticated_user=None, + options=['id', 'thumbnailUrl']) + def get_post_count(): return db.session.query(sqlalchemy.func.count(db.Post.post_id)).one()[0]