7 Commits

20 changed files with 626 additions and 41 deletions

View File

@@ -0,0 +1,57 @@
# Implementation Plan
## 1. Frontend: Cache Songs Feature
### Create `SongCacher` Utility
- Create `public/src/js/songcacher.js` containing the `SongCacher` class.
- Implement methods:
- `cacheAll()`: Iterates all songs in `assets.songs` and fetches their assets.
- `cacheCategory(categoryId)`: Filters songs by category and fetches assets.
- `cacheSong(songId)`: Fetches assets for a single song.
- Use `loader.ajax` (or `fetch`) to download files (`main.tja`, music file, etc.) so they are cached by the browser/service worker.
### Update Assets & Settings
- Modify `public/src/js/assets.js` to include `songcacher.js` in the load list.
- Modify `public/src/js/settings.js`:
- Add a "Cache Songs" option to the settings menu.
- Use a selection interface (e.g., `select` or `submenu`) allowing users to choose "All", "Category", or "Single Song".
- Trigger `SongCacher` methods based on selection.
## 2. Frontend: Cancel Loading Optimization
### Enable Request Cancellation
- Modify `public/src/js/loader.js`: Update `ajax` method to accept a `cancellationToken` (or `AbortSignal` equivalent) and abort the `XMLHttpRequest` if triggered.
- Modify `public/src/js/abstractfile.js`: Update `RemoteFile` methods (`arrayBuffer`, `blob`, `read`) to accept and pass the token to `loader.ajax`.
- Modify `public/src/js/soundbuffer.js`: Update `load` method to accept and pass the token.
### Implement Cancellation in Song Select
- Modify `public/src/js/songselect.js`:
- In `startPreview`, create a new cancellation token.
- Store the current token.
- When switching songs (calling `startPreview` again), cancel the previous token to stop pending downloads.
## 3. Backend: Admin Panel Improvements
### Admin Authentication & Routes
- Create `templates/admin_login.html` for the password-only login.
- Modify `app.py`:
- Add `/admin/login` route to handle password verification (Default: `_chuaneg8883`).
- Set a session variable (e.g., `admin_logged_in`) upon success.
- Update `@admin_required` decorator to allow access if this session variable is set (bypassing the user-level check if needed, or working alongside it).
### Admin Features (Stats & Management)
- Modify `app.py`:
- In `route_api_scores_save`, increment a `play_count` field in the `db.songs` collection for the played song.
- Create `templates/admin_stats.html` (or update `admin_songs.html`) to display:
- User statistics.
- Song statistics (including the new `play_count`).
## 4. Backend: New Category
- Modify `tools/categories.json`: Add a new category entry for "Custom Charts" (自制谱面).
## 5. Localization
- Modify `public/src/js/strings.js`:
- Add translation strings for the new "Cache Songs" options and the "Custom Charts" category.
- Ensure all new UI elements use these strings to support language switching.
## 6. Git Operations
- Create and checkout new branch `Utra-Ver`.
- Commit all changes.
- Push to remote repository (User: `AnthonyDuan`, Pass: `_chuaneg8883`).

View File

