Fix file URL
This commit is contained in:
parent
f93d3f90dd
commit
15dbed335e
|
@ -27,6 +27,7 @@ type File struct {
|
||||||
Size int64 `json:"size"`
|
Size int64 `json:"size"`
|
||||||
CreatedTime string `xorm:"varchar(100)" json:"createdTime"`
|
CreatedTime string `xorm:"varchar(100)" json:"createdTime"`
|
||||||
IsLeaf bool `json:"isLeaf"`
|
IsLeaf bool `json:"isLeaf"`
|
||||||
|
Url string `xorm:"varchar(255)" json:"url"`
|
||||||
Children []*File `xorm:"varchar(1000)" json:"children"`
|
Children []*File `xorm:"varchar(1000)" json:"children"`
|
||||||
|
|
||||||
ChildrenMap map[string]*File `xorm:"-" json:"-"`
|
ChildrenMap map[string]*File `xorm:"-" json:"-"`
|
||||||
|
|
|
@ -21,7 +21,7 @@ import (
|
||||||
"github.com/casbin/casibase/storage"
|
"github.com/casbin/casibase/storage"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (store *Store) createPathIfNotExisted(tokens []string, size int64, lastModifiedTime string, isLeaf bool) {
|
func (store *Store) createPathIfNotExisted(tokens []string, size int64, url string, lastModifiedTime string, isLeaf bool) {
|
||||||
currentFile := store.FileTree
|
currentFile := store.FileTree
|
||||||
for i, token := range tokens {
|
for i, token := range tokens {
|
||||||
if currentFile.Children == nil {
|
if currentFile.Children == nil {
|
||||||
|
@ -47,6 +47,7 @@ func (store *Store) createPathIfNotExisted(tokens []string, size int64, lastModi
|
||||||
Key: key,
|
Key: key,
|
||||||
Title: token,
|
Title: token,
|
||||||
IsLeaf: isLeafTmp,
|
IsLeaf: isLeafTmp,
|
||||||
|
Url: url,
|
||||||
Children: []*File{},
|
Children: []*File{},
|
||||||
ChildrenMap: map[string]*File{},
|
ChildrenMap: map[string]*File{},
|
||||||
}
|
}
|
||||||
|
@ -90,6 +91,7 @@ func (store *Store) Populate() error {
|
||||||
Title: store.DisplayName,
|
Title: store.DisplayName,
|
||||||
CreatedTime: store.CreatedTime,
|
CreatedTime: store.CreatedTime,
|
||||||
IsLeaf: false,
|
IsLeaf: false,
|
||||||
|
Url: "",
|
||||||
Children: []*File{},
|
Children: []*File{},
|
||||||
ChildrenMap: map[string]*File{},
|
ChildrenMap: map[string]*File{},
|
||||||
}
|
}
|
||||||
|
@ -111,9 +113,10 @@ func (store *Store) Populate() error {
|
||||||
lastModifiedTime := object.LastModified
|
lastModifiedTime := object.LastModified
|
||||||
isLeaf := isObjectLeaf(object)
|
isLeaf := isObjectLeaf(object)
|
||||||
size := object.Size
|
size := object.Size
|
||||||
|
url := object.Url
|
||||||
|
|
||||||
tokens := strings.Split(strings.Trim(object.Key, "/"), "/")
|
tokens := strings.Split(strings.Trim(object.Key, "/"), "/")
|
||||||
store.createPathIfNotExisted(tokens, size, lastModifiedTime, isLeaf)
|
store.createPathIfNotExisted(tokens, size, url, lastModifiedTime, isLeaf)
|
||||||
|
|
||||||
// fmt.Printf("%s, %d, %v\n", object.Key, object.Size, object.LastModified)
|
// fmt.Printf("%s, %d, %v\n", object.Key, object.Size, object.LastModified)
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,9 +20,7 @@ import (
|
||||||
"io"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"github.com/astaxie/beego"
|
|
||||||
"github.com/casbin/casibase/casdoor"
|
"github.com/casbin/casibase/casdoor"
|
||||||
"github.com/casbin/casibase/util"
|
|
||||||
"github.com/casdoor/casdoor-go-sdk/casdoorsdk"
|
"github.com/casdoor/casdoor-go-sdk/casdoorsdk"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -66,8 +64,7 @@ func GetObject(provider string, key string) (io.ReadCloser, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func PutObject(provider string, key string, fileBuffer *bytes.Buffer) error {
|
func PutObject(provider string, key string, fileBuffer *bytes.Buffer) error {
|
||||||
_, _, err := casdoorsdk.UploadResource("Casibase", "Casibase", "Casibase",
|
_, _, err := casdoorsdk.UploadResource("Casibase", "", "", fmt.Sprintf("Direct/%s/%s", provider, key), fileBuffer.Bytes())
|
||||||
fmt.Sprintf("/casibase/%s", key), fileBuffer.Bytes())
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -75,8 +72,7 @@ func PutObject(provider string, key string, fileBuffer *bytes.Buffer) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func DeleteObject(provider string, key string) error {
|
func DeleteObject(provider string, key string) error {
|
||||||
casdoorOrganization := beego.AppConfig.String("casdoorOrganization")
|
_, err := casdoorsdk.DeleteResource(fmt.Sprintf("Direct/%s/%s", provider, key))
|
||||||
_, err := casdoorsdk.DeleteResource(util.GetIdFromOwnerAndName(casdoorOrganization, fmt.Sprintf("/casibase/%s", key)))
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
|
@ -207,8 +207,7 @@ class FileTable extends React.Component {
|
||||||
{text}
|
{text}
|
||||||
<Button icon={<DownloadOutlined />} style={{marginLeft: "20px", marginRight: "10px"}} type="primary" size="small" onClick={() => {
|
<Button icon={<DownloadOutlined />} style={{marginLeft: "20px", marginRight: "10px"}} type="primary" size="small" onClick={() => {
|
||||||
files.filter(file => file.isLeaf).forEach((file, index) => {
|
files.filter(file => file.isLeaf).forEach((file, index) => {
|
||||||
const url = `${this.props.store.domain}/${file.key}`;
|
Setting.openLink(file.url);
|
||||||
Setting.openLink(url);
|
|
||||||
});
|
});
|
||||||
}}>{i18next.t("store:Download")}</Button>
|
}}>{i18next.t("store:Download")}</Button>
|
||||||
<Popconfirm
|
<Popconfirm
|
||||||
|
|
|
@ -341,7 +341,7 @@ class FileTree extends React.Component {
|
||||||
const path = selectedKeys[0];
|
const path = selectedKeys[0];
|
||||||
const ext = Setting.getExtFromPath(path);
|
const ext = Setting.getExtFromPath(path);
|
||||||
if (ext !== "") {
|
if (ext !== "") {
|
||||||
const url = `${store.domain}/${path}`;
|
const url = info.node.url;
|
||||||
|
|
||||||
if (!this.isExtForDocViewer((ext) && !this.isExtForFileViewer(ext))) {
|
if (!this.isExtForDocViewer((ext) && !this.isExtForFileViewer(ext))) {
|
||||||
this.setState({
|
this.setState({
|
||||||
|
@ -443,8 +443,7 @@ class FileTree extends React.Component {
|
||||||
<Tooltip title={i18next.t("store:Download")}>
|
<Tooltip title={i18next.t("store:Download")}>
|
||||||
<Button style={{marginRight: "5px"}} icon={<DownloadOutlined />} size="small" onClick={(e) => {
|
<Button style={{marginRight: "5px"}} icon={<DownloadOutlined />} size="small" onClick={(e) => {
|
||||||
Setting.showMessage("success", "Successfully downloaded");
|
Setting.showMessage("success", "Successfully downloaded");
|
||||||
const url = `${store.domain}/${file.key}`;
|
Setting.openLink(file.url);
|
||||||
Setting.openLink(url);
|
|
||||||
e.stopPropagation();
|
e.stopPropagation();
|
||||||
}} />
|
}} />
|
||||||
</Tooltip>
|
</Tooltip>
|
||||||
|
@ -671,7 +670,7 @@ class FileTree extends React.Component {
|
||||||
}
|
}
|
||||||
|
|
||||||
const ext = Setting.getExtFromPath(path);
|
const ext = Setting.getExtFromPath(path);
|
||||||
const url = `${store.domain}/${path}`;
|
const url = this.state.selectedFile.url;
|
||||||
|
|
||||||
const app = this.getCacheApp(filename);
|
const app = this.getCacheApp(filename);
|
||||||
if (app !== "") {
|
if (app !== "") {
|
||||||
|
|
Loading…
Reference in New Issue