Skip to content

Commit

Permalink
set subscribe proxy
Browse files Browse the repository at this point in the history
  • Loading branch information
xxf098 committed Aug 5, 2023
1 parent dbbaa0f commit d8814f3
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 2 deletions.
6 changes: 6 additions & 0 deletions web/gui/src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@
</el-option>
</el-select>
</el-form-item>
<el-form-item label="订阅代理:" v-if="option==1">
<el-input v-model="subscribeProxy" style="width: 235px" placeholder="http://127.0.0.1:8090"
@keyup.enter.native="submit" :disabled="loading" clearable></el-input>
</el-form-item>
<el-form-item label="自定义组名:" v-if="option<2">
<el-input v-model="groupname" style="width: 235px"
@keyup.enter.native="submit" :disabled="loading" clearable></el-input>
Expand Down Expand Up @@ -334,6 +338,7 @@ export default {
proxyPort: 8090,
unique: true,
groupname: "",
subscribeProxy: "",
loadingContent: "",
speedtestMode: "all",
pingMethod: "googleping",
Expand Down Expand Up @@ -924,6 +929,7 @@ export default {
language: self.language,
fontSize: parseInt(self.fontSize),
theme: self.theme,
subscribeProxy: self.subscribeProxy.trim(),
}
},
getOptions() {
Expand Down
40 changes: 38 additions & 2 deletions web/profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,23 @@ const (
// clash to vmess local subscription
func getSubscriptionLinks(link string) ([]string, error) {
c := http.Client{
Timeout: 20 * time.Second,
Timeout: 24 * time.Second,
}
resp, err := c.Get(link)
if rawURL, ok := lookupProxy(); ok && len(rawURL) > 0 {
if uri, err := url.Parse(rawURL); err == nil {
c.Transport = &http.Transport{
Proxy: http.ProxyURL(uri),
}
}
}

req, err := http.NewRequest("GET", link, nil)
if err != nil {
return nil, err
}
req.Header.Set("User-Agent", "ClashforWindows/0.19.24")
resp, err := c.Do(req)
// return timeout error
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -95,6 +109,22 @@ type ParseOption struct {
Type PAESE_TYPE
}

func lookupProxy() (rawURL string, ok bool) {
if rawURL, ok = os.LookupEnv("http_proxy"); ok {
return
}
if rawURL, ok = os.LookupEnv("https_proxy"); ok {
return
}
if rawURL, ok = os.LookupEnv("HTTP_PROXY"); ok {
return
}
if rawURL, ok = os.LookupEnv("HTTPS_PROXY"); ok {
return
}
return
}

// api
func ParseLinks(message string) ([]string, error) {
opt := ParseOption{Type: PARSE_ANY}
Expand Down Expand Up @@ -322,6 +352,7 @@ type ProfileTestOptions struct {
Unique bool `json:"unique"`
GeneratePicMode int `json:"generatePicMode"` // 0: base64 1:pic path 2: no pic 3: json @deprecated use outputMode
OutputMode int `json:"outputMode"`
SubscribeProxy string `json:"subscribeProxy"`
}

type JSONOutput struct {
Expand Down Expand Up @@ -353,6 +384,11 @@ func parseMessage(message []byte) ([]string, *ProfileTestOptions, error) {
return options.Links, options, nil
}
options.TestMode = ALLTEST
if len(options.SubscribeProxy) > 0 {
if _, err := url.Parse(options.SubscribeProxy); err == nil {
os.Setenv("http_proxy", options.SubscribeProxy)
}
}
links, err := ParseLinks(options.Subscription)
if err != nil {
return nil, nil, err
Expand Down

0 comments on commit d8814f3

Please sign in to comment.