Skip to content

Commit

Permalink
content-type
Browse files Browse the repository at this point in the history
  • Loading branch information
Light-Beacon committed Aug 22, 2024
1 parent 8765a37 commit 6f0821a
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 11 deletions.
2 changes: 1 addition & 1 deletion Config/basic.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ System.Script.IgnoreError: False

Logging.Level: 30
# 是否启用 Debug
Debug.Enable: True
Debug.Enable: False
Debug.Logging.Level: 10

# 是否忽略以 IO.IngorePrefix 开头和以 IO.IngoreSuffix 结尾的文件
Expand Down
3 changes: 3 additions & 0 deletions Core/page.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ def generate(self, *args, **kwargs):
@property
def display_name(self):
raise NotImplementedError()

def get_content_type(self, setter):
return 'application/xml'

class FileBasedPage(PageBase):
"基于文件的页面,仅应用于继承"
Expand Down
7 changes: 7 additions & 0 deletions Core/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,13 @@ def get_page_xaml(self, page_alias, no_not_found_err_logging = False, setter = N
raise PageNotFoundError(page_alias)
return self.pages[page_alias].generate(setter = setter)

def get_page_content_type(self, page_alias, no_not_found_err_logging = False, setter = None):
if page_alias not in self.pages:
if not no_not_found_err_logging:
logger.error(t('project.gen_page.failed.notfound', page=page_alias))
raise PageNotFoundError(page_alias)
return self.pages[page_alias].get_content_type(setter = setter)

def get_page_displayname(self, page_alias):
"""获取页面显示名"""
page = self.pages.get(page_alias)
Expand Down
6 changes: 4 additions & 2 deletions Resources/Page_Templates/Default.xaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<!-- <StackPanel xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:local="clr-namespace:PCL2" > -->
<StackPanel Margin="0,-10,0,0" xmlns:sys ="clr-namespace:System;assembly=mscorlib">
<StackPanel Margin="0,-10,0,0"
xmlns:sys="clr-namespace:System;assembly=mscorlib"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:PCL;assembly=Plain Craft Launcher 2">
<!--Animations Starts-->
<StackPanel.Triggers>
${animations}
Expand Down
10 changes: 6 additions & 4 deletions Server/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
服务器主模块
'''
import traceback
from flask import Flask, request
from flask import Flask, request, make_response
from Core.project import PageNotFoundError
from Core.logger import Logger
from Server.project_updater import request_update
Expand Down Expand Up @@ -63,12 +63,14 @@ def getpage(alias:str):
alias = alias[:-5] # 这里两个都得保留
try:
if mode == 'json':
result = projapi.get_page_json(alias)
response_dict = projapi.get_page_json(alias)
logger.debug(t("server.request.response.json",page=alias,args=args))
else:
result = projapi.get_page_xaml(alias,args)
response_dict = projapi.get_page_response(alias,args)
logger.debug(t("server.request.response.page",page=alias,args=args))
return result
response = make_response(response_dict['response'])
response.headers['Content-Type'] = response_dict['content-type']
return response
except PageNotFoundError:
logger.debug(t("server.request.response.not_found",page=alias,args=args))
return process_not_found(alias,mode)
Expand Down
11 changes: 7 additions & 4 deletions Server/project_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,13 @@ def get_page_json(self,alias):
if name is None:
name = alias
self.cache[key] = name
return f'{{"Title":"{self.cache[key]}"}}'
return {'response': f'{{"Title":"{self.cache[key]}"}}',
'content-type': 'application/json'}

def get_page_xaml(self,alias,args = None):
'''获取页面xaml文件'''
def get_page_response(self,alias,args = None):
'''获取页面内容'''
if (alias,args) not in self.cache:
self.cache[(alias,args)] = self.project.get_page_xaml(alias,setter = PropertySetter(None,args))
self.cache[(alias,args)] = {
'response':self.project.get_page_xaml(alias,setter = PropertySetter(None,args)),
'content-type' : self.project.get_page_content_type(alias,setter = PropertySetter(None,args)) }
return self.cache[(alias,args)]

0 comments on commit 6f0821a

Please sign in to comment.