feat(wopi): implement required rest api as a WOPI host

This commit is contained in:
HFO4
2023-01-09 19:37:46 +08:00
parent 4541400755
commit 1c922ac981
12 changed files with 462 additions and 19 deletions

View File

@@ -236,7 +236,7 @@ func GetDocPreview(c *gin.Context) {
var service explorer.FileIDService
if err := c.ShouldBindUri(&service); err == nil {
res := service.CreateDocPreviewSession(ctx, c)
res := service.CreateDocPreviewSession(ctx, c, true)
c.JSON(200, res)
} else {
c.JSON(200, ErrorResponse(err))

View File

@@ -0,0 +1,77 @@
package controllers
import (
"context"
"github.com/cloudreve/Cloudreve/v3/pkg/serializer"
"github.com/cloudreve/Cloudreve/v3/pkg/wopi"
"github.com/cloudreve/Cloudreve/v3/service/explorer"
"github.com/gin-gonic/gin"
"net/http"
)
// CheckFileInfo Get file info
func CheckFileInfo(c *gin.Context) {
var service explorer.WopiService
res, err := service.FileInfo(c)
if err != nil {
c.Status(http.StatusInternalServerError)
c.Header(wopi.ServerErrorHeader, err.Error())
return
}
c.JSON(200, res)
}
// GetFile Get file content
func GetFile(c *gin.Context) {
var service explorer.WopiService
err := service.GetFile(c)
if err != nil {
c.Status(http.StatusInternalServerError)
c.Header(wopi.ServerErrorHeader, err.Error())
return
}
}
// PutFile Puts file content
func PutFile(c *gin.Context) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
service := &explorer.FileIDService{}
res := service.PutContent(ctx, c)
switch res.Code {
case serializer.CodeFileTooLarge:
c.Status(http.StatusRequestEntityTooLarge)
c.Header(wopi.ServerErrorHeader, res.Error)
case serializer.CodeNotFound:
c.Status(http.StatusNotFound)
c.Header(wopi.ServerErrorHeader, res.Error)
case 0:
c.Status(http.StatusOK)
default:
c.Status(http.StatusInternalServerError)
c.Header(wopi.ServerErrorHeader, res.Error)
}
}
// ModifyFile Modify file properties
func ModifyFile(c *gin.Context) {
action := c.GetHeader(wopi.OverwriteHeader)
switch action {
case wopi.MethodLock, wopi.MethodRefreshLock, wopi.MethodUnlock:
c.Status(http.StatusOK)
return
case wopi.MethodRename:
var service explorer.WopiService
err := service.Rename(c)
if err != nil {
c.Status(http.StatusInternalServerError)
c.Header(wopi.ServerErrorHeader, err.Error())
return
}
default:
c.Status(http.StatusNotImplemented)
return
}
}