Merge pull request #17 from Voya9e/fix/filebrowser-q-v2-config

fix(filebrowser-q): 生成兼容 Quantum v2 的配置并迁移旧配置
This commit is contained in:
kiddin9 authored and GitHub committed 2026-11-13 23:23:30 +08:00
commit 72593548eb
1 file changed
+25 -5
+25 -5
View File
@@ -25,24 +25,44 @@ start_service() {
if [ ! -f "$CONF_PATH" ]; then
mkdir -p "$(dirname "$CONF_PATH")"
cat <<EOF > "$CONF_PATH"
server:
http:
port: $listen_port
database: "$DB_PATH"
server:
database:
path: "$DB_PATH"
sources:
- path: "$root_path"
name: "$root_name"
config:
defaultEnabled: true
auth:
adminUsername: "admin"
adminPassword: "admin"
methods:
password:
enabled: true
adminUsername: "admin"
adminPassword: "admin"
userDefaults:
ui:
locale: "zhCN"
EOF
else
# Migrate config files generated by older package versions.
if grep -q '^ database: "' "$CONF_PATH"; then
sed -i \
-e "s/^server:$/http:\\n port: $listen_port\\nserver:/" \
-e "/^ port:/d" \
-e 's,^ database: "\(.*\)", database:\n path: "\1",' \
-e '/^auth:$/a\
methods:\
password:\
enabled: true' \
-e 's/^ adminUsername:/ adminUsername:/' \
-e 's/^ adminPassword:/ adminPassword:/' \
"$CONF_PATH"
fi
grep -q " name:" "$CONF_PATH" || sed -i "s,.*- path:.*,&\n name: \"\"," "$CONF_PATH"
sed -e "s/ port:.*/ port: $listen_port/" \
sed -e "s/^ port:.*/ port: $listen_port/" \
-e "s, - path:.*, - path: \"$root_path\"," \
-e "s/ name: \".*\"/ name: \"$root_name\"/" \
-i "$CONF_PATH"