ds2api / entrypoint.sh
luckfun233
feat: 增强管理员登录安全性,添加IP失败计数器以防止字典攻击,限制请求体大小,优化配置文件权限
33b8f8e
Raw
History Blame Contribute Delete
1 kB
#!/bin/bash
set -e
# Fix /data permissions for HF Spaces Persistent Storage
if [ -d /data ]; then
chown -R ds2api:ds2api /data 2>/dev/null || true
fi
# Create config file if not exists or is empty (with empty JSON object)
if [ ! -f /data/config.json ] || [ ! -s /data/config.json ]; then
echo {} > /data/config.json
fi
# Always ensure config.json is writable by ds2api user, even if the file
# was created by a previous container with different ownership (common on
# HuggingFace Spaces persistent storage after rebuild).
chown ds2api:ds2api /data/config.json 2>/dev/null || true
chmod 600 /data/config.json 2>/dev/null || true
# Create chat history file if not exists or is empty
if [ ! -f /data/chat_history.json ] || [ ! -s /data/chat_history.json ]; then
echo {} > /data/chat_history.json
fi
chown ds2api:ds2api /data/chat_history.json 2>/dev/null || true
chmod 644 /data/chat_history.json 2>/dev/null || true
# Start the application as ds2api user
exec gosu ds2api /usr/local/bin/ds2api