Этот коммит содержится в:
mtvpls
2026-01-26 21:14:24 +08:00
родитель 425c4eae67 b3764a7938
Коммит 1c763bee39
3 изменённых файлов: 18 добавлений и 9 удалений
+1 -1
Просмотреть файл
@@ -2,7 +2,7 @@
### Added ### Added
- 新增网络直播功能 - 新增网络直播功能
- 动漫磁力搜索增加蜜柑 - 动漫磁力搜索增加蜜柑
- 弹幕磁力搜索增加动漫花园 - 动漫磁力搜索增加动漫花园
- pansou增加关键词过滤 - pansou增加关键词过滤
- cloudflare workers部署支持 - cloudflare workers部署支持
+1 -1
Просмотреть файл
@@ -16,7 +16,7 @@ export const changelog: ChangelogEntry[] = [
added: [ added: [
"新增网络直播功能", "新增网络直播功能",
"动漫磁力搜索增加蜜柑", "动漫磁力搜索增加蜜柑",
"弹幕磁力搜索增加动漫花园", "动漫磁力搜索增加动漫花园",
"pansou增加关键词过滤", "pansou增加关键词过滤",
"cloudflare workers部署支持", "cloudflare workers部署支持",
], ],
+16 -7
Просмотреть файл
@@ -1,6 +1,15 @@
/* eslint-disable no-console */ /* eslint-disable no-console */
import { getStorage } from './db'; // Lazy import to avoid Edge Runtime issues in middleware
let getStorage: (() => any) | null = null;
async function loadStorage() {
if (!getStorage) {
const db = await import('./db');
getStorage = db.getStorage;
}
return getStorage();
}
// Token 配置 // Token 配置
export const TOKEN_CONFIG = { export const TOKEN_CONFIG = {
@@ -38,7 +47,7 @@ export async function storeRefreshToken(
tokenData: TokenData tokenData: TokenData
): Promise<void> { ): Promise<void> {
const hashKey = `user_tokens:${username}`; const hashKey = `user_tokens:${username}`;
const storage = getStorage(); const storage = await loadStorage();
if (!storage || typeof (storage as any).adapter?.hSet !== 'function') { if (!storage || typeof (storage as any).adapter?.hSet !== 'function') {
console.warn('Redis Hash not supported, skipping token storage'); console.warn('Redis Hash not supported, skipping token storage');
@@ -65,7 +74,7 @@ export async function verifyRefreshToken(
refreshToken: string refreshToken: string
): Promise<boolean> { ): Promise<boolean> {
const hashKey = `user_tokens:${username}`; const hashKey = `user_tokens:${username}`;
const storage = getStorage(); const storage = await loadStorage();
if (!storage || typeof (storage as any).adapter?.hGet !== 'function') { if (!storage || typeof (storage as any).adapter?.hGet !== 'function') {
console.warn('Redis Hash not supported'); console.warn('Redis Hash not supported');
@@ -114,7 +123,7 @@ export async function revokeRefreshToken(
tokenId: string tokenId: string
): Promise<void> { ): Promise<void> {
const hashKey = `user_tokens:${username}`; const hashKey = `user_tokens:${username}`;
const storage = getStorage(); const storage = await loadStorage();
if (!storage || typeof (storage as any).adapter?.hDel !== 'function') { if (!storage || typeof (storage as any).adapter?.hDel !== 'function') {
console.warn('Redis Hash not supported'); console.warn('Redis Hash not supported');
@@ -138,7 +147,7 @@ export async function getUserDevices(username: string): Promise<Array<{
expiresAt: number; expiresAt: number;
}>> { }>> {
const hashKey = `user_tokens:${username}`; const hashKey = `user_tokens:${username}`;
const storage = getStorage(); const storage = await loadStorage();
if (!storage || typeof (storage as any).adapter?.hGetAll !== 'function') { if (!storage || typeof (storage as any).adapter?.hGetAll !== 'function') {
console.warn('Redis Hash not supported'); console.warn('Redis Hash not supported');
@@ -188,7 +197,7 @@ export async function getUserDevices(username: string): Promise<Array<{
// 撤销所有 Token // 撤销所有 Token
export async function revokeAllRefreshTokens(username: string): Promise<void> { export async function revokeAllRefreshTokens(username: string): Promise<void> {
const hashKey = `user_tokens:${username}`; const hashKey = `user_tokens:${username}`;
const storage = getStorage(); const storage = await loadStorage();
if (!storage || typeof (storage as any).adapter?.del !== 'function') { if (!storage || typeof (storage as any).adapter?.del !== 'function') {
console.warn('Redis Hash not supported'); console.warn('Redis Hash not supported');
@@ -206,7 +215,7 @@ export async function revokeAllRefreshTokens(username: string): Promise<void> {
// 清理过期的 Token(定期任务) // 清理过期的 Token(定期任务)
export async function cleanupExpiredTokens(username: string): Promise<number> { export async function cleanupExpiredTokens(username: string): Promise<number> {
const hashKey = `user_tokens:${username}`; const hashKey = `user_tokens:${username}`;
const storage = getStorage(); const storage = await loadStorage();
if (!storage || typeof (storage as any).adapter?.hGetAll !== 'function') { if (!storage || typeof (storage as any).adapter?.hGetAll !== 'function') {
return 0; return 0;