diff --git a/API.md b/API.md index 05df63d9..4d52409d 100644 --- a/API.md +++ b/API.md @@ -1334,27 +1334,28 @@ One file together with its metadata posted to the site. ```json5 { - "id": , - "creationTime": , - "lastEditTime": , - "safety": , - "source": , - "type": , - "checksum": , - "canvasWidth": , - "canvasHeight": , - "contentUrl": , - "thumbnailUrl": , - "flags": , - "tags": , - "relations": , - "notes": , - "user": , - "score": , - "ownScore": , - "featureCount": , - "lastFeatureTime": , - "favoritedBy": + "id": , + "creationTime": , + "lastEditTime": , + "safety": , + "source": , + "type": , + "checksum": , + "canvasWidth": , + "canvasHeight": , + "contentUrl": , + "thumbnailUrl": , + "flags": , + "tags": , + "relations": , + "notes": , + "user": , + "score": , + "ownScore": , + "featureCount": , + "lastFeatureTime": , + "favoritedBy": , + "hasCustomThumbnail": } ``` @@ -1403,6 +1404,7 @@ One file together with its metadata posted to the site. - ``: the last time the post was featured, formatted as per RFC 3339. - ``: list of users, serialized as [user resources](#user). +- ``: whether the post uses custom thumbnail. ## Detailed post **Description** diff --git a/server/szurubooru/func/files.py b/server/szurubooru/func/files.py index 2a0217b1..f5209327 100644 --- a/server/szurubooru/func/files.py +++ b/server/szurubooru/func/files.py @@ -9,6 +9,9 @@ def delete(path): if os.path.exists(full_path): os.unlink(full_path) +def has(path): + return os.path.exists(_get_full_path(path)) + def get(path): full_path = _get_full_path(path) if not os.path.exists(full_path): diff --git a/server/szurubooru/func/posts.py b/server/szurubooru/func/posts.py index b79c117e..e12f30d7 100644 --- a/server/szurubooru/func/posts.py +++ b/server/szurubooru/func/posts.py @@ -85,6 +85,7 @@ def serialize_post(post, authenticated_user): 'lastFeatureTime': post.last_feature_time, 'favoritedBy': [users.serialize_user(rel.user, authenticated_user) \ for rel in post.favorited_by], + 'hasCustomThumbnail': files.has(get_post_thumbnail_backup_path(post)), } if authenticated_user: diff --git a/server/szurubooru/tests/api/test_comment_creating.py b/server/szurubooru/tests/api/test_comment_creating.py index 218239c0..ccb944d4 100644 --- a/server/szurubooru/tests/api/test_comment_creating.py +++ b/server/szurubooru/tests/api/test_comment_creating.py @@ -4,8 +4,10 @@ from szurubooru import api, db, errors from szurubooru.func import util, posts @pytest.fixture -def test_ctx(config_injector, context_factory, post_factory, user_factory): +def test_ctx( + tmpdir, config_injector, context_factory, post_factory, user_factory): config_injector({ + 'data_dir': str(tmpdir), 'data_url': 'http://example.com', 'ranks': ['anonymous', 'regular_user'], 'rank_names': {'anonymous': 'Peasant', 'regular_user': 'Lord'}, diff --git a/server/szurubooru/tests/api/test_comment_rating.py b/server/szurubooru/tests/api/test_comment_rating.py index 7d10700c..28c49086 100644 --- a/server/szurubooru/tests/api/test_comment_rating.py +++ b/server/szurubooru/tests/api/test_comment_rating.py @@ -4,8 +4,10 @@ from szurubooru import api, db, errors from szurubooru.func import util, comments, scores @pytest.fixture -def test_ctx(config_injector, context_factory, user_factory, comment_factory): +def test_ctx( + tmpdir, config_injector, context_factory, user_factory, comment_factory): config_injector({ + 'data_dir': str(tmpdir), 'data_url': 'http://example.com', 'ranks': ['anonymous', 'regular_user', 'mod'], 'rank_names': {'anonymous': 'Peasant', 'regular_user': 'Lord'}, diff --git a/server/szurubooru/tests/api/test_comment_retrieving.py b/server/szurubooru/tests/api/test_comment_retrieving.py index b0011b60..f0a2f746 100644 --- a/server/szurubooru/tests/api/test_comment_retrieving.py +++ b/server/szurubooru/tests/api/test_comment_retrieving.py @@ -4,8 +4,10 @@ from szurubooru import api, db, errors from szurubooru.func import util, comments @pytest.fixture -def test_ctx(context_factory, config_injector, user_factory, comment_factory): +def test_ctx( + tmpdir, context_factory, config_injector, user_factory, comment_factory): config_injector({ + 'data_dir': str(tmpdir), 'data_url': 'http://example.com', 'ranks': ['anonymous', 'regular_user', 'mod', 'admin'], 'rank_names': {'regular_user': 'Peasant'}, diff --git a/server/szurubooru/tests/api/test_comment_updating.py b/server/szurubooru/tests/api/test_comment_updating.py index 08ade5cc..16b2563d 100644 --- a/server/szurubooru/tests/api/test_comment_updating.py +++ b/server/szurubooru/tests/api/test_comment_updating.py @@ -4,8 +4,10 @@ from szurubooru import api, db, errors from szurubooru.func import util, comments @pytest.fixture -def test_ctx(config_injector, context_factory, user_factory, comment_factory): +def test_ctx( + tmpdir, config_injector, context_factory, user_factory, comment_factory): config_injector({ + 'data_dir': str(tmpdir), 'data_url': 'http://example.com', 'ranks': ['anonymous', 'regular_user', 'mod'], 'rank_names': {'anonymous': 'Peasant', 'regular_user': 'Lord', 'mod': 'King'}, diff --git a/server/szurubooru/tests/api/test_post_favoriting.py b/server/szurubooru/tests/api/test_post_favoriting.py index e5e627d2..d411bf02 100644 --- a/server/szurubooru/tests/api/test_post_favoriting.py +++ b/server/szurubooru/tests/api/test_post_favoriting.py @@ -4,8 +4,10 @@ from szurubooru import api, db, errors from szurubooru.func import util, posts @pytest.fixture -def test_ctx(config_injector, context_factory, user_factory, post_factory): +def test_ctx( + tmpdir, config_injector, context_factory, user_factory, post_factory): config_injector({ + 'data_dir': str(tmpdir), 'data_url': 'http://example.com', 'ranks': ['anonymous', 'regular_user', 'mod'], 'rank_names': {'anonymous': 'Peasant', 'regular_user': 'Lord'}, diff --git a/server/szurubooru/tests/api/test_post_featuring.py b/server/szurubooru/tests/api/test_post_featuring.py index 8a030f3d..cd8e6d66 100644 --- a/server/szurubooru/tests/api/test_post_featuring.py +++ b/server/szurubooru/tests/api/test_post_featuring.py @@ -4,8 +4,10 @@ from szurubooru import api, db, errors from szurubooru.func import util, posts @pytest.fixture -def test_ctx(context_factory, config_injector, user_factory, post_factory): +def test_ctx( + tmpdir, context_factory, config_injector, user_factory, post_factory): config_injector({ + 'data_dir': str(tmpdir), 'data_url': 'http://example.com', 'privileges': { 'posts:feature': 'regular_user', diff --git a/server/szurubooru/tests/api/test_post_rating.py b/server/szurubooru/tests/api/test_post_rating.py index def80fa8..03873c13 100644 --- a/server/szurubooru/tests/api/test_post_rating.py +++ b/server/szurubooru/tests/api/test_post_rating.py @@ -3,8 +3,10 @@ from szurubooru import api, db, errors from szurubooru.func import util, posts, scores @pytest.fixture -def test_ctx(config_injector, context_factory, user_factory, post_factory): +def test_ctx( + tmpdir, config_injector, context_factory, user_factory, post_factory): config_injector({ + 'data_dir': str(tmpdir), 'data_url': 'http://example.com', 'ranks': ['anonymous', 'regular_user'], 'rank_names': {'anonymous': 'Peasant', 'regular_user': 'Lord'}, diff --git a/server/szurubooru/tests/api/test_post_retrieving.py b/server/szurubooru/tests/api/test_post_retrieving.py index ec39a9af..369fa790 100644 --- a/server/szurubooru/tests/api/test_post_retrieving.py +++ b/server/szurubooru/tests/api/test_post_retrieving.py @@ -4,8 +4,10 @@ from szurubooru import api, db, errors from szurubooru.func import util, posts @pytest.fixture -def test_ctx(context_factory, config_injector, user_factory, post_factory): +def test_ctx( + tmpdir, context_factory, config_injector, user_factory, post_factory): config_injector({ + 'data_dir': str(tmpdir), 'data_url': 'http://example.com', 'privileges': { 'posts:list': 'regular_user', diff --git a/server/szurubooru/tests/func/test_posts.py b/server/szurubooru/tests/func/test_posts.py index c0c458c1..f24c1f6c 100644 --- a/server/szurubooru/tests/func/test_posts.py +++ b/server/szurubooru/tests/func/test_posts.py @@ -65,7 +65,8 @@ def test_serialize_empty_post(): assert posts.serialize_post(None, None) is None def test_serialize_post(post_factory, user_factory, tag_factory): - 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): users.serialize_user.side_effect = lambda user, auth_user: user.name auth_user = user_factory(name='auth user') @@ -140,6 +141,7 @@ def test_serialize_post(post_factory, user_factory, tag_factory): 'featureCount': 1, 'lastFeatureTime': datetime.datetime(1999, 1, 1), 'favoritedBy': ['fav1'], + 'hasCustomThumbnail': True, } def test_serialize_post_with_details(post_factory, comment_factory, user_factory):