feat: publish sanitized custom.97 source
This commit is contained in:
1022 files changed
+69903
-19207
No files matched your search
+11
-18
@@ -18,6 +18,7 @@ import (
|
||||
"github.com/QuantumNous/new-api/common"
|
||||
"github.com/QuantumNous/new-api/logger"
|
||||
"github.com/QuantumNous/new-api/model"
|
||||
"github.com/QuantumNous/new-api/pkg/jsplugin"
|
||||
relaychannel "github.com/QuantumNous/new-api/relay/channel"
|
||||
"github.com/QuantumNous/new-api/service"
|
||||
"github.com/QuantumNous/new-api/setting/system_setting"
|
||||
@@ -68,7 +69,7 @@ func VideoProxy(c *gin.Context) {
|
||||
|
||||
task, exists, err := getTaskForArtifactRequest(c, taskID)
|
||||
if err != nil {
|
||||
logger.LogError(c.Request.Context(), fmt.Sprintf("Failed to query task %s: %s", taskID, err.Error()))
|
||||
logger.LogError(c.Request.Context(), common.LogText("Failed to query task %s: %s", taskID, err.Error()))
|
||||
videoProxyError(c, http.StatusInternalServerError, "server_error", "Failed to query task")
|
||||
return
|
||||
}
|
||||
@@ -93,20 +94,20 @@ func VideoProxy(c *gin.Context) {
|
||||
adaptor, adaptorErr := initTaskArtifactAdaptor(task)
|
||||
if adaptorErr == nil {
|
||||
if provider, ok := adaptor.(relaychannel.TaskContentRequestProvider); ok {
|
||||
descriptor, adaptorErr = provider.BuildContentRequest(task, artifact.Key, relaychannel.TaskArtifactClientRequest{
|
||||
descriptor, adaptorErr = provider.BuildContentRequest(c.Request.Context(), task, artifact.Key, relaychannel.TaskArtifactClientRequest{
|
||||
Method: c.Request.Method,
|
||||
Headers: taskArtifactClientHeaders(c.Request.Header),
|
||||
})
|
||||
}
|
||||
}
|
||||
if adaptorErr != nil {
|
||||
logger.LogWarn(c.Request.Context(), fmt.Sprintf("Failed to resolve plugin video content for task %s", taskID))
|
||||
logger.LogWarn(c.Request.Context(), common.LogText("Failed to resolve plugin video content for task %s: %v", taskID, adaptorErr))
|
||||
descriptor = nil
|
||||
}
|
||||
break
|
||||
}
|
||||
} else {
|
||||
logger.LogWarn(c.Request.Context(), fmt.Sprintf("Failed to project plugin video for task %s", taskID))
|
||||
logger.LogWarn(c.Request.Context(), common.LogText("Failed to project plugin video for task %s", taskID))
|
||||
}
|
||||
}
|
||||
if descriptor == nil {
|
||||
@@ -214,7 +215,8 @@ func proxyTaskMedia(c *gin.Context, task *model.Task, descriptor *relaychannel.T
|
||||
message: "Artifact channel is unavailable", err: err,
|
||||
}
|
||||
}
|
||||
proxy := strings.TrimSpace(channel.GetSetting().Proxy)
|
||||
setting := channel.GetSetting()
|
||||
proxy := strings.TrimSpace(setting.Proxy)
|
||||
if err := validateTaskMediaURL(rawURL, proxy); err != nil {
|
||||
return &taskMediaProxyError{
|
||||
status: http.StatusBadGateway, code: "artifact_request_rejected",
|
||||
@@ -224,7 +226,7 @@ func proxyTaskMedia(c *gin.Context, task *model.Task, descriptor *relaychannel.T
|
||||
|
||||
client := service.GetSSRFProtectedHTTPClient()
|
||||
if proxy != "" {
|
||||
client, err = service.GetHttpClientWithProxy(proxy)
|
||||
client, err = service.GetHttpClientWithProxySettings(proxy, setting)
|
||||
if err != nil {
|
||||
return &taskMediaProxyError{
|
||||
status: http.StatusInternalServerError, code: "artifact_internal_error",
|
||||
@@ -289,7 +291,7 @@ func proxyTaskMedia(c *gin.Context, task *model.Task, descriptor *relaychannel.T
|
||||
return nil
|
||||
}
|
||||
if _, err := io.Copy(c.Writer, resp.Body); err != nil {
|
||||
logger.LogError(c.Request.Context(), fmt.Sprintf("Failed to stream task media: %v", err))
|
||||
logger.LogError(c.Request.Context(), common.LogText("Failed to stream task media: %v", err))
|
||||
}
|
||||
return nil
|
||||
case http.StatusUnauthorized, http.StatusForbidden:
|
||||
@@ -388,20 +390,11 @@ func doTaskMediaRequest(client *http.Client, request *http.Request, responseHead
|
||||
}
|
||||
|
||||
func applyTaskMediaRequestHeaders(destination http.Header, headers map[string]string) error {
|
||||
if len(headers) > 64 {
|
||||
if jsplugin.ValidateRequestHeaders(headers) != nil {
|
||||
return errTaskMediaRequestRejected
|
||||
}
|
||||
for name, value := range headers {
|
||||
name = strings.TrimSpace(name)
|
||||
if !httpguts.ValidHeaderFieldName(name) || !httpguts.ValidHeaderFieldValue(value) || len(value) > 8192 {
|
||||
return errTaskMediaRequestRejected
|
||||
}
|
||||
switch strings.ToLower(name) {
|
||||
case "host", "content-length", "accept-encoding", "connection", "proxy-connection", "keep-alive",
|
||||
"proxy-authorization", "te", "trailer", "transfer-encoding", "upgrade":
|
||||
return errTaskMediaRequestRejected
|
||||
}
|
||||
destination.Set(name, value)
|
||||
destination.Set(strings.TrimSpace(name), value)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user