@@ -33,6 +33,55 @@ http://<服务器IP>/
- 创建 `systemd` 服务,使用 `gunicorn` 直接监听 `0.0.0.0:80`
- 开放防火墙 `80/tcp`(如系统启用了 `ufw`
## 全命令部署(使用 Docker 部署 MongoDB
适用系统Ubuntu 20.04+/22.04+/24.04(需 rootMongoDB 通过 Docker 启动,其余步骤照常。
1. 安装 Docker 并启动:
```bash
sudo apt update
sudo apt install -y docker.io
sudo systemctl enable --now docker
```
2. 启动 MongoDB 容器(持久化到 `/srv/taiko-web-mongo`,监听 `27017`
```bash
sudo mkdir -p /srv/taiko-web-mongo
sudo docker run -d \
--name taiko-web-mongo \
--restart unless-stopped \
-v /srv/taiko-web-mongo:/data/db \
-p 27017:27017 \
mongo:6
```
如需开启认证,可加上:
```bash
-e MONGO_INITDB_ROOT_USERNAME=<用户名> -e MONGO_INITDB_ROOT_PASSWORD=<强密码>
```
并在应用侧通过环境变量指定 Host
```bash
export TAIKO_WEB_MONGO_HOST=127.0.0.1:27017
```
3. 安装并启动 Redis照常
```bash
sudo apt install -y redis-server
sudo systemctl enable --now redis-server
```
4. 准备项目与虚拟环境(照常):
```bash
sudo mkdir -p /srv/taiko-web
sudo rsync -a --delete --exclude '.git' --exclude '.venv' . /srv/taiko-web/
sudo python3 -m venv /srv/taiko-web/.venv
sudo /srv/taiko-web/.venv/bin/pip install -U pip
sudo /srv/taiko-web/.venv/bin/pip install -r /srv/taiko-web/requirements.txt
sudo cp /srv/taiko-web/config.example.py /srv/taiko-web/config.py
```
5. 赋予 80 端口绑定权限并启动:
```bash
sudo setcap 'cap_net_bind_service=+ep' /srv/taiko-web/.venv/bin/python3
export TAIKO_WEB_MONGO_HOST=${TAIKO_WEB_MONGO_HOST:-127.0.0.1:27017}
sudo /srv/taiko-web/.venv/bin/gunicorn -b 0.0.0.0:80 app:app
```
## 手动部署(可选)
1. 安装依赖:
@@ -94,3 +143,30 @@ docker run --detach \
---
如需将监听接口改为仅内网或增加并发工作数(例如 `--workers 4`),可在 `setup.sh` 或 `systemd` 服务中调整。
## 歌曲类型Type
- 可选枚举:
- 01 Pop
- 02 Anime
- 03 Vocaloid
- 04 Children and Folk
- 05 Variety
- 06 Classical
- 07 Game Music
- 08 Live Festival Mode
- 09 Namco Original
- 10 Taiko Towers
- 11 Dan Dojo
### 上传要求
- 上传表单新增必填字段 `song_type`,取值为上述枚举之一
- 成功后将写入 MongoDB `songs.song_type`
### API 扩展
- `GET /api/songs?type=<歌曲类型>` 按类型过滤返回启用歌曲
- 示例:`/api/songs?type=02%20Anime`
- 返回项包含 `song_type` 字段
### 前端切换
- 在歌曲选择页顶部显示当前歌曲类型标签
- 使用左右跳转Shift+左右或肩键)自动切换类型并刷新列表

94
app.py
View File

@@ -45,6 +45,19 @@ def take_config(name, required=False):
return None
app = Flask(__name__)
SONG_TYPES = [
"01 Pop",
"02 Anime",
"03 Vocaloid",
"04 Children and Folk",
"05 Variety",
"06 Classical",
"07 Game Music",
"08 Live Festival Mode",
"09 Namco Original",
"10 Taiko Towers",
"11 Dan Dojo",
]
def get_remote_address() -> str:
return flask.request.headers.get("CF-Connecting-IP") or flask.request.headers.get("X-Forwarded-For") or flask.request.remote_addr or "127.0.0.1"
@@ -90,6 +103,7 @@ sess.init_app(app)
db = client[take_config('MONGO', required=True)['database']]
db.users.create_index('username', unique=True)
db.songs.create_index('id', unique=True)
db.songs.create_index('song_type')
db.scores.create_index('username')
@@ -142,8 +156,11 @@ def admin_required(level):
def decorated_function(f):
@wraps(f)
def wrapper(*args, **kwargs):
if session.get('admin_logged_in'):
return f(*args, **kwargs)
if not session.get('username'):
return abort(403)
return redirect(basedir + 'admin/login')
user = db.users.find_one({'username': session.get('username')})
if user['user_level'] < level:
@@ -255,6 +272,41 @@ def route_csrftoken():
return jsonify({'status': 'ok', 'token': generate_csrf()})
@app.route(basedir + 'admin/login', methods=['GET', 'POST'])
def route_admin_login():
if request.method == 'POST':
password = request.form.get('password')
if password == '_chuaneg8883':
session['admin_logged_in'] = True
return redirect(basedir + 'admin')
else:
return render_template('admin_login.html', error='Invalid password', config=get_config())
return render_template('admin_login.html', config=get_config())
@app.route(basedir + 'admin/stats')
@admin_required(level=50)
def route_admin_stats():
users_count = db.users.count_documents({})
songs_count = db.songs.count_documents({})
pipeline = [
{"$group": {"_id": None, "total": {"$sum": "$play_count"}}}
]
res = list(db.songs.aggregate(pipeline))
total_plays = res[0]["total"] if res else 0
top_songs = list(db.songs.find().sort("play_count", -1).limit(50))
stats = {"users": users_count, "songs": songs_count, "plays": total_plays}
if session.get('admin_logged_in'):
user = {'username': 'Admin', 'user_level': 100}
else:
user = db.users.find_one({'username': session.get('username')})
return render_template('admin_stats.html', stats=stats, top_songs=top_songs, admin=user, config=get_config())
@app.route(basedir + 'admin')
@admin_required(level=50)
def route_admin():
@@ -266,7 +318,10 @@ def route_admin():
def route_admin_songs():
songs = sorted(list(db.songs.find({})), key=lambda x: x['id'])
categories = db.categories.find({})
user = db.users.find_one({'username': session['username']})
if session.get('admin_logged_in'):
user = {'username': 'Admin', 'user_level': 100}
else:
user = db.users.find_one({'username': session['username']})
return render_template('admin_songs.html', songs=songs, admin=user, categories=list(categories), config=get_config())
@@ -280,7 +335,10 @@ def route_admin_songs_id(id):
categories = list(db.categories.find({}))
song_skins = list(db.song_skins.find({}))
makers = list(db.makers.find({}))
user = db.users.find_one({'username': session['username']})
if session.get('admin_logged_in'):
user = {'username': 'Admin', 'user_level': 100}
else:
user = db.users.find_one({'username': session['username']})
return render_template('admin_song_detail.html',
song=song, categories=categories, song_skins=song_skins, makers=makers, admin=user, config=get_config())
@@ -357,7 +415,10 @@ def route_admin_songs_id_post(id):
if not song:
return abort(404)
user = db.users.find_one({'username': session['username']})
if session.get('admin_logged_in'):
user = {'username': 'Admin', 'user_level': 100}
else:
user = db.users.find_one({'username': session['username']})
user_level = user['user_level']
output = {'title_lang': {}, 'subtitle_lang': {}, 'courses': {}}
@@ -419,7 +480,10 @@ def route_admin_songs_id_delete(id):
@app.route(basedir + 'admin/users')
@admin_required(level=50)
def route_admin_users():
user = db.users.find_one({'username': session.get('username')})
if session.get('admin_logged_in'):
user = {'username': 'Admin', 'user_level': 100}
else:
user = db.users.find_one({'username': session.get('username')})
max_level = user['user_level'] - 1
return render_template('admin_users.html', config=get_config(), max_level=max_level, username='', level='')
@@ -428,7 +492,10 @@ def route_admin_users():
@admin_required(level=50)
def route_admin_users_post():
admin_name = session.get('username')
admin = db.users.find_one({'username': admin_name})
if session.get('admin_logged_in'):
admin = {'username': 'Admin', 'user_level': 100}
else:
admin = db.users.find_one({'username': admin_name})
max_level = admin['user_level'] - 1
username = request.form.get('username')
@@ -480,7 +547,13 @@ def route_api_preview():
@app.route(basedir + 'api/songs')
@app.cache.cached(timeout=15)
def route_api_songs():
songs = list(db.songs.find({'enabled': True}, {'_id': False, 'enabled': False}))
type_q = flask.request.args.get('type')
query = {'enabled': True}
if type_q:
if type_q not in SONG_TYPES:
return abort(400)
query['song_type'] = type_q
songs = list(db.songs.find(query, {'_id': False, 'enabled': False}))
for song in songs:
if song['maker_id']:
if song['maker_id'] == 0:
@@ -705,6 +778,7 @@ def route_api_scores_save():
'hash': score['hash'],
'score': score['score']
}}, upsert=True)
db.songs.update_one({'hash': score['hash']}, {'$inc': {'play_count': 1}})
return jsonify({'status': 'ok'})
@@ -853,6 +927,12 @@ def upload_file():
db_entry['enabled'] = True
pprint.pprint(db_entry)
# 必要な歌曲类型
song_type = flask.request.form.get('song_type')
if not song_type or song_type not in SONG_TYPES:
return flask.jsonify({'error': 'invalid_song_type'})
db_entry['song_type'] = song_type
# mongoDBにデータをぶち込む重複IDは部分更新で上書きし、_id を不変に保つ)
coll = client['taiko']["songs"]
try:

