Skip to content

Commit

Permalink
加载器改成本地文件
Browse files Browse the repository at this point in the history
  • Loading branch information
xfgryujk committed Jul 29, 2024
1 parent b00ae59 commit 6d7c7b7
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 1 deletion.
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ plugins/
# runtime data
data/*
!data/config.example.ini
!data/loader.html
!data/custom_public/
data/custom_public/*
!data/custom_public/README.txt
Expand Down
11 changes: 11 additions & 0 deletions config.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,8 @@ def _load_app_config(self, config: configparser.ConfigParser):
self.database_url = app_section.get('database_url', self.database_url)
self.tornado_xheaders = app_section.getboolean('tornado_xheaders', self.tornado_xheaders)
self.loader_url = app_section.get('loader_url', self.loader_url)
if self.loader_url == '{local_loader}':
self.loader_url = self._get_local_loader_url()
self.open_browser_at_startup = app_section.getboolean('open_browser_at_startup', self.open_browser_at_startup)
self.enable_upload_file = app_section.getboolean('enable_upload_file', self.enable_upload_file)
self.enable_admin_plugins = app_section.getboolean('enable_admin_plugins', self.enable_admin_plugins)
Expand All @@ -133,6 +135,15 @@ def _load_app_config(self, config: configparser.ConfigParser):
self.translate_max_queue_size = app_section.getint('translate_max_queue_size', self.translate_max_queue_size)
self.translation_cache_size = app_section.getint('translation_cache_size', self.translation_cache_size)

@staticmethod
def _get_local_loader_url():
url = os.path.abspath(os.path.join(DATA_PATH, 'loader.html'))
url = url.replace('\\', '/')
if not url.startswith('/'): # Windows
url = '/' + url
url = 'file://' + url
return url

def _load_translator_configs(self, config: configparser.ConfigParser):
app_section = config['app']
section_names = _str_to_list(app_section.get('translator_configs', ''))
Expand Down
3 changes: 2 additions & 1 deletion data/config.example.ini
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@ tornado_xheaders = false

# 加载器URL,本地使用时加载器可以让你先运行OBS再运行blivechat。如果为空,不使用加载器
# **自建服务器时强烈建议不使用加载器**,否则可能因为混合HTTP和HTTPS等原因加载不出来
# “{local_loader}”表示使用本地加载器文件URL
# Use a loader so that you can run OBS before blivechat. If empty, no loader is used
loader_url = https://xfgryujk.sinacloud.net/blivechat/loader.html
loader_url = {local_loader}

# 启动时打开浏览器
# Open browser at startup
Expand Down
39 changes: 39 additions & 0 deletions data/loader.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>blivechat</title>
</head>

<body>
<p>Loading... Please run blivechat</p>

<script>
function main() {
let params = new URLSearchParams(window.location.search)
let url = params.get('url')
if (!url) {
let element = document.createElement('p')
element.innerText = 'No url specified'
document.body.appendChild(element)
return
}

let timerId = null
function poll() {
window.fetch(url, {mode: 'no-cors'}).then(
() => {
window.clearInterval(timerId)
window.location.href = url
},
() => {}
)
}
timerId = window.setInterval(poll, 1000)
poll()
}

main()
</script>
</body>
</html>

0 comments on commit 6d7c7b7

Please sign in to comment.