fix: 完善成人内容过滤功能的部署兼容性

- 为用户设置API添加Edge Runtime配置确保部署兼容性
- 完善所有存储后端的用户设置方法实现
- 为D1数据库添加user_settings表迁移脚本
- 修复TypeScript类型错误和构建兼容性
- 所有25个API路由现在都正确配置了Edge Runtime
- 确保Docker、Cloudflare Pages等各平台部署正常运行
This commit is contained in:
katelya
2025-09-04 21:25:45 +08:00
parent 86ebbb2cf6
commit b06665788f
6 changed files with 161 additions and 3 deletions
+42
View File
@@ -329,6 +329,48 @@ export class UpstashRedisStorage implements IStorage {
await this.client.srem(this.skipConfigsKey(userName), key);
});
}
// ---------- 用户设置 ----------
private userSettingsKey(userName: string) {
return `u:${userName}:settings`;
}
async getUserSettings(userName: string): Promise<UserSettings | null> {
const val = await withRetry(() =>
this.client.get(this.userSettingsKey(userName))
);
return val ? (val as UserSettings) : null;
}
async setUserSettings(
userName: string,
settings: UserSettings
): Promise<void> {
await withRetry(() =>
this.client.set(this.userSettingsKey(userName), settings)
);
}
async updateUserSettings(
userName: string,
settings: Partial<UserSettings>
): Promise<void> {
const current = await this.getUserSettings(userName);
const defaultSettings: UserSettings = {
filter_adult_content: true,
theme: 'auto',
language: 'zh-CN',
auto_play: false,
video_quality: 'auto'
};
const updated: UserSettings = {
...defaultSettings,
...current,
...settings,
filter_adult_content: settings.filter_adult_content ?? current?.filter_adult_content ?? true
};
await this.setUserSettings(userName, updated);
}
}
// 单例 Upstash Redis 客户端