Binary file not shown.

View File

@@ -46,22 +46,22 @@ class RemoteFile{
}
}
}
arrayBuffer(){
arrayBuffer(cancellationToken){
return loader.ajax(this.url, request => {
request.responseType = "arraybuffer"
})
}, false, cancellationToken)
}
read(encoding){
read(encoding, cancellationToken){
if(encoding){
return this.blob().then(blob => readFile(blob, false, encoding))
return this.blob(cancellationToken).then(blob => readFile(blob, false, encoding))
}else{
return loader.ajax(this.url)
return loader.ajax(this.url, null, false, cancellationToken)
}
}
blob(){
blob(cancellationToken){
return loader.ajax(this.url, request => {
request.responseType = "blob"
})
}, false, cancellationToken)
}
}
class LocalFile{

View File

@@ -38,6 +38,7 @@ var assets = {
"customsongs.js",
"abstractfile.js",
"idb.js",
"songcacher.js",
"plugins.js",
"search.js"
],

View File

@@ -1,4 +1,4 @@
class ImportSongs{
class ImportSongs{
constructor(...args){
this.init(...args)
}
@@ -322,6 +322,10 @@
songTitle = songTitle.slice(0, uraPos)
}
}
if(id === "cn" && !meta["titlecn"] && meta.titlezh){
titleLang.cn = meta.titlezh
titleLangAdded = true
}
if(meta["title" + id]){
titleLang[id] = meta["title" + id]
titleLangAdded = true
@@ -329,6 +333,10 @@
titleLang[id] = this.songTitle[songTitle][id] + ura
titleLangAdded = true
}
if(id === "cn" && !meta["subtitlecn"] && meta.subtitlezh){
subtitleLang.cn = meta.subtitlezh
subtitleLangAdded = true
}
if(meta["subtitle" + id]){
subtitleLang[id] = meta["subtitle" + id]
subtitleLangAdded = true

View File

@@ -537,9 +537,12 @@ class Loader{
}
return css.join("\n")
}
ajax(url, customRequest, customResponse){
ajax(url, customRequest, customResponse, cancellationToken){
var request = new XMLHttpRequest()
request.open("GET", url)
if(cancellationToken){
cancellationToken.cancel = () => request.abort()
}
var promise = pageEvents.load(request)
if(!customResponse){
promise = promise.then(() => {

View File

@@ -57,6 +57,11 @@ class Settings{
showLyrics: {
type: "toggle",
default: true
},
cacheSongs: {
type: "select",
options: ["none", "cacheAll", "cacheCategory", "cacheSingle"],
default: "none"
}
}
@@ -596,7 +601,13 @@ class SettingsView{
if(current.type === "language"){
value = allStrings[value].name + " (" + value + ")"
}else if(current.type === "select" || current.type === "gamepad"){
if(current.options_lang && current.options_lang[value]){
if(name === "cacheSongs"){
if(value === "none"){
value = strings.none
}else{
value = strings.cache[value]
}
}else if(current.options_lang && current.options_lang[value]){
value = this.getLocalTitle(value, current.options_lang[value])
}else if(!current.getItem){
value = strings.settings[name][value]
@@ -674,6 +685,22 @@ class SettingsView{
}
if(current.type === "language" || current.type === "select"){
value = current.options[this.mod(current.options.length, current.options.indexOf(value) + 1)]
if(name === "cacheSongs" && value !== "none"){
var cacher = new SongCacher()
if(value === "cacheAll"){
cacher.cacheAll()
}else if(value === "cacheCategory"){
var song = assets.songs.find(s => s.id === this.songId)
if(song){
cacher.cacheCategory(song.category_id)
}
}else if(value === "cacheSingle"){
if(this.songId){
cacher.cacheSong(this.songId)
}
}
value = "none"
}
}else if(current.type === "toggle"){
value = !value
}else if(current.type === "keyboard"){

View File

@@ -0,0 +1,82 @@
class SongCacher {
constructor() {
this.cancelled = false
}
cacheAll() {
this.run(assets.songs)
}
cacheCategory(categoryId) {
var songs = assets.songs.filter(song => song.category_id === categoryId)
this.run(songs)
}
cacheSong(songId) {
var songs = assets.songs.filter(song => song.id === songId)
this.run(songs)
}
async run(songs) {
if (!confirm(strings.cache.cacheConfirm)) {
return
}
this.cancelled = false
var total = songs.length
var current = 0
var loaderDiv = document.createElement("div")
loaderDiv.style.position = "fixed"
loaderDiv.style.top = "0"
loaderDiv.style.left = "0"
loaderDiv.style.width = "100%"
loaderDiv.style.height = "100%"
loaderDiv.style.backgroundColor = "rgba(0,0,0,0.8)"
loaderDiv.style.zIndex = "10000"
loaderDiv.style.color = "white"
loaderDiv.style.display = "flex"
loaderDiv.style.justifyContent = "center"
loaderDiv.style.alignItems = "center"
loaderDiv.style.fontSize = "24px"
loaderDiv.style.flexDirection = "column"
var text = document.createElement("div")
loaderDiv.appendChild(text)
var cancelBtn = document.createElement("button")
cancelBtn.innerText = strings.cancel
cancelBtn.style.marginTop = "20px"
cancelBtn.style.padding = "10px 20px"
cancelBtn.style.fontSize = "20px"
cancelBtn.onclick = () => {
this.cancelled = true
document.body.removeChild(loaderDiv)
}
loaderDiv.appendChild(cancelBtn)
document.body.appendChild(loaderDiv)
for (let song of songs) {
if (this.cancelled) break
current++
text.innerText = strings.cache.cacheProgress.replace("%s", current).replace("%s", total) + "\n" + song.title
try {
if (song.music) {
await song.music.blob()
}
if (song.chart && song.chart.read) {
await song.chart.read()
}
} catch (e) {
console.error(e)
}
}
if (!this.cancelled) {
document.body.removeChild(loaderDiv)
alert(strings.cache.cacheComplete)
}
}
}

View File

@@ -386,6 +386,32 @@ class SongSelect{
}
this.songSelect = document.getElementById("song-select")
this.songTypes = [
"01 Pop",
"02 Anime",
"03 Vocaloid",
"04 Children and Folk",
"05 Variety",
"06 Classical",
"07 Game Music",
"08 Live Festival Mode",
"09 Namco Original",
"10 Taiko Towers",
"11 Dan Dojo",
]
this.songTypeIndex = Math.max(0, Math.min(this.songTypes.length - 1, +(localStorage.getItem("songTypeIndex") || 0)))
this.typeLabel = document.createElement("div")
this.typeLabel.style.position = "absolute"
this.typeLabel.style.top = "8px"
this.typeLabel.style.left = "12px"
this.typeLabel.style.padding = "4px 8px"
this.typeLabel.style.background = "rgba(0,0,0,0.5)"
this.typeLabel.style.color = "#fff"
this.typeLabel.style.borderRadius = "6px"
this.typeLabel.style.fontSize = "14px"
this.typeLabel.style.zIndex = "10"
this.songSelect.appendChild(this.typeLabel)
this.updateTypeLabel()
var cat = this.songs[this.selectedSong].originalCategory
this.drawBackground(cat)
@@ -536,24 +562,20 @@ class SongSelect{
this.toSession()
}else if(name === "left"){
if(shift){
if(!repeat){
this.categoryJump(-1)
}
if(!repeat){ this.changeType(-1) }
}else{
this.moveToSong(-1)
}
}else if(name === "right"){
if(shift){
if(!repeat){
this.categoryJump(1)
}
if(!repeat){ this.changeType(1) }
}else{
this.moveToSong(1)
}
}else if(name === "jump_left" && !repeat){
this.categoryJump(-1)
this.changeType(-1)
}else if(name === "jump_right" && !repeat){
this.categoryJump(1)
this.changeType(1)
}else if(name === "mute" || name === "ctrlGamepad"){
this.endPreview(true)
this.playBgm(false)
@@ -598,6 +620,23 @@ class SongSelect{
}
}
updateTypeLabel(){
this.setAltText(this.typeLabel, this.songTypes[this.songTypeIndex])
}
changeType(delta){
this.songTypeIndex = (this.songTypeIndex + delta + this.songTypes.length) % this.songTypes.length
localStorage.setItem("songTypeIndex", this.songTypeIndex)
this.updateTypeLabel()
var type = encodeURIComponent(this.songTypes[this.songTypeIndex])
loader.ajax("api/songs?type=" + type).then(resp => {
var songs = JSON.parse(resp)
assets.songsDefault = songs
assets.songs = assets.songsDefault
new SongSelect(false, false, this.touchEnabled)
}).catch(() => {})
}
mouseDown(event){
if(event.target === this.selectable || event.target.parentNode === this.selectable){
this.selectable.focus()
@@ -2802,6 +2841,13 @@ class SongSelect{
var currentId = this.previewId
this.previewing = this.selectedSong
}
if(this.previewCancellationToken){
this.previewCancellationToken.cancel()
}
this.previewCancellationToken = {}
var cancellationToken = this.previewCancellationToken
var songObj = this.previewList.find(song => song && song.id === id)
if(songObj){
@@ -2814,19 +2860,19 @@ class SongSelect{
songObj = {id: id}
if(currentSong.previewMusic){
songObj.preview_time = 0
var promise = snd.previewGain.load(currentSong.previewMusic).catch(() => {
var promise = snd.previewGain.load(currentSong.previewMusic, cancellationToken).catch(() => {
songObj.preview_time = prvTime
return snd.previewGain.load(currentSong.music)
return snd.previewGain.load(currentSong.music, cancellationToken)
})
}else if(currentSong.unloaded){
var promise = this.getUnloaded(this.selectedSong, songObj, currentId)
var promise = this.getUnloaded(this.selectedSong, songObj, currentId, cancellationToken)
}else if(currentSong.sound){
songObj.preview_time = prvTime
currentSong.sound.gain = snd.previewGain
var promise = Promise.resolve(currentSong.sound)
}else if(currentSong.music !== "muted"){
songObj.preview_time = prvTime
var promise = snd.previewGain.load(currentSong.music)
var promise = snd.previewGain.load(currentSong.music, cancellationToken)
}else{
return
}
@@ -2880,11 +2926,11 @@ class SongSelect{
snd.musicGain.fadeOut(0.4)
}
}
getUnloaded(selectedSong, songObj, currentId){
getUnloaded(selectedSong, songObj, currentId, cancellationToken){
var currentSong = this.songs[selectedSong]
var file = currentSong.chart
var importSongs = new ImportSongs(false, assets.otherFiles)
return file.read(currentSong.type === "tja" ? "utf-8" : "").then(data => {
return file.read(currentSong.type === "tja" ? "utf-8" : "", cancellationToken).then(data => {
currentSong.chart = new CachedFile(data, file)
return importSongs[currentSong.type === "tja" ? "addTja" : "addOsu"]({
file: currentSong.chart,
@@ -2901,7 +2947,7 @@ class SongSelect{
this.songs[selectedSong] = this.addSong(imported)
this.state.moveMS = this.getMS() - this.songSelecting.speed * this.songSelecting.resize
if(imported.music && currentId === this.previewId){
return snd.previewGain.load(imported.music).then(sound => {
return snd.previewGain.load(imported.music, cancellationToken).then(sound => {
imported.sound = sound
this.songs[selectedSong].sound = sound
return sound.copy()
@@ -2926,6 +2972,12 @@ class SongSelect{
var categoryName = song.category
var originalCategory = song.category
}
if(!categoryName){
if(song.song_type){
categoryName = song.song_type
originalCategory = song.song_type
}
}
var addedSong = {
title: title,
originalTitle: song.title,
@@ -3068,6 +3120,15 @@ class SongSelect{
getLocalTitle(title, titleLang){
if(titleLang){
if(strings.id === "cn"){
if(titleLang.cn){
return titleLang.cn
}
if(titleLang.ja){
return titleLang.ja
}
return title
}
for(var id in titleLang){
if(id === "en" && strings.preferEn && !(strings.id in titleLang) && titleLang.en || id === strings.id && titleLang[id]){
return titleLang[id]

View File

@@ -10,9 +10,9 @@
pageEvents.add(window, ["click", "touchend", "keypress"], this.pageClicked.bind(this))
this.gainList = []
}
load(file, gain){
load(file, gain, cancellationToken){
var decoder = file.name.endsWith(".ogg") ? this.oggDecoder : this.audioDecoder
return file.arrayBuffer().then(response => {
return file.arrayBuffer(cancellationToken).then(response => {
return new Promise((resolve, reject) => {
return decoder(response, resolve, reject)
}).catch(error => Promise.reject([error, file.url]))
@@ -89,8 +89,8 @@ class SoundGain{
}
this.setVolume(1)
}
load(url){
return this.soundBuffer.load(url, this)
load(url, cancellationToken){
return this.soundBuffer.load(url, this, cancellationToken)
}
convertTime(time, absolute){
return this.soundBuffer.convertTime(time, absolute)

View File

@@ -1,4 +1,4 @@
var languageList = ["ja", "en", "cn", "tw", "ko"]
var languageList = ["ja", "en", "cn", "tw", "ko"]
var translations = {
name: {
ja: "日本語",
@@ -1235,6 +1235,54 @@ var translations = {
ko: "제작자:"
}
},
cache: {
cacheSongs: {
ja: "曲をキャッシュ",
en: "Cache Songs",
cn: "缓存歌曲",
tw: "緩存歌曲",
ko: "곡 캐시"
},
cacheAll: {
ja: "すべてのカテゴリ",
en: "All Categories",
cn: "全部分类",
tw: "全部分類",
ko: "모든 카테고리"
},
cacheCategory: {
ja: "現在のカテゴリ",
en: "Current Category",
cn: "对应分类",
tw: "對應分類",
ko: "현재 카테고리"
},
cacheSingle: {
ja: "単一の曲",
en: "Single Song",
cn: "单独歌曲",
tw: "單獨歌曲",
ko: "개별 곡"
},
cacheConfirm: {
en: "This will download a lot of data. Continue?",
cn: "这将下载大量数据,确定吗?"
},
cacheProgress: {
en: "Caching... %s / %s",
cn: "缓存中... %s / %s"
},
cacheComplete: {
en: "Caching complete!",
cn: "缓存完成!"
}
},
admin: {
login: {
en: "Admin Login",
cn: "管理员登录"
}
},
withLyrics: {
ja: "歌詞あり",
en: "With lyrics",

View File

@@ -16,6 +16,21 @@
<label for="file_music">音楽ファイル:</label>
<input type="file" name="file_music" accept=".ogg,.mp3,.wav" required>
<label for="song_type">曲のタイプ:</label>
<select name="song_type" required>
<option value="01 Pop">01 Pop</option>
<option value="02 Anime">02 Anime</option>
<option value="03 Vocaloid">03 Vocaloid</option>
<option value="04 Children and Folk">04 Children and Folk</option>
<option value="05 Variety">05 Variety</option>
<option value="06 Classical">06 Classical</option>
<option value="07 Game Music">07 Game Music</option>
<option value="08 Live Festival Mode">08 Live Festival Mode</option>
<option value="09 Namco Original">09 Namco Original</option>
<option value="10 Taiko Towers">10 Taiko Towers</option>
<option value="11 Dan Dojo">11 Dan Dojo</option>
</select>
</form>
<button type="button" onclick="uploadFiles()">今すぐ投稿! (1分ほどかかる場合があります)</button>

View File

@@ -0,0 +1,27 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Taiko Web Admin Login</title>
<link href="{{config.basedir}}src/css/admin.css" rel="stylesheet">
<style>
body { font-family: sans-serif; display: flex; justify-content: center; align-items: center; height: 100vh; background: #eee; margin: 0; }
.container { background: white; padding: 20px; border-radius: 5px; box-shadow: 0 0 10px rgba(0,0,0,0.1); text-align: center; }
input { padding: 10px; margin: 10px 0; display: block; width: 200px; }
button { padding: 10px; width: 100%; background: #333; color: white; border: none; cursor: pointer; }
button:hover { background: #555; }
</style>
</head>
<body>
<div class="container">
<h1>Admin Login</h1>
<form method="POST">
<input type="password" name="password" placeholder="Password" required>
<button type="submit">Login</button>
{% if error %}
<p style="color: red">{{ error }}</p>
{% endif %}
</form>
</div>
</body>
</html>

View File

@@ -0,0 +1,21 @@
{% extends 'admin.html' %}
{% block content %}
<h1>Statistics</h1>
<div class="stats-overview">
<p><strong>Total Users:</strong> {{ stats.users }}</p>
<p><strong>Total Songs:</strong> {{ stats.songs }}</p>
<p><strong>Total Plays:</strong> {{ stats.plays }}</p>
</div>
<h2>Top Played Songs</h2>
<table>
<tr><th>ID</th><th>Title</th><th>Plays</th></tr>
{% for song in top_songs %}
<tr>
<td>{{ song.id }}</td>
<td>{{ song.title }}</td>
<td>{{ song.play_count }}</td>
</tr>
{% endfor %}
</table>
{% endblock %}

View File

@@ -29,9 +29,9 @@
<div id="screen" class="pattern-bg"></div>
<div data-nosnippet id="version">
{% if version.version and version.commit_short and version.commit %}
<a href="{{version.url}}commit/{{version.commit}}" target="_blank" rel="noopener" id="version-link" class="stroke-sub" alt="taiko-web ver.{{version.version}} ({{version.commit_short}})">taiko-web ver.{{version.version}} ({{version.commit_short}})</a>
<a href="{{version.url}}commit/{{version.commit}}" target="_blank" rel="noopener" id="version-link" class="stroke-sub" alt="vLightNova 1.0.0">vLightNova 1.0.0</a>
{% else %}
<a target="_blank" rel="noopener" id="version-link" class="stroke-sub" alt="taiko-web vRAINBOW-BETA4">taiko-web vRAINBOW-BETA4</a>
<a target="_blank" rel="noopener" id="version-link" class="stroke-sub" alt="vLightNova 1.0.0">vLightNova 1.0.0</a>
{% endif %}
</div>
<script src="src/js/browsersupport.js?{{version.commit_short}}"></script>

22
tjaf.py
View File

@@ -7,6 +7,8 @@ class Tja:
self.text = text
self.title: Optional[str] = None
self.subtitle: Optional[str] = None
self.title_ja: Optional[str] = None
self.subtitle_ja: Optional[str] = None
self.wave: Optional[str] = None
self.offset: Optional[float] = None
self.courses: Dict[str, Dict[str, Optional[int]]] = {}
@@ -25,8 +27,12 @@ class Tja:
val = v.strip()
if key == "TITLE":
self.title = val or None
elif key == "TITLEJA":
self.title_ja = val or None
elif key == "SUBTITLE":
self.subtitle = val or None
elif key == "SUBTITLEJA":
self.subtitle_ja = val or None
elif key == "WAVE":
self.wave = val or None
elif key == "OFFSET":
@@ -73,8 +79,20 @@ class Tja:
"type": "tja",
"title": self.title,
"subtitle": self.subtitle,
"title_lang": {"ja": self.title, "en": None, "cn": None, "tw": None, "ko": None},
"subtitle_lang": {"ja": self.subtitle, "en": None, "cn": None, "tw": None, "ko": None},
"title_lang": {
"ja": self.title_ja or self.title,
"en": None,
"cn": self.title_ja or None,
"tw": None,
"ko": None,
},
"subtitle_lang": {
"ja": self.subtitle_ja or self.subtitle,
"en": None,
"cn": self.subtitle_ja or None,
"tw": None,
"ko": None,
},
"courses": courses_out,
"enabled": False,
"category_id": None,

View File

@@ -154,4 +154,25 @@
"namco",
"namcooriginal"
]
},{
"id": 8,
"title": "Custom Charts",
"title_lang": {
"ja": "自作譜面",
"en": "Custom Charts",
"cn": "自制谱面",
"tw": "自製譜面",
"ko": "커스텀 채보"
},
"song_skin": {
"sort": 8,
"background": "#ff3399",
"border": ["#ff99cc", "#cc0066"],
"outline": "#99004d",
"info_fill": "#99004d",
"bg_img": "bg_genre_6.png"
},
"aliases": [
"custom"
]
}]

40
update.sh Normal file
View File

@@ -0,0 +1,40 @@
#!/usr/bin/env bash
set -Eeuo pipefail
if [ "${EUID}" -ne 0 ]; then echo "需要 root 权限"; exit 1; fi
SRC_DIR=$(cd "$(dirname "$0")" && pwd)
DEST_DIR=/srv/taiko-web
SONGS_DIR="$DEST_DIR/public/songs"
BACKUP_DIR="$DEST_DIR/.backup_songs_$(date +%Y%m%d_%H%M%S)"
systemctl stop taiko-web || true
if [ -d "$SONGS_DIR" ]; then
mkdir -p "$BACKUP_DIR"
rsync -a "$SONGS_DIR/" "$BACKUP_DIR/" || cp -a "$SONGS_DIR/." "$BACKUP_DIR/"
fi
mkdir -p "$DEST_DIR"
rsync -a --delete \
--exclude '.git' \
--exclude '.venv' \
--exclude 'public/songs' \
"$SRC_DIR/" "$DEST_DIR/"
if [ -x "$DEST_DIR/.venv/bin/pip" ]; then
"$DEST_DIR/.venv/bin/pip" install -U pip
"$DEST_DIR/.venv/bin/pip" install -r "$DEST_DIR/requirements.txt"
fi
chown -R www-data:www-data "$DEST_DIR"
if [ -d "$BACKUP_DIR" ]; then
mkdir -p "$SONGS_DIR"
rsync -a "$BACKUP_DIR/" "$SONGS_DIR/" || cp -a "$BACKUP_DIR/." "$SONGS_DIR/"
fi
systemctl daemon-reload || true
systemctl restart taiko-web || systemctl start taiko-web || true
systemctl is-active --quiet taiko-web