mirror of
https://github.com/casdoor/casdoor.git
synced 2025-09-07 19:50:33 +08:00
feat: standardize Resource APIs by handling path prefix internally and returning clean paths (#4047)
This commit is contained in:
@@ -20,6 +20,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"mime"
|
"mime"
|
||||||
|
"path"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
@@ -187,6 +188,11 @@ func (c *ApiController) DeleteResource() {
|
|||||||
}
|
}
|
||||||
_, resource.Name = refineFullFilePath(resource.Name)
|
_, resource.Name = refineFullFilePath(resource.Name)
|
||||||
|
|
||||||
|
tag := c.Input().Get("tag")
|
||||||
|
if tag == "Direct" {
|
||||||
|
resource.Name = path.Join(provider.PathPrefix, resource.Name)
|
||||||
|
}
|
||||||
|
|
||||||
err = object.DeleteFile(provider, resource.Name, c.GetAcceptLanguage())
|
err = object.DeleteFile(provider, resource.Name, c.GetAcceptLanguage())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.ResponseError(err.Error())
|
c.ResponseError(err.Error())
|
||||||
|
@@ -31,9 +31,11 @@ func GetDirectResources(owner string, user string, provider *Provider, prefix st
|
|||||||
fullPathPrefix := util.UrlJoin(provider.PathPrefix, prefix)
|
fullPathPrefix := util.UrlJoin(provider.PathPrefix, prefix)
|
||||||
objects, err := storageProvider.List(fullPathPrefix)
|
objects, err := storageProvider.List(fullPathPrefix)
|
||||||
for _, obj := range objects {
|
for _, obj := range objects {
|
||||||
|
name := strings.TrimPrefix(obj.Path, "/")
|
||||||
|
name = strings.TrimPrefix(name, provider.PathPrefix+"/")
|
||||||
resource := &Resource{
|
resource := &Resource{
|
||||||
Owner: owner,
|
Owner: owner,
|
||||||
Name: strings.TrimPrefix(obj.Path, "/"),
|
Name: name,
|
||||||
CreatedTime: obj.LastModified.Local().Format(time.RFC3339),
|
CreatedTime: obj.LastModified.Local().Format(time.RFC3339),
|
||||||
User: user,
|
User: user,
|
||||||
Provider: "",
|
Provider: "",
|
||||||
|
Reference in New Issue
Block a user