server/posts: add hasCustomThumbnail to post info
This commit is contained in:
parent
ce095816d9
commit
067e438b8c
4
API.md
4
API.md
|
@ -1354,7 +1354,8 @@ One file together with its metadata posted to the site.
|
||||||
"ownScore": <own-score>,
|
"ownScore": <own-score>,
|
||||||
"featureCount": <feature-count>,
|
"featureCount": <feature-count>,
|
||||||
"lastFeatureTime": <last-feature-time>,
|
"lastFeatureTime": <last-feature-time>,
|
||||||
"favoritedBy": <favorited-by>
|
"favoritedBy": <favorited-by>,
|
||||||
|
"hasCustomThumbnail": <has-custom-thumbnail>
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
@ -1403,6 +1404,7 @@ One file together with its metadata posted to the site.
|
||||||
- `<last-feature-time>`: the last time the post was featured, formatted as per
|
- `<last-feature-time>`: the last time the post was featured, formatted as per
|
||||||
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.
|
||||||
|
|
||||||
## Detailed post
|
## Detailed post
|
||||||
**Description**
|
**Description**
|
||||||
|
|
|
@ -9,6 +9,9 @@ def delete(path):
|
||||||
if os.path.exists(full_path):
|
if os.path.exists(full_path):
|
||||||
os.unlink(full_path)
|
os.unlink(full_path)
|
||||||
|
|
||||||
|
def has(path):
|
||||||
|
return os.path.exists(_get_full_path(path))
|
||||||
|
|
||||||
def get(path):
|
def get(path):
|
||||||
full_path = _get_full_path(path)
|
full_path = _get_full_path(path)
|
||||||
if not os.path.exists(full_path):
|
if not os.path.exists(full_path):
|
||||||
|
|
|
@ -85,6 +85,7 @@ def serialize_post(post, authenticated_user):
|
||||||
'lastFeatureTime': post.last_feature_time,
|
'lastFeatureTime': post.last_feature_time,
|
||||||
'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)),
|
||||||
}
|
}
|
||||||
|
|
||||||
if authenticated_user:
|
if authenticated_user:
|
||||||
|
|
|
@ -4,8 +4,10 @@ from szurubooru import api, db, errors
|
||||||
from szurubooru.func import util, posts
|
from szurubooru.func import util, posts
|
||||||
|
|
||||||
@pytest.fixture
|
@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({
|
config_injector({
|
||||||
|
'data_dir': str(tmpdir),
|
||||||
'data_url': 'http://example.com',
|
'data_url': 'http://example.com',
|
||||||
'ranks': ['anonymous', 'regular_user'],
|
'ranks': ['anonymous', 'regular_user'],
|
||||||
'rank_names': {'anonymous': 'Peasant', 'regular_user': 'Lord'},
|
'rank_names': {'anonymous': 'Peasant', 'regular_user': 'Lord'},
|
||||||
|
|
|
@ -4,8 +4,10 @@ from szurubooru import api, db, errors
|
||||||
from szurubooru.func import util, comments, scores
|
from szurubooru.func import util, comments, scores
|
||||||
|
|
||||||
@pytest.fixture
|
@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({
|
config_injector({
|
||||||
|
'data_dir': str(tmpdir),
|
||||||
'data_url': 'http://example.com',
|
'data_url': 'http://example.com',
|
||||||
'ranks': ['anonymous', 'regular_user', 'mod'],
|
'ranks': ['anonymous', 'regular_user', 'mod'],
|
||||||
'rank_names': {'anonymous': 'Peasant', 'regular_user': 'Lord'},
|
'rank_names': {'anonymous': 'Peasant', 'regular_user': 'Lord'},
|
||||||
|
|
|
@ -4,8 +4,10 @@ from szurubooru import api, db, errors
|
||||||
from szurubooru.func import util, comments
|
from szurubooru.func import util, comments
|
||||||
|
|
||||||
@pytest.fixture
|
@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({
|
config_injector({
|
||||||
|
'data_dir': str(tmpdir),
|
||||||
'data_url': 'http://example.com',
|
'data_url': 'http://example.com',
|
||||||
'ranks': ['anonymous', 'regular_user', 'mod', 'admin'],
|
'ranks': ['anonymous', 'regular_user', 'mod', 'admin'],
|
||||||
'rank_names': {'regular_user': 'Peasant'},
|
'rank_names': {'regular_user': 'Peasant'},
|
||||||
|
|
|
@ -4,8 +4,10 @@ from szurubooru import api, db, errors
|
||||||
from szurubooru.func import util, comments
|
from szurubooru.func import util, comments
|
||||||
|
|
||||||
@pytest.fixture
|
@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({
|
config_injector({
|
||||||
|
'data_dir': str(tmpdir),
|
||||||
'data_url': 'http://example.com',
|
'data_url': 'http://example.com',
|
||||||
'ranks': ['anonymous', 'regular_user', 'mod'],
|
'ranks': ['anonymous', 'regular_user', 'mod'],
|
||||||
'rank_names': {'anonymous': 'Peasant', 'regular_user': 'Lord', 'mod': 'King'},
|
'rank_names': {'anonymous': 'Peasant', 'regular_user': 'Lord', 'mod': 'King'},
|
||||||
|
|
|
@ -4,8 +4,10 @@ from szurubooru import api, db, errors
|
||||||
from szurubooru.func import util, posts
|
from szurubooru.func import util, posts
|
||||||
|
|
||||||
@pytest.fixture
|
@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({
|
config_injector({
|
||||||
|
'data_dir': str(tmpdir),
|
||||||
'data_url': 'http://example.com',
|
'data_url': 'http://example.com',
|
||||||
'ranks': ['anonymous', 'regular_user', 'mod'],
|
'ranks': ['anonymous', 'regular_user', 'mod'],
|
||||||
'rank_names': {'anonymous': 'Peasant', 'regular_user': 'Lord'},
|
'rank_names': {'anonymous': 'Peasant', 'regular_user': 'Lord'},
|
||||||
|
|
|
@ -4,8 +4,10 @@ from szurubooru import api, db, errors
|
||||||
from szurubooru.func import util, posts
|
from szurubooru.func import util, posts
|
||||||
|
|
||||||
@pytest.fixture
|
@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({
|
config_injector({
|
||||||
|
'data_dir': str(tmpdir),
|
||||||
'data_url': 'http://example.com',
|
'data_url': 'http://example.com',
|
||||||
'privileges': {
|
'privileges': {
|
||||||
'posts:feature': 'regular_user',
|
'posts:feature': 'regular_user',
|
||||||
|
|
|
@ -3,8 +3,10 @@ from szurubooru import api, db, errors
|
||||||
from szurubooru.func import util, posts, scores
|
from szurubooru.func import util, posts, scores
|
||||||
|
|
||||||
@pytest.fixture
|
@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({
|
config_injector({
|
||||||
|
'data_dir': str(tmpdir),
|
||||||
'data_url': 'http://example.com',
|
'data_url': 'http://example.com',
|
||||||
'ranks': ['anonymous', 'regular_user'],
|
'ranks': ['anonymous', 'regular_user'],
|
||||||
'rank_names': {'anonymous': 'Peasant', 'regular_user': 'Lord'},
|
'rank_names': {'anonymous': 'Peasant', 'regular_user': 'Lord'},
|
||||||
|
|
|
@ -4,8 +4,10 @@ from szurubooru import api, db, errors
|
||||||
from szurubooru.func import util, posts
|
from szurubooru.func import util, posts
|
||||||
|
|
||||||
@pytest.fixture
|
@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({
|
config_injector({
|
||||||
|
'data_dir': str(tmpdir),
|
||||||
'data_url': 'http://example.com',
|
'data_url': 'http://example.com',
|
||||||
'privileges': {
|
'privileges': {
|
||||||
'posts:list': 'regular_user',
|
'posts:list': 'regular_user',
|
||||||
|
|
|
@ -65,7 +65,8 @@ 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):
|
||||||
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
|
users.serialize_user.side_effect = lambda user, auth_user: user.name
|
||||||
|
|
||||||
auth_user = user_factory(name='auth user')
|
auth_user = user_factory(name='auth user')
|
||||||
|
@ -140,6 +141,7 @@ def test_serialize_post(post_factory, user_factory, tag_factory):
|
||||||
'featureCount': 1,
|
'featureCount': 1,
|
||||||
'lastFeatureTime': datetime.datetime(1999, 1, 1),
|
'lastFeatureTime': datetime.datetime(1999, 1, 1),
|
||||||
'favoritedBy': ['fav1'],
|
'favoritedBy': ['fav1'],
|
||||||
|
'hasCustomThumbnail': True,
|
||||||
}
|
}
|
||||||
|
|
||||||
def test_serialize_post_with_details(post_factory, comment_factory, user_factory):
|
def test_serialize_post_with_details(post_factory, comment_factory, user_factory):
|
||||||
|
|
Loading…
Reference in New Issue