server/info: add serverTime field
This commit is contained in:
parent
40565e82ae
commit
162904bfc3
6
API.md
6
API.md
|
@ -1373,14 +1373,16 @@ data.
|
||||||
"diskUsage": <disk-usage>, // in bytes
|
"diskUsage": <disk-usage>, // in bytes
|
||||||
"featuredPost": <featured-post>,
|
"featuredPost": <featured-post>,
|
||||||
"featuringTime": <time>,
|
"featuringTime": <time>,
|
||||||
"featuringUser": <user>
|
"featuringUser": <user>,
|
||||||
|
"serverTime": <server-time>
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
- **Description**
|
- **Description**
|
||||||
|
|
||||||
Retrieves simple statistics. `<featured-post>` is null if there is no
|
Retrieves simple statistics. `<featured-post>` is null if there is no
|
||||||
featured post yet.
|
featured post yet. `<server-time>` is pretty much the same as the `Date`
|
||||||
|
HTTP field, only formatted in a manner consistent with other dates.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -20,6 +20,7 @@ class InfoApi(BaseApi):
|
||||||
'featuringTime': post_feature.time if post_feature else None,
|
'featuringTime': post_feature.time if post_feature else None,
|
||||||
'featuringUser': users.serialize_user(post_feature.user, ctx.user) \
|
'featuringUser': users.serialize_user(post_feature.user, ctx.user) \
|
||||||
if post_feature else None,
|
if post_feature else None,
|
||||||
|
'serverTime': datetime.datetime.now(),
|
||||||
}
|
}
|
||||||
|
|
||||||
def _get_disk_usage(self):
|
def _get_disk_usage(self):
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
from datetime import datetime
|
||||||
from szurubooru import api, db
|
from szurubooru import api, db
|
||||||
|
|
||||||
def test_info_api(
|
def test_info_api(
|
||||||
|
@ -7,28 +8,31 @@ def test_info_api(
|
||||||
config_injector({'data_dir': str(directory)})
|
config_injector({'data_dir': str(directory)})
|
||||||
db.session.add_all([post_factory(), post_factory()])
|
db.session.add_all([post_factory(), post_factory()])
|
||||||
info_api = api.InfoApi()
|
info_api = api.InfoApi()
|
||||||
with fake_datetime('13:00'):
|
with fake_datetime('2016-01-01 13:00'):
|
||||||
assert info_api.get(context_factory()) == {
|
assert info_api.get(context_factory()) == {
|
||||||
'postCount': 2,
|
'postCount': 2,
|
||||||
'diskUsage': 3,
|
'diskUsage': 3,
|
||||||
'featuredPost': None,
|
'featuredPost': None,
|
||||||
'featuringTime': None,
|
'featuringTime': None,
|
||||||
'featuringUser': None,
|
'featuringUser': None,
|
||||||
|
'serverTime': datetime(2016, 1, 1, 13, 0),
|
||||||
}
|
}
|
||||||
directory.join('test2.txt').write('abc')
|
directory.join('test2.txt').write('abc')
|
||||||
with fake_datetime('13:59'):
|
with fake_datetime('2016-01-01 13:59'):
|
||||||
assert info_api.get(context_factory()) == {
|
assert info_api.get(context_factory()) == {
|
||||||
'postCount': 2,
|
'postCount': 2,
|
||||||
'diskUsage': 3, # still 3 - it's cached
|
'diskUsage': 3, # still 3 - it's cached
|
||||||
'featuredPost': None,
|
'featuredPost': None,
|
||||||
'featuringTime': None,
|
'featuringTime': None,
|
||||||
'featuringUser': None,
|
'featuringUser': None,
|
||||||
|
'serverTime': datetime(2016, 1, 1, 13, 59),
|
||||||
}
|
}
|
||||||
with fake_datetime('14:01'):
|
with fake_datetime('2016-01-01 14:01'):
|
||||||
assert info_api.get(context_factory()) == {
|
assert info_api.get(context_factory()) == {
|
||||||
'postCount': 2,
|
'postCount': 2,
|
||||||
'diskUsage': 6, # cache expired
|
'diskUsage': 6, # cache expired
|
||||||
'featuredPost': None,
|
'featuredPost': None,
|
||||||
'featuringTime': None,
|
'featuringTime': None,
|
||||||
'featuringUser': None,
|
'featuringUser': None,
|
||||||
|
'serverTime': datetime(2016, 1, 1, 14, 1),
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue