Compare commits
6 Commits
Utra-Ver
...
sorted-fas
| Author | SHA1 | Date | |
|---|---|---|---|
| ee93c1c5fc | |||
| e32cb4efe4 | |||
| 055e3d7f42 | |||
| c145545302 | |||
| 9b0416d493 | |||
| d9dad9d6fd |
@@ -1,57 +0,0 @@
|
||||
# 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`).
|
||||
112
app.py
112
app.py
@@ -28,6 +28,7 @@ import tjaf
|
||||
|
||||
from functools import wraps
|
||||
from flask import Flask, g, jsonify, render_template, request, abort, redirect, session, flash, make_response, send_from_directory
|
||||
import mimetypes
|
||||
from flask_caching import Cache
|
||||
from flask_session import Session
|
||||
from flask_wtf.csrf import CSRFProtect, generate_csrf, CSRFError
|
||||
@@ -65,37 +66,30 @@ def get_remote_address() -> str:
|
||||
limiter = Limiter(
|
||||
get_remote_address,
|
||||
app=app,
|
||||
# default_limits=[],
|
||||
# storage_uri="memory://",
|
||||
# Redis
|
||||
storage_uri=os.environ.get("REDIS_URI", "redis://127.0.0.1:6379/"),
|
||||
# Redis cluster
|
||||
# storage_uri="redis+cluster://localhost:7000,localhost:7001,localhost:70002",
|
||||
# Memcached
|
||||
# storage_uri="memcached://localhost:11211",
|
||||
# Memcached Cluster
|
||||
# storage_uri="memcached://localhost:11211,localhost:11212,localhost:11213",
|
||||
# MongoDB
|
||||
# storage_uri="mongodb://localhost:27017",
|
||||
# Etcd
|
||||
# storage_uri="etcd://localhost:2379",
|
||||
strategy="fixed-window", # or "moving-window"
|
||||
strategy="fixed-window",
|
||||
storage_uri=os.environ.get("REDIS_URI") or "memory://",
|
||||
)
|
||||
|
||||
client = MongoClient(host=os.environ.get("TAIKO_WEB_MONGO_HOST") or take_config('MONGO', required=True)['host'])
|
||||
basedir = take_config('BASEDIR') or '/'
|
||||
|
||||
app.secret_key = take_config('SECRET_KEY') or 'change-me'
|
||||
app.config['SESSION_TYPE'] = 'redis'
|
||||
redis_config = take_config('REDIS', required=True)
|
||||
redis_config['CACHE_REDIS_HOST'] = os.environ.get("TAIKO_WEB_REDIS_HOST") or redis_config['CACHE_REDIS_HOST']
|
||||
app.config['SESSION_REDIS'] = Redis(
|
||||
try:
|
||||
_r = Redis(
|
||||
host=redis_config['CACHE_REDIS_HOST'],
|
||||
port=redis_config['CACHE_REDIS_PORT'],
|
||||
password=redis_config['CACHE_REDIS_PASSWORD'],
|
||||
db=redis_config['CACHE_REDIS_DB']
|
||||
)
|
||||
_r.ping()
|
||||
app.config['SESSION_TYPE'] = 'redis'
|
||||
app.config['SESSION_REDIS'] = _r
|
||||
app.cache = Cache(app, config=redis_config)
|
||||
except Exception:
|
||||
app.config['SESSION_TYPE'] = 'filesystem'
|
||||
app.cache = Cache(app, config={'CACHE_TYPE': 'SimpleCache'})
|
||||
sess = Session()
|
||||
sess.init_app(app)
|
||||
#csrf = CSRFProtect(app)
|
||||
@@ -156,11 +150,8 @@ 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 redirect(basedir + 'admin/login')
|
||||
return abort(403)
|
||||
|
||||
user = db.users.find_one({'username': session.get('username')})
|
||||
if user['user_level'] < level:
|
||||
@@ -272,41 +263,6 @@ 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():
|
||||
@@ -318,9 +274,6 @@ def route_admin():
|
||||
def route_admin_songs():
|
||||
songs = sorted(list(db.songs.find({})), key=lambda x: x['id'])
|
||||
categories = db.categories.find({})
|
||||
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())
|
||||
|
||||
@@ -335,9 +288,6 @@ def route_admin_songs_id(id):
|
||||
categories = list(db.categories.find({}))
|
||||
song_skins = list(db.song_skins.find({}))
|
||||
makers = list(db.makers.find({}))
|
||||
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',
|
||||
@@ -415,9 +365,6 @@ def route_admin_songs_id_post(id):
|
||||
if not song:
|
||||
return abort(404)
|
||||
|
||||
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']
|
||||
|
||||
@@ -480,9 +427,6 @@ def route_admin_songs_id_delete(id):
|
||||
@app.route(basedir + 'admin/users')
|
||||
@admin_required(level=50)
|
||||
def route_admin_users():
|
||||
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='')
|
||||
@@ -492,9 +436,6 @@ def route_admin_users():
|
||||
@admin_required(level=50)
|
||||
def route_admin_users_post():
|
||||
admin_name = session.get('username')
|
||||
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
|
||||
|
||||
@@ -778,7 +719,6 @@ 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'})
|
||||
|
||||
@@ -860,7 +800,33 @@ def send_assets(ref):
|
||||
|
||||
@app.route(basedir + "songs/<path:ref>")
|
||||
def send_songs(ref):
|
||||
return cache_wrap(flask.send_from_directory("public/songs", ref), 604800)
|
||||
path = os.path.normpath(os.path.join("public/songs", ref))
|
||||
if not os.path.isfile(path):
|
||||
return abort(404)
|
||||
rng = flask.request.headers.get("Range")
|
||||
if rng and re.match(r"^bytes=\d+-\d*$", rng):
|
||||
size = os.path.getsize(path)
|
||||
m = re.match(r"bytes=(\d+)-(\d*)", rng)
|
||||
start = int(m.group(1))
|
||||
end = int(m.group(2) or size - 1)
|
||||
start = max(0, start)
|
||||
end = min(size - 1, end)
|
||||
with open(path, "rb") as f:
|
||||
f.seek(start)
|
||||
data = f.read(end - start + 1)
|
||||
mime = mimetypes.guess_type(path)[0] or "application/octet-stream"
|
||||
resp = flask.Response(data, 206, mimetype=mime)
|
||||
resp.headers["Content-Range"] = f"bytes {start}-{end}/{size}"
|
||||
resp.headers["Accept-Ranges"] = "bytes"
|
||||
resp.headers["Cache-Control"] = "public, max-age=604800, s-maxage=604800"
|
||||
resp.headers["CDN-Cache-Control"] = "max-age=604800"
|
||||
return resp
|
||||
resp = flask.send_from_directory("public/songs", ref)
|
||||
res = flask.make_response(resp)
|
||||
res.headers["Accept-Ranges"] = "bytes"
|
||||
res.headers["Cache-Control"] = "public, max-age=604800, s-maxage=604800"
|
||||
res.headers["CDN-Cache-Control"] = "max-age=604800"
|
||||
return res
|
||||
|
||||
@app.route(basedir + "manifest.json")
|
||||
def send_manifest():
|
||||
|
||||
Binary file not shown.
@@ -46,22 +46,71 @@ class RemoteFile{
|
||||
}
|
||||
}
|
||||
}
|
||||
arrayBuffer(cancellationToken){
|
||||
arrayBuffer(){
|
||||
return loader.ajax(this.url, request => {
|
||||
request.responseType = "arraybuffer"
|
||||
}, false, cancellationToken)
|
||||
})
|
||||
}
|
||||
read(encoding, cancellationToken){
|
||||
arrayBufferFast(threads){
|
||||
var t = threads || 4
|
||||
var head = new XMLHttpRequest()
|
||||
head.open("HEAD", this.url)
|
||||
var headPromise = pageEvents.load(head).then(() => {
|
||||
if(head.status !== 200){
|
||||
return Promise.reject()
|
||||
}
|
||||
var len = parseInt(head.getResponseHeader("Content-Length"))
|
||||
if(!len || len < 262144){
|
||||
return this.arrayBuffer()
|
||||
}
|
||||
var chunk = Math.ceil(len / t)
|
||||
var ranges = []
|
||||
for(var i = 0; i < t; i++){
|
||||
var start = i * chunk
|
||||
var end = Math.min(len - 1, (i + 1) * chunk - 1)
|
||||
if(start > end){ break }
|
||||
ranges.push([start, end])
|
||||
}
|
||||
var promises = ranges.map(r => {
|
||||
var req = new XMLHttpRequest()
|
||||
req.open("GET", this.url)
|
||||
req.responseType = "arraybuffer"
|
||||
req.setRequestHeader("Range", "bytes=" + r[0] + "-" + r[1])
|
||||
return pageEvents.load(req).then(() => {
|
||||
if(req.status !== 206 && req.status !== 200){
|
||||
return Promise.reject()
|
||||
}
|
||||
return req.response
|
||||
})
|
||||
})
|
||||
return Promise.all(promises).then(parts => {
|
||||
var total = 0
|
||||
for(var i = 0; i < parts.length; i++){
|
||||
total += parts[i].byteLength
|
||||
}
|
||||
var out = new Uint8Array(total)
|
||||
var offset = 0
|
||||
for(var i = 0; i < parts.length; i++){
|
||||
out.set(new Uint8Array(parts[i]), offset)
|
||||
offset += parts[i].byteLength
|
||||
}
|
||||
return out.buffer
|
||||
})
|
||||
})
|
||||
head.send()
|
||||
return headPromise.catch(() => this.arrayBuffer())
|
||||
}
|
||||
read(encoding){
|
||||
if(encoding){
|
||||
return this.blob(cancellationToken).then(blob => readFile(blob, false, encoding))
|
||||
return this.blob().then(blob => readFile(blob, false, encoding))
|
||||
}else{
|
||||
return loader.ajax(this.url, null, false, cancellationToken)
|
||||
return loader.ajax(this.url)
|
||||
}
|
||||
}
|
||||
blob(cancellationToken){
|
||||
blob(){
|
||||
return loader.ajax(this.url, request => {
|
||||
request.responseType = "blob"
|
||||
}, false, cancellationToken)
|
||||
})
|
||||
}
|
||||
}
|
||||
class LocalFile{
|
||||
|
||||
@@ -38,7 +38,6 @@ var assets = {
|
||||
"customsongs.js",
|
||||
"abstractfile.js",
|
||||
"idb.js",
|
||||
"songcacher.js",
|
||||
"plugins.js",
|
||||
"search.js"
|
||||
],
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
class ImportSongs{
|
||||
class ImportSongs{
|
||||
constructor(...args){
|
||||
this.init(...args)
|
||||
}
|
||||
@@ -322,10 +322,6 @@ class ImportSongs{
|
||||
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
|
||||
@@ -333,10 +329,6 @@ class ImportSongs{
|
||||
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
|
||||
|
||||
@@ -55,21 +55,23 @@ class Loader{
|
||||
){
|
||||
reject("Version on the page and config does not match\n(page: " + pageVersion + ",\nconfig: "+ gameConfig._version.commit + ")")
|
||||
}
|
||||
var cssCount = document.styleSheets.length + assets.css.length
|
||||
var loaded = 0
|
||||
var total = assets.css.length
|
||||
assets.css.forEach(name => {
|
||||
var stylesheet = document.createElement("link")
|
||||
stylesheet.rel = "stylesheet"
|
||||
stylesheet.href = "src/css/" + name + this.queryString
|
||||
stylesheet.addEventListener("load", () => {
|
||||
loaded++
|
||||
if(loaded >= total){
|
||||
resolve()
|
||||
}
|
||||
})
|
||||
stylesheet.addEventListener("error", () => {
|
||||
reject("src/css/" + name)
|
||||
})
|
||||
document.head.appendChild(stylesheet)
|
||||
})
|
||||
var checkStyles = () => {
|
||||
if(document.styleSheets.length >= cssCount){
|
||||
resolve()
|
||||
clearInterval(interval)
|
||||
}
|
||||
}
|
||||
var interval = setInterval(checkStyles, 100)
|
||||
checkStyles()
|
||||
}))
|
||||
|
||||
for(var name in assets.fonts){
|
||||
@@ -537,12 +539,10 @@ class Loader{
|
||||
}
|
||||
return css.join("\n")
|
||||
}
|
||||
ajax(url, customRequest, customResponse, cancellationToken){
|
||||
ajax(url, customRequest, customResponse){
|
||||
var request = new XMLHttpRequest()
|
||||
request.open("GET", url)
|
||||
if(cancellationToken){
|
||||
cancellationToken.cancel = () => request.abort()
|
||||
}
|
||||
request.timeout = 15000
|
||||
var promise = pageEvents.load(request)
|
||||
if(!customResponse){
|
||||
promise = promise.then(() => {
|
||||
|
||||
@@ -76,7 +76,11 @@ class PageEvents{
|
||||
}
|
||||
load(target){
|
||||
return new Promise((resolve, reject) => {
|
||||
this.race(target, "load", "error", "abort").then(response => {
|
||||
var timer = setTimeout(() => {
|
||||
reject(["Loading timeout", target])
|
||||
}, 15000)
|
||||
this.race(target, "load", "error", "abort", "timeout").then(response => {
|
||||
clearTimeout(timer)
|
||||
switch(response.type){
|
||||
case "load":
|
||||
return resolve(response.event)
|
||||
@@ -84,6 +88,8 @@ class PageEvents{
|
||||
return reject(["Loading error", target])
|
||||
case "abort":
|
||||
return reject("Loading aborted")
|
||||
case "timeout":
|
||||
return reject(["Loading timeout", target])
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
@@ -57,11 +57,6 @@ class Settings{
|
||||
showLyrics: {
|
||||
type: "toggle",
|
||||
default: true
|
||||
},
|
||||
cacheSongs: {
|
||||
type: "select",
|
||||
options: ["none", "cacheAll", "cacheCategory", "cacheSingle"],
|
||||
default: "none"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -601,13 +596,7 @@ class SettingsView{
|
||||
if(current.type === "language"){
|
||||
value = allStrings[value].name + " (" + value + ")"
|
||||
}else if(current.type === "select" || current.type === "gamepad"){
|
||||
if(name === "cacheSongs"){
|
||||
if(value === "none"){
|
||||
value = strings.none
|
||||
}else{
|
||||
value = strings.cache[value]
|
||||
}
|
||||
}else if(current.options_lang && current.options_lang[value]){
|
||||
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]
|
||||
@@ -685,22 +674,6 @@ 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"){
|
||||
|
||||
@@ -1,82 +0,0 @@
|
||||
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)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2841,13 +2841,6 @@ 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){
|
||||
@@ -2860,19 +2853,19 @@ class SongSelect{
|
||||
songObj = {id: id}
|
||||
if(currentSong.previewMusic){
|
||||
songObj.preview_time = 0
|
||||
var promise = snd.previewGain.load(currentSong.previewMusic, cancellationToken).catch(() => {
|
||||
var promise = snd.previewGain.load(currentSong.previewMusic).catch(() => {
|
||||
songObj.preview_time = prvTime
|
||||
return snd.previewGain.load(currentSong.music, cancellationToken)
|
||||
return snd.previewGain.load(currentSong.music)
|
||||
})
|
||||
}else if(currentSong.unloaded){
|
||||
var promise = this.getUnloaded(this.selectedSong, songObj, currentId, cancellationToken)
|
||||
var promise = this.getUnloaded(this.selectedSong, songObj, currentId)
|
||||
}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, cancellationToken)
|
||||
var promise = snd.previewGain.load(currentSong.music)
|
||||
}else{
|
||||
return
|
||||
}
|
||||
@@ -2926,11 +2919,11 @@ class SongSelect{
|
||||
snd.musicGain.fadeOut(0.4)
|
||||
}
|
||||
}
|
||||
getUnloaded(selectedSong, songObj, currentId, cancellationToken){
|
||||
getUnloaded(selectedSong, songObj, currentId){
|
||||
var currentSong = this.songs[selectedSong]
|
||||
var file = currentSong.chart
|
||||
var importSongs = new ImportSongs(false, assets.otherFiles)
|
||||
return file.read(currentSong.type === "tja" ? "utf-8" : "", cancellationToken).then(data => {
|
||||
return file.read(currentSong.type === "tja" ? "utf-8" : "").then(data => {
|
||||
currentSong.chart = new CachedFile(data, file)
|
||||
return importSongs[currentSong.type === "tja" ? "addTja" : "addOsu"]({
|
||||
file: currentSong.chart,
|
||||
@@ -2947,7 +2940,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, cancellationToken).then(sound => {
|
||||
return snd.previewGain.load(imported.music).then(sound => {
|
||||
imported.sound = sound
|
||||
this.songs[selectedSong].sound = sound
|
||||
return sound.copy()
|
||||
@@ -2972,12 +2965,6 @@ 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,
|
||||
@@ -3120,15 +3107,6 @@ 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]
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
class SoundBuffer{
|
||||
class SoundBuffer{
|
||||
constructor(...args){
|
||||
this.init(...args)
|
||||
}
|
||||
@@ -10,9 +10,10 @@
|
||||
pageEvents.add(window, ["click", "touchend", "keypress"], this.pageClicked.bind(this))
|
||||
this.gainList = []
|
||||
}
|
||||
load(file, gain, cancellationToken){
|
||||
load(file, gain){
|
||||
var decoder = file.name.endsWith(".ogg") ? this.oggDecoder : this.audioDecoder
|
||||
return file.arrayBuffer(cancellationToken).then(response => {
|
||||
var promise = typeof file.arrayBufferFast === "function" ? file.arrayBufferFast(4) : file.arrayBuffer()
|
||||
return promise.then(response => {
|
||||
return new Promise((resolve, reject) => {
|
||||
return decoder(response, resolve, reject)
|
||||
}).catch(error => Promise.reject([error, file.url]))
|
||||
@@ -89,8 +90,8 @@ class SoundGain{
|
||||
}
|
||||
this.setVolume(1)
|
||||
}
|
||||
load(url, cancellationToken){
|
||||
return this.soundBuffer.load(url, this, cancellationToken)
|
||||
load(url){
|
||||
return this.soundBuffer.load(url, this)
|
||||
}
|
||||
convertTime(time, absolute){
|
||||
return this.soundBuffer.convertTime(time, absolute)
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
var languageList = ["ja", "en", "cn", "tw", "ko"]
|
||||
var languageList = ["ja", "en", "cn", "tw", "ko"]
|
||||
var translations = {
|
||||
name: {
|
||||
ja: "日本語",
|
||||
@@ -1235,54 +1235,6 @@ 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",
|
||||
|
||||
@@ -1,27 +0,0 @@
|
||||
<!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>
|
||||
@@ -1,21 +0,0 @@
|
||||
{% 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 %}
|
||||
@@ -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="vLightNova 1.0.0">vLightNova 1.0.0</a>
|
||||
<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>
|
||||
{% else %}
|
||||
<a target="_blank" rel="noopener" id="version-link" class="stroke-sub" alt="vLightNova 1.0.0">vLightNova 1.0.0</a>
|
||||
<a target="_blank" rel="noopener" id="version-link" class="stroke-sub" alt="taiko-web vRAINBOW-BETA4">taiko-web vRAINBOW-BETA4</a>
|
||||
{% endif %}
|
||||
</div>
|
||||
<script src="src/js/browsersupport.js?{{version.commit_short}}"></script>
|
||||
|
||||
22
tjaf.py
22
tjaf.py
@@ -7,8 +7,6 @@ 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]]] = {}
|
||||
@@ -27,12 +25,8 @@ 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":
|
||||
@@ -79,20 +73,8 @@ class Tja:
|
||||
"type": "tja",
|
||||
"title": self.title,
|
||||
"subtitle": self.subtitle,
|
||||
"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,
|
||||
},
|
||||
"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},
|
||||
"courses": courses_out,
|
||||
"enabled": False,
|
||||
"category_id": None,
|
||||
|
||||
@@ -154,25 +154,4 @@
|
||||
"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
40
update.sh
@@ -1,40 +0,0 @@
|
||||
#!/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
|
||||
Reference in New Issue
Block a user