- Added a new `setting` package to replace the `constant` package for configuration management, improving code organization and clarity. - Moved various configuration variables such as `ServerAddress`, `PayAddress`, and `SensitiveWords` to the new `setting` package. - Updated references throughout the codebase to use the new `setting` package, ensuring consistent access to configuration values. - Introduced new files for managing chat settings and midjourney settings, enhancing modularity and maintainability of the code.
27 lines
700 B
Go
27 lines
700 B
Go
package service
|
|
|
|
import (
|
|
"bytes"
|
|
"fmt"
|
|
"net/http"
|
|
"one-api/common"
|
|
"one-api/setting"
|
|
"strings"
|
|
)
|
|
|
|
func DoImageRequest(originUrl string) (resp *http.Response, err error) {
|
|
if setting.EnableWorker() {
|
|
common.SysLog(fmt.Sprintf("downloading image from worker: %s", originUrl))
|
|
workerUrl := setting.WorkerUrl
|
|
if !strings.HasSuffix(workerUrl, "/") {
|
|
workerUrl += "/"
|
|
}
|
|
// post request to worker
|
|
data := []byte(`{"url":"` + originUrl + `","key":"` + setting.WorkerValidKey + `"}`)
|
|
return http.Post(setting.WorkerUrl, "application/json", bytes.NewBuffer(data))
|
|
} else {
|
|
common.SysLog(fmt.Sprintf("downloading image from origin: %s", originUrl))
|
|
return http.Get(originUrl)
|
|
}
|
|
}
|