增加剧集更新检查

This commit is contained in:
mtvpls
2025-12-18 23:44:14 +08:00
parent 0ae5923b4b
commit c60e25ded6
12 changed files with 864 additions and 9 deletions
+81
View File
@@ -415,6 +415,87 @@ export class UpstashRedisStorage implements IStorage {
async deleteGlobalValue(key: string): Promise<void> {
await withRetry(() => this.client.del(this.globalValueKey(key)));
}
// ---------- 通知相关 ----------
private notificationsKey(userName: string) {
return `u:${userName}:notifications`;
}
private lastFavoriteCheckKey(userName: string) {
return `u:${userName}:last_fav_check`;
}
async getNotifications(userName: string): Promise<import('./types').Notification[]> {
const val = await withRetry(() =>
this.client.get(this.notificationsKey(userName))
);
return val ? (val as import('./types').Notification[]) : [];
}
async addNotification(
userName: string,
notification: import('./types').Notification
): Promise<void> {
const notifications = await this.getNotifications(userName);
notifications.unshift(notification); // 新通知放在最前面
// 限制通知数量,最多保留100条
if (notifications.length > 100) {
notifications.splice(100);
}
await withRetry(() =>
this.client.set(this.notificationsKey(userName), notifications)
);
}
async markNotificationAsRead(
userName: string,
notificationId: string
): Promise<void> {
const notifications = await this.getNotifications(userName);
const notification = notifications.find((n) => n.id === notificationId);
if (notification) {
notification.read = true;
await withRetry(() =>
this.client.set(this.notificationsKey(userName), notifications)
);
}
}
async deleteNotification(
userName: string,
notificationId: string
): Promise<void> {
const notifications = await this.getNotifications(userName);
const filtered = notifications.filter((n) => n.id !== notificationId);
await withRetry(() =>
this.client.set(this.notificationsKey(userName), filtered)
);
}
async clearAllNotifications(userName: string): Promise<void> {
await withRetry(() => this.client.del(this.notificationsKey(userName)));
}
async getUnreadNotificationCount(userName: string): Promise<number> {
const notifications = await this.getNotifications(userName);
return notifications.filter((n) => !n.read).length;
}
async getLastFavoriteCheckTime(userName: string): Promise<number> {
const val = await withRetry(() =>
this.client.get(this.lastFavoriteCheckKey(userName))
);
return val ? (val as number) : 0;
}
async setLastFavoriteCheckTime(
userName: string,
timestamp: number
): Promise<void> {
await withRetry(() =>
this.client.set(this.lastFavoriteCheckKey(userName), timestamp)
);
}
}
// 单例 Upstash Redis 客户端