server/posts: send mime type to client

This commit is contained in:
rr- 2016-05-22 22:50:00 +02:00
parent d99c03b9fa
commit af22ec735d
3 changed files with 10 additions and 4 deletions

9
API.md
View file

@ -1440,7 +1440,7 @@ experience.
"name": <name>, "name": <name>,
"color": <color>, "color": <color>,
"usages": <usages> "usages": <usages>
"default": <is_default> "default": <is-default>
} }
``` ```
@ -1449,7 +1449,7 @@ experience.
- `<name>`: the category name. - `<name>`: the category name.
- `<color>`: the category color. - `<color>`: the category color.
- `<usages>`: how many tags is the given category used with. - `<usages>`: how many tags is the given category used with.
- `<is_default>`: whether the tag category is the default one. - `<is-default>`: whether the tag category is the default one.
## Detailed tag category ## Detailed tag category
**Description** **Description**
@ -1560,7 +1560,8 @@ One file together with its metadata posted to the site.
"featureCount": <feature-count>, "featureCount": <feature-count>,
"lastFeatureTime": <last-feature-time>, "lastFeatureTime": <last-feature-time>,
"favoritedBy": <favorited-by>, "favoritedBy": <favorited-by>,
"hasCustomThumbnail": <has-custom-thumbnail> "hasCustomThumbnail": <has-custom-thumbnail>,
"mimeType": <mime-type>
} }
``` ```
@ -1610,6 +1611,8 @@ One file together with its metadata posted to the site.
RFC 3339. RFC 3339.
- `<favorited-by>`: list of users, serialized as [user resources](#user). - `<favorited-by>`: list of users, serialized as [user resources](#user).
- `<has-custom-thumbnail>`: whether the post uses custom thumbnail. - `<has-custom-thumbnail>`: whether the post uses custom thumbnail.
- `<mime-type>`: subsidiary to `<type>`, used to tell exact content format;
useful for `<video>` tags for instance.
## Detailed post ## Detailed post
**Description** **Description**

View file

@ -89,6 +89,7 @@ def serialize_post(post, authenticated_user):
'favoritedBy': [users.serialize_user(rel.user, authenticated_user) \ 'favoritedBy': [users.serialize_user(rel.user, authenticated_user) \
for rel in post.favorited_by], for rel in post.favorited_by],
'hasCustomThumbnail': files.has(get_post_thumbnail_backup_path(post)), 'hasCustomThumbnail': files.has(get_post_thumbnail_backup_path(post)),
'mimeType': post.mime_type,
} }
if authenticated_user: if authenticated_user:

View file

@ -64,7 +64,8 @@ def test_serialize_note():
def test_serialize_empty_post(): def test_serialize_empty_post():
assert posts.serialize_post(None, None) is None assert posts.serialize_post(None, None) is None
def test_serialize_post(post_factory, user_factory, tag_factory): def test_serialize_post(post_factory, user_factory, tag_factory, config_injector):
config_injector({'data_url': 'http://example.com/'})
with unittest.mock.patch('szurubooru.func.users.serialize_user'), \ with unittest.mock.patch('szurubooru.func.users.serialize_user'), \
unittest.mock.patch('szurubooru.func.posts.files.has', return_value=True): unittest.mock.patch('szurubooru.func.posts.files.has', return_value=True):
users.serialize_user.side_effect = lambda user, auth_user: user.name users.serialize_user.side_effect = lambda user, auth_user: user.name
@ -142,6 +143,7 @@ def test_serialize_post(post_factory, user_factory, tag_factory):
'lastFeatureTime': datetime.datetime(1999, 1, 1), 'lastFeatureTime': datetime.datetime(1999, 1, 1),
'favoritedBy': ['fav1'], 'favoritedBy': ['fav1'],
'hasCustomThumbnail': True, 'hasCustomThumbnail': True,
'mimeType': 'image/jpeg',
} }
def test_serialize_post_with_details(post_factory, comment_factory, user_factory): def test_serialize_post_with_details(post_factory, comment_factory, user_factory):