Add resource list page.

This commit is contained in:
Yang Luo
2021-08-15 00:17:53 +08:00
parent f3c10c59cb
commit 495b64995f
16 changed files with 631 additions and 89 deletions

View File

@ -15,10 +15,8 @@
package controllers
import (
"bytes"
"encoding/json"
"fmt"
"io"
"strconv"
"github.com/casbin/casdoor/object"
@ -212,67 +210,6 @@ func (c *ApiController) GetAccount() {
c.ResponseOk(user, organization)
}
// UploadFile
// @Title UploadFile
// @Description upload file
// @Param owner query string true "The owner"
// @Param tag query string true "The tag"
// @Param fullFilePath query string true "The full file path"
// @Param file query string true "The file"
// @Success 200 {object} controllers.Response The Response object
// @router /upload-file [post]
func (c *ApiController) UploadFile() {
userId, ok := c.RequireSignedIn()
if !ok {
return
}
//owner := c.Input().Get("owner")
tag := c.Input().Get("tag")
parent := c.Input().Get("parent")
fullFilePath := c.Input().Get("fullFilePath")
file, _, err := c.GetFile("file")
defer file.Close()
if err != nil {
c.ResponseError(err.Error())
return
}
fileBuffer := bytes.NewBuffer(nil)
if _, err = io.Copy(fileBuffer, file); err != nil {
c.ResponseError(err.Error())
return
}
user := object.GetUser(userId)
application := object.GetApplicationByUser(user)
provider := application.GetStorageProvider()
if provider == nil {
c.ResponseError("No storage provider is found")
return
}
fileUrl, err := object.UploadFile(provider, fullFilePath, fileBuffer)
if err != nil {
c.ResponseError(err.Error())
return
}
switch tag {
case "avatar":
user.Avatar = fileUrl
object.UpdateUser(user.GetId(), user)
case "termsOfUse":
applicationId := fmt.Sprintf("admin/%s", parent)
app := object.GetApplication(applicationId)
app.TermsOfUse = fileUrl
object.UpdateApplication(applicationId, app)
}
c.ResponseOk(fileUrl)
}
// GetHumanCheck ...
func (c *ApiController) GetHumanCheck() {
c.Data["json"] = HumanCheck{Type: "none"}