revert: 去掉资源历史查询逻辑, 保留纯IP+is_primary分配
- 网盘分享按新资源奖励机制, 不需追资源转存历史 - getAndValidateCredential 去掉 shareUrl 参数 - 保留 save_records.config_id 字段(仅用于日志排查)
This commit is contained in:
@@ -141,7 +141,7 @@ async function doSaveFromShare(shareUrl: string, cloudType: string, sourceTitle?
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ── Unified credential validation ──
|
// ── Unified credential validation ──
|
||||||
const credential = await getAndValidateCredential(cloudType, ipAddress, shareUrl);
|
const credential = await getAndValidateCredential(cloudType, ipAddress);
|
||||||
if (!credential.valid || !credential.config) {
|
if (!credential.valid || !credential.config) {
|
||||||
return { success: false, message: credential.message };
|
return { success: false, message: credential.message };
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -423,37 +423,12 @@ export interface CredentialValidationResult {
|
|||||||
*
|
*
|
||||||
* Reference: search-ucmao get_and_validate_credential() pattern.
|
* Reference: search-ucmao get_and_validate_credential() pattern.
|
||||||
*/
|
*/
|
||||||
export async function getAndValidateCredential(cloudType: string, ipAddress?: string, shareUrl?: string): Promise<CredentialValidationResult> {
|
export async function getAndValidateCredential(cloudType: string, ipAddress?: string): Promise<CredentialValidationResult> {
|
||||||
const db = getDb();
|
const db = getDb();
|
||||||
|
|
||||||
let config: CloudConfig | undefined;
|
let config: CloudConfig | undefined;
|
||||||
|
|
||||||
// ── Resource history lookup: if this share URL was saved before, reuse that account ──
|
|
||||||
if (shareUrl) {
|
|
||||||
const historyRecord = db.prepare(
|
|
||||||
`SELECT config_id, target_cloud, folder_name FROM save_records
|
|
||||||
WHERE share_url = ? AND target_cloud = ? AND status IN ('success', 'reused')
|
|
||||||
ORDER BY id DESC LIMIT 1`
|
|
||||||
).get(shareUrl, cloudType) as { config_id: number; target_cloud: string; folder_name: string } | undefined;
|
|
||||||
|
|
||||||
if (historyRecord) {
|
|
||||||
// Resource was previously saved — reuse the exact same config if still healthy
|
|
||||||
if (historyRecord.config_id) {
|
|
||||||
config = db.prepare(
|
|
||||||
`SELECT * FROM cloud_configs WHERE id = ? AND is_active = 1 AND consecutive_failures < 5`
|
|
||||||
).get(historyRecord.config_id) as CloudConfig | undefined;
|
|
||||||
}
|
|
||||||
if (!config) {
|
|
||||||
// Fallback: pick any healthy account from this cloud type
|
|
||||||
config = db.prepare(
|
|
||||||
`SELECT * FROM cloud_configs
|
|
||||||
WHERE cloud_type = ? AND is_active = 1 AND consecutive_failures < 5
|
|
||||||
ORDER BY is_primary DESC, last_used_at ASC NULLS FIRST
|
|
||||||
LIMIT 1`
|
|
||||||
).get(cloudType) as CloudConfig | undefined;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!ipAddress) {
|
if (!ipAddress) {
|
||||||
// No IP info — fallback to simple LUR
|
// No IP info — fallback to simple LUR
|
||||||
|
|||||||
Reference in New Issue
Block a user