From b6842271915d227da6444ea00ec53a45502dec84 Mon Sep 17 00:00:00 2001 From: wjqserver <114663932+WJQSERVER@users.noreply.github.com> Date: Thu, 27 Mar 2025 11:19:42 +0800 Subject: [PATCH] [port] config add rewriteAPI --- config/config.go | 4 +++- config/config.toml | 1 + proxy/match.go | 10 ++++++---- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/config/config.go b/config/config.go index ddeed7b..594fe1b 100644 --- a/config/config.go +++ b/config/config.go @@ -64,9 +64,11 @@ type GitCloneConfig struct { /* [shell] editor = true +rewriteAPI = false */ type ShellConfig struct { - Editor bool `toml:"editor"` + Editor bool `toml:"editor"` + RewriteAPI bool `toml:"rewriteAPI"` } /* diff --git a/config/config.toml b/config/config.toml index 64ad1da..9ae7000 100644 --- a/config/config.toml +++ b/config/config.toml @@ -19,6 +19,7 @@ ForceH2C = false [shell] editor = false +rewriteAPI = false [pages] mode = "internal" # "internal" or "external" diff --git a/proxy/match.go b/proxy/match.go index 67d1412..d2e5d23 100644 --- a/proxy/match.go +++ b/proxy/match.go @@ -151,10 +151,12 @@ func EditorMatcher(rawPath string, cfg *config.Config) (bool, string, error) { if strings.HasPrefix(rawPath, "https://gist.github.com") { return true, matcher, nil } - // 匹配 "https://api.github.com/"开头的链接 - if strings.HasPrefix(rawPath, "https://api.github.com") { - matcher = "api" - return true, matcher, nil + if cfg.Shell.RewriteAPI { + // 匹配 "https://api.github.com/"开头的链接 + if strings.HasPrefix(rawPath, "https://api.github.com") { + matcher = "api" + return true, matcher, nil + } } return false, "", ErrInvalidURL }