mirror of
https://github.com/ente-io/ente.git
synced 2025-08-13 01:27:17 +00:00
[server] Limit copying max 100 files in single req
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
package api
|
package api
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"github.com/ente-io/museum/pkg/controller/file_copy"
|
"github.com/ente-io/museum/pkg/controller/file_copy"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
@@ -27,6 +28,7 @@ type FileHandler struct {
|
|||||||
|
|
||||||
// DefaultMaxBatchSize is the default maximum API batch size unless specified otherwise
|
// DefaultMaxBatchSize is the default maximum API batch size unless specified otherwise
|
||||||
const DefaultMaxBatchSize = 1000
|
const DefaultMaxBatchSize = 1000
|
||||||
|
const DefaultCopyBatchSize = 100
|
||||||
|
|
||||||
// CreateOrUpdate creates an entry for a file
|
// CreateOrUpdate creates an entry for a file
|
||||||
func (h *FileHandler) CreateOrUpdate(c *gin.Context) {
|
func (h *FileHandler) CreateOrUpdate(c *gin.Context) {
|
||||||
@@ -67,6 +69,10 @@ func (h *FileHandler) CopyFiles(c *gin.Context) {
|
|||||||
handler.Error(c, stacktrace.Propagate(err, ""))
|
handler.Error(c, stacktrace.Propagate(err, ""))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
if len(req.CollectionFileItems) > DefaultCopyBatchSize {
|
||||||
|
handler.Error(c, stacktrace.Propagate(ente.NewBadRequestWithMessage(fmt.Sprintf("more than %d items", DefaultCopyBatchSize)), ""))
|
||||||
|
return
|
||||||
|
}
|
||||||
response, err := h.FileCopyCtrl.CopyFiles(c, req)
|
response, err := h.FileCopyCtrl.CopyFiles(c, req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
handler.Error(c, stacktrace.Propagate(err, ""))
|
handler.Error(c, stacktrace.Propagate(err, ""))
|
||||||
|
@@ -17,6 +17,8 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const ()
|
||||||
|
|
||||||
type FileCopyController struct {
|
type FileCopyController struct {
|
||||||
S3Config *s3config.S3Config
|
S3Config *s3config.S3Config
|
||||||
FileController *controller.FileController
|
FileController *controller.FileController
|
||||||
|
Reference in New Issue
Block a user