[server] Add basic scaffold for copying files
This commit is contained in:
parent
aabb884828
commit
c124cde471
|
@ -5,6 +5,7 @@ import (
|
||||||
"database/sql"
|
"database/sql"
|
||||||
b64 "encoding/base64"
|
b64 "encoding/base64"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"github.com/ente-io/museum/pkg/controller/file_copy"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
"os/signal"
|
"os/signal"
|
||||||
|
@ -389,9 +390,11 @@ func main() {
|
||||||
timeout.WithHandler(healthCheckHandler.PingDBStats),
|
timeout.WithHandler(healthCheckHandler.PingDBStats),
|
||||||
timeout.WithResponse(timeOutResponse),
|
timeout.WithResponse(timeOutResponse),
|
||||||
))
|
))
|
||||||
|
fileCopyCtrl := &file_copy.FileCopyController{FileController: fileController, CollectionCtrl: collectionController, S3Config: s3Config}
|
||||||
|
|
||||||
fileHandler := &api.FileHandler{
|
fileHandler := &api.FileHandler{
|
||||||
Controller: fileController,
|
Controller: fileController,
|
||||||
|
FileCopyCtrl: fileCopyCtrl,
|
||||||
}
|
}
|
||||||
privateAPI.GET("/files/upload-urls", fileHandler.GetUploadURLs)
|
privateAPI.GET("/files/upload-urls", fileHandler.GetUploadURLs)
|
||||||
privateAPI.GET("/files/multipart-upload-urls", fileHandler.GetMultipartUploadURLs)
|
privateAPI.GET("/files/multipart-upload-urls", fileHandler.GetMultipartUploadURLs)
|
||||||
|
@ -400,6 +403,7 @@ func main() {
|
||||||
privateAPI.GET("/files/preview/:fileID", fileHandler.GetThumbnail)
|
privateAPI.GET("/files/preview/:fileID", fileHandler.GetThumbnail)
|
||||||
privateAPI.GET("/files/preview/v2/:fileID", fileHandler.GetThumbnail)
|
privateAPI.GET("/files/preview/v2/:fileID", fileHandler.GetThumbnail)
|
||||||
privateAPI.POST("/files", fileHandler.CreateOrUpdate)
|
privateAPI.POST("/files", fileHandler.CreateOrUpdate)
|
||||||
|
privateAPI.POST("/files/copy", fileHandler.CopyFiles)
|
||||||
privateAPI.PUT("/files/update", fileHandler.Update)
|
privateAPI.PUT("/files/update", fileHandler.Update)
|
||||||
privateAPI.POST("/files/trash", fileHandler.Trash)
|
privateAPI.POST("/files/trash", fileHandler.Trash)
|
||||||
privateAPI.POST("/files/size", fileHandler.GetSize)
|
privateAPI.POST("/files/size", fileHandler.GetSize)
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package api
|
package api
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"github.com/ente-io/museum/pkg/controller/file_copy"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
@ -21,6 +22,7 @@ import (
|
||||||
// FileHandler exposes request handlers for all encrypted file related requests
|
// FileHandler exposes request handlers for all encrypted file related requests
|
||||||
type FileHandler struct {
|
type FileHandler struct {
|
||||||
Controller *controller.FileController
|
Controller *controller.FileController
|
||||||
|
FileCopyCtrl *file_copy.FileCopyController
|
||||||
}
|
}
|
||||||
|
|
||||||
// DefaultMaxBatchSize is the default maximum API batch size unless specified otherwise
|
// DefaultMaxBatchSize is the default maximum API batch size unless specified otherwise
|
||||||
|
@ -58,6 +60,21 @@ func (h *FileHandler) CreateOrUpdate(c *gin.Context) {
|
||||||
c.JSON(http.StatusOK, response)
|
c.JSON(http.StatusOK, response)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// CopyFiles copies files that are owned by another user
|
||||||
|
func (h *FileHandler) CopyFiles(c *gin.Context) {
|
||||||
|
var req ente.CopyFileSyncRequest
|
||||||
|
if err := c.ShouldBindJSON(&req); err != nil {
|
||||||
|
handler.Error(c, stacktrace.Propagate(err, ""))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
response, err := h.FileCopyCtrl.CopyFiles(c, req)
|
||||||
|
if err != nil {
|
||||||
|
handler.Error(c, stacktrace.Propagate(err, ""))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
c.JSON(http.StatusOK, response)
|
||||||
|
}
|
||||||
|
|
||||||
// Update updates already existing file
|
// Update updates already existing file
|
||||||
func (h *FileHandler) Update(c *gin.Context) {
|
func (h *FileHandler) Update(c *gin.Context) {
|
||||||
enteApp := auth.GetApp(c)
|
enteApp := auth.GetApp(c)
|
||||||
|
|
|
@ -464,7 +464,7 @@ func (c *CollectionController) isRemoveAllowed(ctx *gin.Context, actorUserID int
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *CollectionController) isCopyAllowed(ctx *gin.Context, actorUserID int64, req ente.CopyFileSyncRequest) error {
|
func (c *CollectionController) IsCopyAllowed(ctx *gin.Context, actorUserID int64, req ente.CopyFileSyncRequest) error {
|
||||||
// verify that srcCollectionID is accessible by actorUserID
|
// verify that srcCollectionID is accessible by actorUserID
|
||||||
if _, err := c.AccessCtrl.GetCollection(ctx, &access.GetCollectionParams{
|
if _, err := c.AccessCtrl.GetCollection(ctx, &access.GetCollectionParams{
|
||||||
CollectionID: req.SrcCollectionID,
|
CollectionID: req.SrcCollectionID,
|
||||||
|
|
25
server/pkg/controller/file_copy/file_copy.go
Normal file
25
server/pkg/controller/file_copy/file_copy.go
Normal file
|
@ -0,0 +1,25 @@
|
||||||
|
package file_copy
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/ente-io/museum/ente"
|
||||||
|
"github.com/ente-io/museum/pkg/controller"
|
||||||
|
"github.com/ente-io/museum/pkg/utils/auth"
|
||||||
|
"github.com/ente-io/museum/pkg/utils/s3config"
|
||||||
|
"github.com/gin-gonic/gin"
|
||||||
|
)
|
||||||
|
|
||||||
|
type FileCopyController struct {
|
||||||
|
S3Config *s3config.S3Config
|
||||||
|
FileController *controller.FileController
|
||||||
|
CollectionCtrl *controller.CollectionController
|
||||||
|
}
|
||||||
|
|
||||||
|
func (fc *FileCopyController) CopyFiles(c *gin.Context, req ente.CopyFileSyncRequest) (interface{}, error) {
|
||||||
|
userID := auth.GetUserID(c.Request.Header)
|
||||||
|
err := fc.CollectionCtrl.IsCopyAllowed(c, userID, req)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return nil, ente.NewInternalError("yet to implement actual copy")
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in a new issue