Compare commits

..

3 Commits

Author SHA1 Message Date
admin d898e92935 Merge pull request '共用 OpenCode TLS httpsAgent 建立邏輯' (#22) from ai-review-resolve/20260620134144 into develop
Reviewed-on: #22
2026-06-20 13:51:30 +00:00
jiantw83 12d7403a0e chore(ai-review 狀態): 移除已解決的 OpenCode TLS finding
AI / 計算版本號 (pull_request) Successful in 2s
AI / Code Review (pull_request) Successful in 29s
2026-06-20 13:42:25 +00:00
jiantw83 babe599977 refactor(OpenCode TLS): 共用 httpsAgent 建立邏輯 2026-06-20 13:42:25 +00:00
4 changed files with 11 additions and 14 deletions
+1 -9
View File
@@ -1,9 +1 @@
[ []
{
"level": "warning",
"role": "Mage",
"location": "app/preflight.js:23",
"suggestion": "在 `app/llm.js` 與 `app/preflight.js` 中,`opencodeAxiosOptions` 函數的邏輯存在重複。雖然 `timeout` 參數在兩處有所不同,但處理 `httpsAgent` 的核心邏輯是相同的。建議將 `httpsAgent` 的建立邏輯抽象為一個共用函數或在 `config.js` 中定義,以避免未來修改時造成不一致,並提高程式碼的可維護性。\n\n例如,可以將 `httpsAgent` 的邏輯移至 `config.js`\n```javascript\n// app/config.js\nexport function getOpenCodeHttpsAgent() {\n return shouldSkipOpenCodeTLSVerify() ? new https.Agent({ rejectUnauthorized: false }) : undefined;\n}\n\n// app/llm.js\nimport { getOpenCodeHttpsAgent } from './config.js';\nfunction opencodeAxiosOptions(headers) {\n return {\n headers,\n httpsAgent: getOpenCodeHttpsAgent(),\n };\n}\n\n// app/preflight.js\nimport { getOpenCodeHttpsAgent } from './config.js';\nconst opencodeAxiosOptions = (headers) => ({\n headers,\n timeout: 30000,\n httpsAgent: getOpenCodeHttpsAgent(),\n});\n```",
"is_new": true
}
]
+6
View File
@@ -1,3 +1,5 @@
import https from 'https';
export const GITEA_TOKEN = process.env.GITEA_TOKEN || ''; export const GITEA_TOKEN = process.env.GITEA_TOKEN || '';
export const GITEA_COMMENT_TOKEN = process.env.GITEA_COMMENT_TOKEN || ''; export const GITEA_COMMENT_TOKEN = process.env.GITEA_COMMENT_TOKEN || '';
export const GITEA_SERVER_URL = process.env.GITEA_SERVER_URL || 'https://gitea.com'; export const GITEA_SERVER_URL = process.env.GITEA_SERVER_URL || 'https://gitea.com';
@@ -15,6 +17,10 @@ export function shouldSkipOpenCodeTLSVerify() {
return process.env.OPENCODE_SKIP_TLS_VERIFY === 'true'; return process.env.OPENCODE_SKIP_TLS_VERIFY === 'true';
} }
export function getOpenCodeHttpsAgent() {
return shouldSkipOpenCodeTLSVerify() ? new https.Agent({ rejectUnauthorized: false }) : undefined;
}
/** 將逗號分隔的 API key 字串拆成陣列 */ /** 將逗號分隔的 API key 字串拆成陣列 */
function splitKeys(value) { function splitKeys(value) {
if (!value) return []; if (!value) return [];
+2 -3
View File
@@ -1,6 +1,5 @@
import axios from 'axios'; import axios from 'axios';
import https from 'https'; import { getLLMConfig, getOpenCodeHttpsAgent } from './config.js';
import { getLLMConfig, shouldSkipOpenCodeTLSVerify } from './config.js';
import { line, error } from './log.js'; import { line, error } from './log.js';
function isOpenAIGpt55(provider, model) { function isOpenAIGpt55(provider, model) {
@@ -50,7 +49,7 @@ function applyOpenCodeAuth(headers) {
function opencodeAxiosOptions(headers) { function opencodeAxiosOptions(headers) {
return { return {
headers, headers,
httpsAgent: shouldSkipOpenCodeTLSVerify() ? new https.Agent({ rejectUnauthorized: false }) : undefined, httpsAgent: getOpenCodeHttpsAgent(),
}; };
} }
+2 -2
View File
@@ -7,8 +7,8 @@ import {
GITEA_REPOSITORY, GITEA_REPOSITORY,
GITEA_SKIP_TLS_VERIFY, GITEA_SKIP_TLS_VERIFY,
PR_NUMBER, PR_NUMBER,
getOpenCodeHttpsAgent,
getLLMConfig, getLLMConfig,
shouldSkipOpenCodeTLSVerify,
} from './config.js'; } from './config.js';
import { verifyRemoteAccess } from './git.js'; import { verifyRemoteAccess } from './git.js';
import { step, line, ok, error } from './log.js'; import { step, line, ok, error } from './log.js';
@@ -30,7 +30,7 @@ const applyOpenCodeAuth = (headers) => {
const opencodeAxiosOptions = (headers) => ({ const opencodeAxiosOptions = (headers) => ({
headers, headers,
timeout: 30000, timeout: 30000,
httpsAgent: shouldSkipOpenCodeTLSVerify() ? new https.Agent({ rejectUnauthorized: false }) : undefined, httpsAgent: getOpenCodeHttpsAgent(),
}); });
function giteaErr(e) { function giteaErr(e) {