diff options
| author | Shyam Sunder | 2020-06-05 18:03:37 -0400 |
|---|---|---|
| committer | Shyam Sunder | 2020-06-06 08:58:23 -0400 |
| commit | 57193b57157b7a42896c887a2d5930493ac7b290 (patch) | |
| tree | 9555453a944caae64d8a00e4b073482d9e7fb244 /server/szurubooru/api/info_api.py | |
| parent | c06aaa63af977e64ef08bfba7829214f0f0ed38e (diff) | |
client+server: implement code autoformatting using prettier and black
Diffstat (limited to 'server/szurubooru/api/info_api.py')
| -rw-r--r-- | server/szurubooru/api/info_api.py | 59 |
1 files changed, 31 insertions, 28 deletions
diff --git a/server/szurubooru/api/info_api.py b/server/szurubooru/api/info_api.py index 1e2fd1d..757b09c 100644 --- a/server/szurubooru/api/info_api.py +++ b/server/szurubooru/api/info_api.py @@ -1,10 +1,10 @@ import os -from typing import Optional, Dict from datetime import datetime, timedelta +from typing import Dict, Optional + from szurubooru import config, rest from szurubooru.func import auth, posts, users, util - _cache_time = None # type: Optional[datetime] _cache_result = None # type: Optional[int] @@ -17,7 +17,7 @@ def _get_disk_usage() -> int: assert _cache_result is not None return _cache_result total_size = 0 - for dir_path, _, file_names in os.walk(config.config['data_dir']): + for dir_path, _, file_names in os.walk(config.config["data_dir"]): for file_name in file_names: file_path = os.path.join(dir_path, file_name) try: @@ -29,35 +29,38 @@ def _get_disk_usage() -> int: return total_size -@rest.routes.get('/info/?') -def get_info( - ctx: rest.Context, _params: Dict[str, str] = {}) -> rest.Response: +@rest.routes.get("/info/?") +def get_info(ctx: rest.Context, _params: Dict[str, str] = {}) -> rest.Response: post_feature = posts.try_get_current_post_feature() ret = { - 'postCount': posts.get_post_count(), - 'diskUsage': _get_disk_usage(), - 'serverTime': datetime.utcnow(), - 'config': { - 'name': config.config['name'], - 'userNameRegex': config.config['user_name_regex'], - 'passwordRegex': config.config['password_regex'], - 'tagNameRegex': config.config['tag_name_regex'], - 'tagCategoryNameRegex': config.config['tag_category_name_regex'], - 'defaultUserRank': config.config['default_rank'], - 'enableSafety': config.config['enable_safety'], - 'contactEmail': config.config['contact_email'], - 'canSendMails': bool(config.config['smtp']['host']), - 'privileges': - util.snake_case_to_lower_camel_case_keys( - config.config['privileges']), + "postCount": posts.get_post_count(), + "diskUsage": _get_disk_usage(), + "serverTime": datetime.utcnow(), + "config": { + "name": config.config["name"], + "userNameRegex": config.config["user_name_regex"], + "passwordRegex": config.config["password_regex"], + "tagNameRegex": config.config["tag_name_regex"], + "tagCategoryNameRegex": config.config["tag_category_name_regex"], + "defaultUserRank": config.config["default_rank"], + "enableSafety": config.config["enable_safety"], + "contactEmail": config.config["contact_email"], + "canSendMails": bool(config.config["smtp"]["host"]), + "privileges": util.snake_case_to_lower_camel_case_keys( + config.config["privileges"] + ), }, } - if auth.has_privilege(ctx.user, 'posts:view:featured'): - ret['featuredPost'] = ( + if auth.has_privilege(ctx.user, "posts:view:featured"): + ret["featuredPost"] = ( posts.serialize_post(post_feature.post, ctx.user) - if post_feature else None) - ret['featuringUser'] = ( + if post_feature + else None + ) + ret["featuringUser"] = ( users.serialize_user(post_feature.user, ctx.user) - if post_feature else None) - ret['featuringTime'] = post_feature.time if post_feature else None + if post_feature + else None + ) + ret["featuringTime"] = post_feature.time if post_feature else None return ret |