Commit b9d78515 by comeback01

Merge branch 'main' into french-translation

parents 5aaf0066 c2a61934
...@@ -2,7 +2,7 @@ package common ...@@ -2,7 +2,7 @@ package common
import ( import (
"bytes" "bytes"
"errors" "fmt"
"io" "io"
"mime" "mime"
"mime/multipart" "mime/multipart"
...@@ -12,6 +12,7 @@ import ( ...@@ -12,6 +12,7 @@ import (
"time" "time"
"github.com/QuantumNous/new-api/constant" "github.com/QuantumNous/new-api/constant"
"github.com/pkg/errors"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
) )
...@@ -39,8 +40,15 @@ func GetRequestBody(c *gin.Context) ([]byte, error) { ...@@ -39,8 +40,15 @@ func GetRequestBody(c *gin.Context) ([]byte, error) {
} }
} }
maxMB := constant.MaxRequestBodyMB maxMB := constant.MaxRequestBodyMB
if maxMB <= 0 { if maxMB < 0 {
maxMB = 32 // no limit
body, err := io.ReadAll(c.Request.Body)
_ = c.Request.Body.Close()
if err != nil {
return nil, err
}
c.Set(KeyRequestBody, body)
return body, nil
} }
maxBytes := int64(maxMB) << 20 maxBytes := int64(maxMB) << 20
...@@ -49,13 +57,13 @@ func GetRequestBody(c *gin.Context) ([]byte, error) { ...@@ -49,13 +57,13 @@ func GetRequestBody(c *gin.Context) ([]byte, error) {
if err != nil { if err != nil {
_ = c.Request.Body.Close() _ = c.Request.Body.Close()
if IsRequestBodyTooLargeError(err) { if IsRequestBodyTooLargeError(err) {
return nil, ErrRequestBodyTooLarge return nil, errors.Wrap(ErrRequestBodyTooLarge, fmt.Sprintf("request body exceeds %d MB", maxMB))
} }
return nil, err return nil, err
} }
_ = c.Request.Body.Close() _ = c.Request.Body.Close()
if int64(len(body)) > maxBytes { if int64(len(body)) > maxBytes {
return nil, ErrRequestBodyTooLarge return nil, errors.Wrap(ErrRequestBodyTooLarge, fmt.Sprintf("request body exceeds %d MB", maxMB))
} }
c.Set(KeyRequestBody, body) c.Set(KeyRequestBody, body)
return body, nil return body, nil
......
...@@ -118,7 +118,7 @@ func initConstantEnv() { ...@@ -118,7 +118,7 @@ func initConstantEnv() {
constant.MaxFileDownloadMB = GetEnvOrDefault("MAX_FILE_DOWNLOAD_MB", 20) constant.MaxFileDownloadMB = GetEnvOrDefault("MAX_FILE_DOWNLOAD_MB", 20)
constant.StreamScannerMaxBufferMB = GetEnvOrDefault("STREAM_SCANNER_MAX_BUFFER_MB", 64) constant.StreamScannerMaxBufferMB = GetEnvOrDefault("STREAM_SCANNER_MAX_BUFFER_MB", 64)
// MaxRequestBodyMB 请求体最大大小(解压后),用于防止超大请求/zip bomb导致内存暴涨 // MaxRequestBodyMB 请求体最大大小(解压后),用于防止超大请求/zip bomb导致内存暴涨
constant.MaxRequestBodyMB = GetEnvOrDefault("MAX_REQUEST_BODY_MB", 32) constant.MaxRequestBodyMB = GetEnvOrDefault("MAX_REQUEST_BODY_MB", 64)
// ForceStreamOption 覆盖请求参数,强制返回usage信息 // ForceStreamOption 覆盖请求参数,强制返回usage信息
constant.ForceStreamOption = GetEnvOrDefaultBool("FORCE_STREAM_OPTION", true) constant.ForceStreamOption = GetEnvOrDefaultBool("FORCE_STREAM_OPTION", true)
constant.CountToken = GetEnvOrDefaultBool("CountToken", true) constant.CountToken = GetEnvOrDefaultBool("CountToken", true)
......
...@@ -254,6 +254,9 @@ func (channel *Channel) Save() error { ...@@ -254,6 +254,9 @@ func (channel *Channel) Save() error {
} }
func (channel *Channel) SaveWithoutKey() error { func (channel *Channel) SaveWithoutKey() error {
if channel.Id == 0 {
return errors.New("channel ID is 0")
}
return DB.Omit("key").Save(channel).Error return DB.Omit("key").Save(channel).Error
} }
......
...@@ -78,15 +78,16 @@ ...@@ -78,15 +78,16 @@
"@so1ve/prettier-config": "^3.1.0", "@so1ve/prettier-config": "^3.1.0",
"@vitejs/plugin-react": "^4.2.1", "@vitejs/plugin-react": "^4.2.1",
"autoprefixer": "^10.4.21", "autoprefixer": "^10.4.21",
"code-inspector-plugin": "^1.3.3",
"eslint": "8.57.0", "eslint": "8.57.0",
"eslint-plugin-header": "^3.1.1", "eslint-plugin-header": "^3.1.1",
"eslint-plugin-react-hooks": "^5.2.0", "eslint-plugin-react-hooks": "^5.2.0",
"i18next-cli": "^1.10.3",
"postcss": "^8.5.3", "postcss": "^8.5.3",
"prettier": "^3.0.0", "prettier": "^3.0.0",
"tailwindcss": "^3", "tailwindcss": "^3",
"typescript": "4.4.2", "typescript": "4.4.2",
"vite": "^5.2.0", "vite": "^5.2.0"
"i18next-cli": "^1.10.3"
}, },
"prettier": { "prettier": {
"singleQuote": true, "singleQuote": true,
......
...@@ -1604,7 +1604,7 @@ const EditChannelModal = (props) => { ...@@ -1604,7 +1604,7 @@ const EditChannelModal = (props) => {
> >
{() => ( {() => (
<Spin spinning={loading}> <Spin spinning={loading}>
<div className='p-2' ref={formContainerRef}> <div className='p-2 space-y-3' ref={formContainerRef}>
<div ref={(el) => (formSectionRefs.current.basicInfo = el)}> <div ref={(el) => (formSectionRefs.current.basicInfo = el)}>
<Card className='!rounded-2xl shadow-sm border-0 mb-6'> <Card className='!rounded-2xl shadow-sm border-0 mb-6'>
{/* Header: Basic Info */} {/* Header: Basic Info */}
......
...@@ -21,6 +21,7 @@ import react from '@vitejs/plugin-react'; ...@@ -21,6 +21,7 @@ import react from '@vitejs/plugin-react';
import { defineConfig, transformWithEsbuild } from 'vite'; import { defineConfig, transformWithEsbuild } from 'vite';
import pkg from '@douyinfe/vite-plugin-semi'; import pkg from '@douyinfe/vite-plugin-semi';
import path from 'path'; import path from 'path';
import { codeInspectorPlugin } from 'code-inspector-plugin';
const { vitePluginSemi } = pkg; const { vitePluginSemi } = pkg;
// https://vitejs.dev/config/ // https://vitejs.dev/config/
...@@ -31,6 +32,9 @@ export default defineConfig({ ...@@ -31,6 +32,9 @@ export default defineConfig({
}, },
}, },
plugins: [ plugins: [
codeInspectorPlugin({
bundler: 'vite',
}),
{ {
name: 'treat-js-files-as-jsx', name: 'treat-js-files-as-jsx',
async transform(code, id) { async transform(code, id) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment