github.com/cloudreve/Cloudreve/v3@v3.0.0-20240224133659-3edb00a6484c/routers/controllers/wopi.go (about) 1 package controllers 2 3 import ( 4 "context" 5 "github.com/cloudreve/Cloudreve/v3/pkg/serializer" 6 "github.com/cloudreve/Cloudreve/v3/pkg/wopi" 7 "github.com/cloudreve/Cloudreve/v3/service/explorer" 8 "github.com/gin-gonic/gin" 9 "net/http" 10 ) 11 12 // CheckFileInfo Get file info 13 func CheckFileInfo(c *gin.Context) { 14 var service explorer.WopiService 15 res, err := service.FileInfo(c) 16 if err != nil { 17 c.Status(http.StatusInternalServerError) 18 c.Header(wopi.ServerErrorHeader, err.Error()) 19 return 20 } 21 22 c.JSON(200, res) 23 } 24 25 // GetFile Get file content 26 func GetFile(c *gin.Context) { 27 var service explorer.WopiService 28 err := service.GetFile(c) 29 if err != nil { 30 c.Status(http.StatusInternalServerError) 31 c.Header(wopi.ServerErrorHeader, err.Error()) 32 return 33 } 34 } 35 36 // PutFile Puts file content 37 func PutFile(c *gin.Context) { 38 ctx, cancel := context.WithCancel(context.Background()) 39 defer cancel() 40 41 service := &explorer.FileIDService{} 42 res := service.PutContent(ctx, c) 43 switch res.Code { 44 case serializer.CodeFileTooLarge: 45 c.Status(http.StatusRequestEntityTooLarge) 46 c.Header(wopi.ServerErrorHeader, res.Error) 47 case serializer.CodeNotFound: 48 c.Status(http.StatusNotFound) 49 c.Header(wopi.ServerErrorHeader, res.Error) 50 case 0: 51 c.Status(http.StatusOK) 52 default: 53 c.Status(http.StatusInternalServerError) 54 c.Header(wopi.ServerErrorHeader, res.Error) 55 } 56 } 57 58 // ModifyFile Modify file properties 59 func ModifyFile(c *gin.Context) { 60 action := c.GetHeader(wopi.OverwriteHeader) 61 switch action { 62 case wopi.MethodLock, wopi.MethodRefreshLock, wopi.MethodUnlock: 63 c.Status(http.StatusOK) 64 return 65 case wopi.MethodRename: 66 var service explorer.WopiService 67 err := service.Rename(c) 68 if err != nil { 69 c.Status(http.StatusInternalServerError) 70 c.Header(wopi.ServerErrorHeader, err.Error()) 71 return 72 } 73 default: 74 c.Status(http.StatusNotImplemented) 75 return 76 } 77 }