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