v0.3.13: Cookie解密修复 + 配置统一化
修复: - credential.service.ts: 5个getter函数统一解密cookie (解决夸克连接失败) - decryptCookie从extractCookieUid嵌套作用域提到模块顶层 - testCloudConnection/getAndValidateCredential添加解密调用 - 去掉docker run的COOKIE_ENCRYPTION_KEY(回退默认key与旧数据一致) 配置统一化: - config/index.ts新增: corsOrigin/cookieEncryptionKey/logLevel/appVersionFile/uploadDir - main.ts: CORS_ORIGIN/REDIS_URL/uploads改用config而非raw process.env - middleware/cache.ts: REDIS_URL改用config - docker-compose.env: 完整环境变量模板(18个变量)
This commit is contained in:
@@ -23,13 +23,13 @@ export interface CloudConfig {
|
||||
|
||||
// ── Cookie UID Extraction ────────────────────────────────────────
|
||||
|
||||
function extractCookieUid(cookie: string): string {
|
||||
|
||||
function decryptCookie(encrypted: string): string {
|
||||
if (!encrypted) return '';
|
||||
if (!isEncrypted(encrypted)) return encrypted;
|
||||
return decrypt(encrypted);
|
||||
}
|
||||
|
||||
function extractCookieUid(cookie: string): string {
|
||||
if (!cookie) return '';
|
||||
let m = cookie.match(/__uid=([a-zA-Z0-9+/=_-]+)/);
|
||||
if (m) return m[1];
|
||||
@@ -42,22 +42,26 @@ function decryptCookie(encrypted: string): string {
|
||||
|
||||
export function getCloudConfigs(): CloudConfig[] {
|
||||
const db = getDb();
|
||||
return db.prepare(
|
||||
const rows = db.prepare(
|
||||
`SELECT id, cloud_type, cookie, nickname, is_active, storage_used, storage_total,
|
||||
checkin_status, last_checkin_at, checkin_message, consecutive_failures,
|
||||
last_used_at, total_saves, created_at, updated_at, verification_status
|
||||
FROM cloud_configs ORDER BY id ASC`
|
||||
).all() as CloudConfig[];
|
||||
rows.forEach(r => { if (r.cookie) r.cookie = decryptCookie(r.cookie); });
|
||||
return rows;
|
||||
}
|
||||
|
||||
export function getAvailableClouds(): CloudConfig[] {
|
||||
const db = getDb();
|
||||
return db.prepare(
|
||||
const rows = db.prepare(
|
||||
`SELECT id, cloud_type, nickname, is_active, storage_used, storage_total,
|
||||
checkin_status, last_checkin_at, checkin_message, consecutive_failures,
|
||||
last_used_at, total_saves, created_at, updated_at
|
||||
FROM cloud_configs WHERE is_active = 1 ORDER BY id ASC`
|
||||
).all() as CloudConfig[];
|
||||
rows.forEach(r => { if (r.cookie) r.cookie = decryptCookie(r.cookie); });
|
||||
return rows;
|
||||
}
|
||||
|
||||
/** Returns the first active config matching the given cloud type. */
|
||||
@@ -70,6 +74,7 @@ export function getCloudConfigByType(cloudType: string): CloudConfig | undefined
|
||||
FROM cloud_configs WHERE cloud_type = ? AND is_active = 1
|
||||
ORDER BY id ASC LIMIT 1`
|
||||
).get(cloudType) as CloudConfig | undefined;
|
||||
if (cfg && cfg.cookie) cfg.cookie = decryptCookie(cfg.cookie);
|
||||
return cfg;
|
||||
}
|
||||
|
||||
@@ -81,19 +86,22 @@ export function getCloudConfigById(id: number): CloudConfig | undefined {
|
||||
last_used_at, total_saves, created_at, updated_at, verification_status
|
||||
FROM cloud_configs WHERE id = ?`
|
||||
).get(id) as CloudConfig | undefined;
|
||||
if (cfg && cfg.cookie) cfg.cookie = decryptCookie(cfg.cookie);
|
||||
return cfg;
|
||||
}
|
||||
|
||||
/** Returns all active cloud configs (used by save flow for cloud type switching). */
|
||||
export function getActiveCloudConfigs(): CloudConfig[] {
|
||||
const db = getDb();
|
||||
return db.prepare(
|
||||
const rows = db.prepare(
|
||||
`SELECT id, cloud_type, cookie, nickname, is_active, storage_used, storage_total,
|
||||
checkin_status, last_checkin_at, checkin_message, consecutive_failures,
|
||||
last_used_at, total_saves, created_at, updated_at
|
||||
FROM cloud_configs WHERE is_active = 1
|
||||
ORDER BY cloud_type ASC, id ASC`
|
||||
).all() as CloudConfig[];
|
||||
rows.forEach(r => { if (r.cookie) r.cookie = decryptCookie(r.cookie); });
|
||||
return rows;
|
||||
}
|
||||
|
||||
export function saveCloudConfig(data: {
|
||||
@@ -210,6 +218,8 @@ export async function testCloudConnection(id: number): Promise<{
|
||||
return { success: false, message: 'Cookie not configured' };
|
||||
}
|
||||
|
||||
const cookie = decryptCookie(config.cookie);
|
||||
|
||||
try {
|
||||
let valid = false;
|
||||
let nickname = '';
|
||||
@@ -218,7 +228,7 @@ export async function testCloudConnection(id: number): Promise<{
|
||||
|
||||
if (config.cloud_type === 'baidu') {
|
||||
const { BaiduDriver } = require('./drivers/baidu.driver');
|
||||
const driver = new BaiduDriver({ cookie: config.cookie, nickname: config.nickname });
|
||||
const driver = new BaiduDriver({ cookie: cookie, nickname: config.nickname });
|
||||
valid = await driver.validate();
|
||||
if (valid) {
|
||||
const info = await driver.getUserInfo();
|
||||
@@ -231,10 +241,10 @@ export async function testCloudConnection(id: number): Promise<{
|
||||
}
|
||||
} else {
|
||||
const { QuarkDriver } = require('./drivers/quark.driver');
|
||||
const driver = new QuarkDriver({ cookie: config.cookie, nickname: config.nickname });
|
||||
const driver = new QuarkDriver({ cookie: cookie, nickname: config.nickname });
|
||||
valid = await driver.validate();
|
||||
if (valid) {
|
||||
nickname = config.nickname || (await fetchQuarkNickname(config.cookie)) || '夸克网盘';
|
||||
nickname = config.nickname || (await fetchQuarkNickname(cookie)) || '夸克网盘';
|
||||
const storage = await driver.getStorageInfoQuick();
|
||||
storageTotal = (storage.total !== '-' && storage.total !== '0 B') ? storage.total : (config.storage_total || '');
|
||||
}
|
||||
@@ -345,15 +355,17 @@ export async function getAndValidateCredential(cloudType: string): Promise<Crede
|
||||
};
|
||||
}
|
||||
|
||||
const cookie = decryptCookie(config.cookie);
|
||||
|
||||
try {
|
||||
let cookieValid = false;
|
||||
if (cloudType === 'baidu') {
|
||||
const { BaiduDriver } = require('./drivers/baidu.driver');
|
||||
const driver = new BaiduDriver({ cookie: config.cookie, nickname: config.nickname });
|
||||
const driver = new BaiduDriver({ cookie: cookie, nickname: config.nickname });
|
||||
cookieValid = await driver.validate();
|
||||
} else {
|
||||
const { QuarkDriver } = require('./drivers/quark.driver');
|
||||
const driver = new QuarkDriver({ cookie: config.cookie, nickname: config.nickname });
|
||||
const driver = new QuarkDriver({ cookie: cookie, nickname: config.nickname });
|
||||
cookieValid = await driver.validate();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user