feat: add option to allow worker HTTP image requests

This commit is contained in:
creamlike1024
2025-05-09 02:00:42 +08:00
parent 9de24668d8
commit 3d4bd76083
4 changed files with 28 additions and 5 deletions

View File

@@ -67,6 +67,7 @@ func InitOptionMap() {
common.OptionMap["ServerAddress"] = "" common.OptionMap["ServerAddress"] = ""
common.OptionMap["WorkerUrl"] = setting.WorkerUrl common.OptionMap["WorkerUrl"] = setting.WorkerUrl
common.OptionMap["WorkerValidKey"] = setting.WorkerValidKey common.OptionMap["WorkerValidKey"] = setting.WorkerValidKey
common.OptionMap["WorkerAllowHttpImageRequestEnabled"] = strconv.FormatBool(setting.WorkerAllowHttpImageRequestEnabled)
common.OptionMap["PayAddress"] = "" common.OptionMap["PayAddress"] = ""
common.OptionMap["CustomCallbackAddress"] = "" common.OptionMap["CustomCallbackAddress"] = ""
common.OptionMap["EpayId"] = "" common.OptionMap["EpayId"] = ""
@@ -257,6 +258,8 @@ func updateOptionMap(key string, value string) (err error) {
setting.StopOnSensitiveEnabled = boolValue setting.StopOnSensitiveEnabled = boolValue
case "SMTPSSLEnabled": case "SMTPSSLEnabled":
common.SMTPSSLEnabled = boolValue common.SMTPSSLEnabled = boolValue
case "WorkerAllowHttpImageRequestEnabled":
setting.WorkerAllowHttpImageRequestEnabled = boolValue
} }
} }
switch key { switch key {

View File

@@ -24,7 +24,7 @@ func DoWorkerRequest(req *WorkerRequest) (*http.Response, error) {
if !setting.EnableWorker() { if !setting.EnableWorker() {
return nil, fmt.Errorf("worker not enabled") return nil, fmt.Errorf("worker not enabled")
} }
if !strings.HasPrefix(req.URL, "https") { if !setting.WorkerAllowHttpImageRequestEnabled && !strings.HasPrefix(req.URL, "https") {
return nil, fmt.Errorf("only support https url") return nil, fmt.Errorf("only support https url")
} }

View File

@@ -3,6 +3,7 @@ package setting
var ServerAddress = "http://localhost:3000" var ServerAddress = "http://localhost:3000"
var WorkerUrl = "" var WorkerUrl = ""
var WorkerValidKey = "" var WorkerValidKey = ""
var WorkerAllowHttpImageRequestEnabled = false
func EnableWorker() bool { func EnableWorker() bool {
return WorkerUrl != "" return WorkerUrl != ""

View File

@@ -19,7 +19,7 @@ import {
verifyJSON, verifyJSON,
} from '../helpers/utils'; } from '../helpers/utils';
import { API } from '../helpers/api'; import { API } from '../helpers/api';
import axios from "axios"; import axios from 'axios';
const SystemSetting = () => { const SystemSetting = () => {
let [inputs, setInputs] = useState({ let [inputs, setInputs] = useState({
@@ -45,6 +45,7 @@ const SystemSetting = () => {
ServerAddress: '', ServerAddress: '',
WorkerUrl: '', WorkerUrl: '',
WorkerValidKey: '', WorkerValidKey: '',
WorkerAllowHttpImageRequestEnabled: '',
EpayId: '', EpayId: '',
EpayKey: '', EpayKey: '',
Price: 7.3, Price: 7.3,
@@ -111,6 +112,7 @@ const SystemSetting = () => {
case 'SMTPSSLEnabled': case 'SMTPSSLEnabled':
case 'LinuxDOOAuthEnabled': case 'LinuxDOOAuthEnabled':
case 'oidc.enabled': case 'oidc.enabled':
case 'WorkerAllowHttpImageRequestEnabled':
item.value = item.value === 'true'; item.value = item.value === 'true';
break; break;
case 'Price': case 'Price':
@@ -206,7 +208,11 @@ const SystemSetting = () => {
let WorkerUrl = removeTrailingSlash(inputs.WorkerUrl); let WorkerUrl = removeTrailingSlash(inputs.WorkerUrl);
const options = [ const options = [
{ key: 'WorkerUrl', value: WorkerUrl }, { key: 'WorkerUrl', value: WorkerUrl },
] {
key: 'WorkerAllowHttpImageRequestEnabled',
value: inputs.WorkerAllowHttpImageRequestEnabled ? 'true' : 'false',
},
];
if (inputs.WorkerValidKey !== '' || WorkerUrl === '') { if (inputs.WorkerValidKey !== '' || WorkerUrl === '') {
options.push({ key: 'WorkerValidKey', value: inputs.WorkerValidKey }); options.push({ key: 'WorkerValidKey', value: inputs.WorkerValidKey });
} }
@@ -302,7 +308,8 @@ const SystemSetting = () => {
const domain = emailToAdd.trim(); const domain = emailToAdd.trim();
// 验证域名格式 // 验证域名格式
const domainRegex = /^([a-zA-Z0-9]([a-zA-Z0-9\-]{0,61}[a-zA-Z0-9])?\.)+[a-zA-Z]{2,}$/; const domainRegex =
/^([a-zA-Z0-9]([a-zA-Z0-9\-]{0,61}[a-zA-Z0-9])?\.)+[a-zA-Z]{2,}$/;
if (!domainRegex.test(domain)) { if (!domainRegex.test(domain)) {
showError('邮箱域名格式不正确,请输入有效的域名,如 gmail.com'); showError('邮箱域名格式不正确,请输入有效的域名,如 gmail.com');
return; return;
@@ -577,6 +584,12 @@ const SystemSetting = () => {
/> />
</Col> </Col>
</Row> </Row>
<Form.Checkbox
field='WorkerAllowHttpImageRequestEnabled'
noLabel
>
允许 HTTP 协议图片请求适用于自部署代理
</Form.Checkbox>
<Button onClick={submitWorker}>更新Worker设置</Button> <Button onClick={submitWorker}>更新Worker设置</Button>
</Form.Section> </Form.Section>
</Card> </Card>
@@ -799,7 +812,13 @@ const SystemSetting = () => {
onChange={(value) => setEmailToAdd(value)} onChange={(value) => setEmailToAdd(value)}
style={{ marginTop: 16 }} style={{ marginTop: 16 }}
suffix={ suffix={
<Button theme="solid" type="primary" onClick={handleAddEmail}>添加</Button> <Button
theme='solid'
type='primary'
onClick={handleAddEmail}
>
添加
</Button>
} }
onEnterPress={handleAddEmail} onEnterPress={handleAddEmail}
/> />