mirror of
https://github.com/casdoor/casdoor.git
synced 2025-05-22 18:25:47 +08:00
Support custom provider for storage API
This commit is contained in:
parent
21004f3009
commit
32fbb5b534
@ -167,11 +167,16 @@ func (c *ApiController) DeleteResource() {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if resource.Provider != "" {
|
||||||
|
c.Input().Set("provider", resource.Provider)
|
||||||
|
}
|
||||||
|
c.Input().Set("fullFilePath", resource.Name)
|
||||||
provider, err := c.GetProviderFromContext("Storage")
|
provider, err := c.GetProviderFromContext("Storage")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.ResponseError(err.Error())
|
c.ResponseError(err.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
_, resource.Name = refineFullFilePath(resource.Name)
|
||||||
|
|
||||||
err = object.DeleteFile(provider, resource.Name, c.GetAcceptLanguage())
|
err = object.DeleteFile(provider, resource.Name, c.GetAcceptLanguage())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -231,6 +236,7 @@ func (c *ApiController) UploadResource() {
|
|||||||
c.ResponseError(err.Error())
|
c.ResponseError(err.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
_, fullFilePath = refineFullFilePath(fullFilePath)
|
||||||
|
|
||||||
fileType := "unknown"
|
fileType := "unknown"
|
||||||
contentType := header.Header.Get("Content-Type")
|
contentType := header.Header.Get("Content-Type")
|
||||||
|
@ -16,6 +16,7 @@ package controllers
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"github.com/casdoor/casdoor/conf"
|
"github.com/casdoor/casdoor/conf"
|
||||||
"github.com/casdoor/casdoor/i18n"
|
"github.com/casdoor/casdoor/i18n"
|
||||||
@ -143,6 +144,17 @@ func (c *ApiController) IsMaskedEnabled() (bool, bool) {
|
|||||||
return true, isMaskEnabled
|
return true, isMaskEnabled
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func refineFullFilePath(fullFilePath string) (string, string) {
|
||||||
|
tokens := strings.Split(fullFilePath, "/")
|
||||||
|
if len(tokens) >= 2 && tokens[0] == "Direct" && tokens[1] != "" {
|
||||||
|
providerName := tokens[1]
|
||||||
|
res := strings.Join(tokens[2:], "/")
|
||||||
|
return providerName, "/" + res
|
||||||
|
} else {
|
||||||
|
return "", fullFilePath
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func (c *ApiController) GetProviderFromContext(category string) (*object.Provider, error) {
|
func (c *ApiController) GetProviderFromContext(category string) (*object.Provider, error) {
|
||||||
providerName := c.Input().Get("provider")
|
providerName := c.Input().Get("provider")
|
||||||
if providerName == "" {
|
if providerName == "" {
|
||||||
@ -150,6 +162,9 @@ func (c *ApiController) GetProviderFromContext(category string) (*object.Provide
|
|||||||
value := c.Input().Get("value")
|
value := c.Input().Get("value")
|
||||||
if field == "provider" && value != "" {
|
if field == "provider" && value != "" {
|
||||||
providerName = value
|
providerName = value
|
||||||
|
} else {
|
||||||
|
fullFilePath := c.Input().Get("fullFilePath")
|
||||||
|
providerName, _ = refineFullFilePath(fullFilePath)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user