From 919c4c3155feffb3b43886f82e2e25ba8a4d2c17 Mon Sep 17 00:00:00 2001 From: kozzzx Date: Sat, 21 Oct 2023 01:37:27 +0800 Subject: [PATCH] Add homepage setting --- app/apis/site_setting.py | 10 ++++++++++ app/apis/urls.py | 7 ++++++- app/models/site_setting.py | 4 ++++ app/validators/site_setting.py | 2 ++ 4 files changed, 22 insertions(+), 1 deletion(-) diff --git a/app/apis/site_setting.py b/app/apis/site_setting.py index 3f72b3a..b491199 100644 --- a/app/apis/site_setting.py +++ b/app/apis/site_setting.py @@ -52,6 +52,16 @@ def put(self): site_setting.whitelist_emails = data["whitelist_emails"] site_setting.only_allow_admin_create_team = data["only_allow_admin_create_team"] site_setting.auto_join_team_ids = data["auto_join_team_ids"] + site_setting.homepage_html = data["homepage_html"] + site_setting.homepage_css = data["homepage_css"] site_setting.save() site_setting.reload() return site_setting.to_api() + + +class HomepageAPI(MoeAPIView): + def get(self): + return { + "html": SiteSetting.get().homepage_html, + "css": SiteSetting.get().homepage_css, + } diff --git a/app/apis/urls.py b/app/apis/urls.py index a12a9e2..f520547 100644 --- a/app/apis/urls.py +++ b/app/apis/urls.py @@ -23,7 +23,7 @@ MeRelatedApplicationListAPI, ) from app.apis.avatar import AvatarAPI -from app.apis.site_setting import SiteSettingAPI +from app.apis.site_setting import HomepageAPI, SiteSettingAPI from app.apis.user import ( AdminUserAPI, AdminUserAdminStatusAPI, @@ -92,6 +92,11 @@ index.add_url_rule( "/error", methods=["GET", "OPTIONS"], view_func=ErrorAPI.as_view("error") ) +# site公开配置模块 +site = Blueprint("site", __name__, url_prefix=v1_prefix + "/site") +site.add_url_rule( + "/homepage", methods=["GET", "OPTIONS"], view_func=HomepageAPI.as_view("homepage") +) # type模块 type = Blueprint("type", __name__, url_prefix=v1_prefix + "/types") type.add_url_rule( diff --git a/app/models/site_setting.py b/app/models/site_setting.py index 5240dfa..e74ae15 100644 --- a/app/models/site_setting.py +++ b/app/models/site_setting.py @@ -18,6 +18,8 @@ class SiteSetting(Document): whitelist_emails = ListField(StringField(), db_field="we", default=list) only_allow_admin_create_team = BooleanField(db_field="oacg", default=True) auto_join_team_ids = ListField(ObjectIdField(), db_field="ajt", default=list) + homepage_html = StringField(db_field="h", default="") + homepage_css = StringField(db_field="hc", default="") meta = { "indexes": [ @@ -44,4 +46,6 @@ def to_api(self): "whitelist_emails": self.whitelist_emails, "only_allow_admin_create_team": self.only_allow_admin_create_team, "auto_join_team_ids": [str(id) for id in self.auto_join_team_ids], + "homepage_html": self.homepage_html, + "homepage_css": self.homepage_css, } diff --git a/app/validators/site_setting.py b/app/validators/site_setting.py index 1cf34ba..b96bf6c 100644 --- a/app/validators/site_setting.py +++ b/app/validators/site_setting.py @@ -23,3 +23,5 @@ class SiteSettingSchema(Schema): required=True, error_messages={**required_message}, ) + homepage_html = fields.Str() + homepage_css = fields.Str()