mirror of
https://github.com/casdoor/casdoor.git
synced 2025-05-23 10:45:47 +08:00
Add provider to file API.
This commit is contained in:
parent
518c3f9f69
commit
8674b4853a
@ -64,23 +64,41 @@ func (c *ApiController) AddResource() {
|
|||||||
c.ServeJSON()
|
c.ServeJSON()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *ApiController) DeleteResource() {
|
func (c *ApiController) GetProviderParam() (*object.Provider, *object.User, bool) {
|
||||||
userId, ok := c.RequireSignedIn()
|
providerName := c.Input().Get("provider")
|
||||||
if !ok {
|
if providerName != "" {
|
||||||
return
|
provider := object.GetProvider(util.GetId(providerName))
|
||||||
|
if provider == nil {
|
||||||
|
c.ResponseError(fmt.Sprintf("The provider: %s is not found", providerName))
|
||||||
|
return nil, nil, false
|
||||||
|
}
|
||||||
|
return provider, nil, true
|
||||||
}
|
}
|
||||||
|
|
||||||
var resource object.Resource
|
userId, ok := c.RequireSignedIn()
|
||||||
err := json.Unmarshal(c.Ctx.Input.RequestBody, &resource)
|
if !ok {
|
||||||
if err != nil {
|
return nil, nil, false
|
||||||
panic(err)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
user := object.GetUser(userId)
|
user := object.GetUser(userId)
|
||||||
application := object.GetApplicationByUser(user)
|
application := object.GetApplicationByUser(user)
|
||||||
provider := application.GetStorageProvider()
|
provider := application.GetStorageProvider()
|
||||||
if provider == nil {
|
if provider == nil {
|
||||||
c.ResponseError("No storage provider is found")
|
c.ResponseError(fmt.Sprintf("No storage provider is found for application: %s", application.Name))
|
||||||
|
return nil, nil, false
|
||||||
|
}
|
||||||
|
return provider, user, true
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *ApiController) DeleteResource() {
|
||||||
|
var resource object.Resource
|
||||||
|
err := json.Unmarshal(c.Ctx.Input.RequestBody, &resource)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
provider, _, ok := c.GetProviderParam()
|
||||||
|
if !ok {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -95,11 +113,6 @@ func (c *ApiController) DeleteResource() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (c *ApiController) UploadResource() {
|
func (c *ApiController) UploadResource() {
|
||||||
userId, ok := c.RequireSignedIn()
|
|
||||||
if !ok {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
owner := c.Input().Get("owner")
|
owner := c.Input().Get("owner")
|
||||||
tag := c.Input().Get("tag")
|
tag := c.Input().Get("tag")
|
||||||
parent := c.Input().Get("parent")
|
parent := c.Input().Get("parent")
|
||||||
@ -119,11 +132,8 @@ func (c *ApiController) UploadResource() {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
user := object.GetUser(userId)
|
provider, user, ok := c.GetProviderParam()
|
||||||
application := object.GetApplicationByUser(user)
|
if !ok {
|
||||||
provider := application.GetStorageProvider()
|
|
||||||
if provider == nil {
|
|
||||||
c.ResponseError("No storage provider is found")
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -147,6 +157,7 @@ func (c *ApiController) UploadResource() {
|
|||||||
Owner: owner,
|
Owner: owner,
|
||||||
Name: filename,
|
Name: filename,
|
||||||
CreatedTime: util.GetCurrentTime(),
|
CreatedTime: util.GetCurrentTime(),
|
||||||
|
Provider: provider.Name,
|
||||||
Tag: tag,
|
Tag: tag,
|
||||||
Parent: parent,
|
Parent: parent,
|
||||||
FileType: fileType,
|
FileType: fileType,
|
||||||
|
@ -26,6 +26,7 @@ type Resource struct {
|
|||||||
Name string `xorm:"varchar(100) notnull pk" json:"name"`
|
Name string `xorm:"varchar(100) notnull pk" json:"name"`
|
||||||
CreatedTime string `xorm:"varchar(100)" json:"createdTime"`
|
CreatedTime string `xorm:"varchar(100)" json:"createdTime"`
|
||||||
|
|
||||||
|
Provider string `xorm:"varchar(100)" json:"provider"`
|
||||||
Tag string `xorm:"varchar(100)" json:"tag"`
|
Tag string `xorm:"varchar(100)" json:"tag"`
|
||||||
Parent string `xorm:"varchar(100)" json:"parent"`
|
Parent string `xorm:"varchar(100)" json:"parent"`
|
||||||
FileType string `xorm:"varchar(100)" json:"fileType"`
|
FileType string `xorm:"varchar(100)" json:"fileType"`
|
||||||
|
@ -89,20 +89,27 @@ class ResourceListPage extends React.Component {
|
|||||||
|
|
||||||
renderTable(resources) {
|
renderTable(resources) {
|
||||||
const columns = [
|
const columns = [
|
||||||
|
{
|
||||||
|
title: i18next.t("general:Provider"),
|
||||||
|
dataIndex: 'provider',
|
||||||
|
key: 'provider',
|
||||||
|
width: '150px',
|
||||||
|
fixed: 'left',
|
||||||
|
sorter: (a, b) => a.provider.localeCompare(b.provider),
|
||||||
|
render: (text, record, index) => {
|
||||||
|
return (
|
||||||
|
<Link to={`/providers/${text}`}>
|
||||||
|
{text}
|
||||||
|
</Link>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
},
|
||||||
{
|
{
|
||||||
title: i18next.t("general:Name"),
|
title: i18next.t("general:Name"),
|
||||||
dataIndex: 'name',
|
dataIndex: 'name',
|
||||||
key: 'name',
|
key: 'name',
|
||||||
width: '150px',
|
width: '150px',
|
||||||
fixed: 'left',
|
|
||||||
sorter: (a, b) => a.name.localeCompare(b.name),
|
sorter: (a, b) => a.name.localeCompare(b.name),
|
||||||
// render: (text, record, index) => {
|
|
||||||
// return (
|
|
||||||
// <Link to={`/resources/${text}`}>
|
|
||||||
// {text}
|
|
||||||
// </Link>
|
|
||||||
// )
|
|
||||||
// }
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
title: i18next.t("general:Created time"),
|
title: i18next.t("general:Created time"),
|
||||||
|
@ -46,19 +46,19 @@ export function addResource(resource) {
|
|||||||
}).then(res => res.json());
|
}).then(res => res.json());
|
||||||
}
|
}
|
||||||
|
|
||||||
export function deleteResource(resource) {
|
export function deleteResource(resource, provider="") {
|
||||||
let newResource = Setting.deepCopy(resource);
|
let newResource = Setting.deepCopy(resource);
|
||||||
return fetch(`${Setting.ServerUrl}/api/delete-resource`, {
|
return fetch(`${Setting.ServerUrl}/api/delete-resource?provider=${provider}`, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
credentials: 'include',
|
credentials: 'include',
|
||||||
body: JSON.stringify(newResource),
|
body: JSON.stringify(newResource),
|
||||||
}).then(res => res.json());
|
}).then(res => res.json());
|
||||||
}
|
}
|
||||||
|
|
||||||
export function uploadResource(owner, tag, parent, fullFilePath, file) {
|
export function uploadResource(owner, tag, parent, fullFilePath, file, provider="") {
|
||||||
let formData = new FormData();
|
let formData = new FormData();
|
||||||
formData.append("file", file);
|
formData.append("file", file);
|
||||||
return fetch(`${Setting.ServerUrl}/api/upload-resource?owner=${owner}&tag=${tag}&parent=${parent}&fullFilePath=${encodeURIComponent(fullFilePath)}`, {
|
return fetch(`${Setting.ServerUrl}/api/upload-resource?owner=${owner}&tag=${tag}&parent=${parent}&fullFilePath=${encodeURIComponent(fullFilePath)}&provider=${provider}`, {
|
||||||
body: formData,
|
body: formData,
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
credentials: 'include',
|
credentials: 'include',
|
||||||
|
Loading…
x
Reference in New Issue
Block a user