mirror of
https://github.com/linux-do/new-api.git
synced 2025-09-17 07:56:38 +08:00
27 lines
705 B
Go
27 lines
705 B
Go
package service
|
|
|
|
import (
|
|
"bytes"
|
|
"fmt"
|
|
"net/http"
|
|
"one-api/common"
|
|
"one-api/constant"
|
|
"strings"
|
|
)
|
|
|
|
func DoImageRequest(originUrl string) (resp *http.Response, err error) {
|
|
if constant.EnableWorker() {
|
|
common.SysLog(fmt.Sprintf("downloading image from worker: %s", originUrl))
|
|
workerUrl := constant.WorkerUrl
|
|
if !strings.HasSuffix(workerUrl, "/") {
|
|
workerUrl += "/"
|
|
}
|
|
// post request to worker
|
|
data := []byte(`{"url":"` + originUrl + `","key":"` + constant.WorkerValidKey + `"}`)
|
|
return http.Post(constant.WorkerUrl, "application/json", bytes.NewBuffer(data))
|
|
} else {
|
|
common.SysLog(fmt.Sprintf("downloading image from origin: %s", originUrl))
|
|
return http.Get(originUrl)
|
|
}
|
|
}
|