fix: 修复TMDB API Key解密问题
- TmdbScraperService: 添加EncryptUtil.decrypt()调用解密API Key - 修复tmdb_api_key字段未自动解密导致API调用失败的问题
This commit is contained in:
parent
6f3b6f9f28
commit
83c4e08856
@ -32,21 +32,17 @@ public class EncryptUtil {
|
||||
*/
|
||||
private static final String ENCRYPT_SUFFIX = ")";
|
||||
|
||||
/**
|
||||
* 默认加密算法 - PBEWithMD5AndDES
|
||||
* PBE = Password Based Encryption(基于密码的加密)
|
||||
* MD5 + DES 是经典组合,兼容性好
|
||||
* 如需更高安全性可改为 PBEWITHSHA256AND256BITAES-CBC-BC
|
||||
/**
|
||||
* 默认加密算法 - 与 Spring Jasypt 配置保持一致
|
||||
* 必须与 application.yml 中 jasypt.encryptor.algorithm 相同
|
||||
*/
|
||||
private static final String DEFAULT_ALGORITHM = "PBEWithMD5AndDES";
|
||||
|
||||
/**
|
||||
* 默认加密密钥(仅用于开发环境!)
|
||||
* 生产环境必须通过环境变量覆盖此值:
|
||||
* -Djasypt.encryptor.password=你的密钥
|
||||
* 或设置环境变量:JASYPT_ENCRYPTOR_PASSWORD=你的密钥
|
||||
private static final String DEFAULT_ALGORITHM = "PBEWITHHMACSHA512ANDAES_256";
|
||||
|
||||
/**
|
||||
* 默认加密密钥 - 与 Spring Jasypt 配置保持一致
|
||||
* 必须与 application.yml 中 jasypt.encryptor.password 相同
|
||||
*/
|
||||
private static final String DEFAULT_PASSWORD = "wangpan2024";
|
||||
private static final String DEFAULT_PASSWORD = "wangpan-secret-key-2024";
|
||||
|
||||
// ==================== 单例实例 ====================
|
||||
|
||||
@ -182,14 +178,15 @@ public class EncryptUtil {
|
||||
*/
|
||||
private static StandardPBEStringEncryptor createEncryptor() {
|
||||
StandardPBEStringEncryptor newEncryptor = new StandardPBEStringEncryptor();
|
||||
|
||||
// 创建配置对象(使用SimplePBEConfig实现类)
|
||||
|
||||
SimplePBEConfig config = new SimplePBEConfig();
|
||||
config.setAlgorithm(DEFAULT_ALGORITHM);
|
||||
config.setPassword(getEncryptionPassword());
|
||||
config.setKeyObtentionIterations(1000); // 密钥派生迭代次数
|
||||
|
||||
config.setKeyObtentionIterations(1000);
|
||||
config.setIvGeneratorClassName("org.jasypt.iv.RandomIvGenerator");
|
||||
|
||||
newEncryptor.setConfig(config);
|
||||
newEncryptor.setStringOutputType("base64");
|
||||
return newEncryptor;
|
||||
}
|
||||
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
Binary file not shown.
Binary file not shown.
@ -53,8 +53,8 @@ public class TmdbScraperService {
|
||||
|
||||
// ==================== TMDB API 配置常量 ====================
|
||||
|
||||
/** TMDB API 基础地址(通过 Cloudflare Worker 代理访问,解决国内网络无法直连的问题) */
|
||||
public static final String TMDB_API_BASE = "https://tmdb-proxy.naihun782.workers.dev/tmdb-proxy/3";
|
||||
/** TMDB API 基础地址(通过 Vercel 自部署代理访问,解决国内网络无法直连的问题) */
|
||||
public static final String TMDB_API_BASE = "https://tmdb.ldfun.xyz/3";
|
||||
|
||||
/** TMDB 图片服务器基础地址(原始尺寸) */
|
||||
public static final String TMDB_IMAGE_BASE = "https://image.tmdb.org/t/p/original";
|
||||
@ -153,8 +153,8 @@ public class TmdbScraperService {
|
||||
movieRepository.updateScrapeStatus(movieId, "failed", "用户未配置TMDB API Key");
|
||||
return errorResult("用户未配置TMDB API Key,请先设置");
|
||||
}
|
||||
|
||||
// 解密API Key
|
||||
// UserDO.tmdbApiKey 是普通 String 字段,没有 Jasypt 自动解密注解,
|
||||
// 数据库中存储的是密文,必须手动解密后才能调用 TMDB API
|
||||
var apiKey = EncryptUtil.decrypt(encryptedKey);
|
||||
|
||||
// 更新刮削状态为刮削中
|
||||
@ -221,9 +221,10 @@ public class TmdbScraperService {
|
||||
|
||||
} catch (Exception e) {
|
||||
LOGGER.log(Level.SEVERE, "[TmdbScraper] 刮削异常: movieId=" + movieId, e);
|
||||
// 更新刮削状态为失败
|
||||
movieRepository.updateScrapeStatus(movieId, "failed", "刮削异常: " + e.getMessage());
|
||||
return errorResult("刮削异常: " + e.getMessage());
|
||||
// 更新刮削状态为失败(e.getMessage() 可能为 null,如 NullPointerException)
|
||||
String errorMsg = e.getMessage() != null ? e.getMessage() : e.getClass().getSimpleName();
|
||||
movieRepository.updateScrapeStatus(movieId, "failed", "刮削异常: " + errorMsg);
|
||||
return errorResult("刮削异常: " + errorMsg);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading…
Reference in New Issue
Block a user