diff --git a/controllers/resource.go b/controllers/resource.go index 04f4a5ad..e0db9a4d 100644 --- a/controllers/resource.go +++ b/controllers/resource.go @@ -88,6 +88,7 @@ func (c *ApiController) DeleteResource() { func (c *ApiController) UploadResource() { owner := c.Input().Get("owner") + username := c.Input().Get("user") application := c.Input().Get("application") tag := c.Input().Get("tag") parent := c.Input().Get("parent") @@ -134,6 +135,7 @@ func (c *ApiController) UploadResource() { Owner: owner, Name: objectKey, CreatedTime: util.GetCurrentTime(), + User: username, Provider: provider.Name, Application: application, Tag: tag, diff --git a/object/resource.go b/object/resource.go index cbd7139e..05a51c53 100644 --- a/object/resource.go +++ b/object/resource.go @@ -26,6 +26,7 @@ type Resource struct { Name string `xorm:"varchar(100) notnull pk" json:"name"` CreatedTime string `xorm:"varchar(100)" json:"createdTime"` + User string `xorm:"varchar(100)" json:"user"` Provider string `xorm:"varchar(100)" json:"provider"` Application string `xorm:"varchar(100)" json:"application"` Tag string `xorm:"varchar(100)" json:"tag"` @@ -38,6 +39,10 @@ type Resource struct { } func GetResources(owner string) []*Resource { + if owner == "admin" { + owner = "" + } + resources := []*Resource{} err := adapter.Engine.Desc("created_time").Find(&resources, &Resource{Owner: owner}) if err != nil { diff --git a/web/src/ApplicationEditPage.js b/web/src/ApplicationEditPage.js index e313821e..79115088 100644 --- a/web/src/ApplicationEditPage.js +++ b/web/src/ApplicationEditPage.js @@ -99,7 +99,7 @@ class ApplicationEditPage extends React.Component { } this.setState({uploading: true}); const fullFilePath = `termsOfUse/${this.state.application.owner}/${this.state.application.name}.html`; - ResourceBackend.uploadResource(this.state.application.owner, "termsOfUse", this.state.application.name, fullFilePath, info.file) + ResourceBackend.uploadResource(this.props.account.owner, this.props.account.name, "termsOfUse", this.state.application.name, fullFilePath, info.file) .then(res => { if (res.status === "ok") { Setting.showMessage("success", i18next.t("application:File uploaded successfully")); diff --git a/web/src/CropperDiv.js b/web/src/CropperDiv.js index 65e0df92..872ed123 100644 --- a/web/src/CropperDiv.js +++ b/web/src/CropperDiv.js @@ -58,7 +58,7 @@ export const CropperDiv = (props) => { // Setting.showMessage("success", "uploading..."); const extension = image.substring(image.indexOf('/') + 1, image.indexOf(';base64')); const fullFilePath = `avatar/${user.owner}/${user.name}.${extension}`; - ResourceBackend.uploadResource("admin", "avatar", account.name, fullFilePath, blob) + ResourceBackend.uploadResource(user.owner, user.name, "avatar", account.name, fullFilePath, blob) .then((res) => { if (res.status === "ok") { window.location.href = "/account"; diff --git a/web/src/ResourceListPage.js b/web/src/ResourceListPage.js index eed769a5..bf664b69 100644 --- a/web/src/ResourceListPage.js +++ b/web/src/ResourceListPage.js @@ -63,7 +63,7 @@ class ResourceListPage extends React.Component { this.setState({uploading: true}); const filename = info.fileList[0].name; const fullFilePath = `resource/${this.props.account.owner}/${this.props.account.name}/${filename}`; - ResourceBackend.uploadResource("admin", "custom", this.props.account.name, fullFilePath, info.file) + ResourceBackend.uploadResource(this.props.account.owner, this.props.account.name, "custom", this.props.account.name, fullFilePath, info.file) .then(res => { if (res.status === "ok") { Setting.showMessage("success", i18next.t("application:File uploaded successfully")); @@ -128,6 +128,20 @@ class ResourceListPage extends React.Component { width: '80px', sorter: (a, b) => a.tag.localeCompare(b.tag), }, + { + title: i18next.t("resource:User"), + dataIndex: 'user', + key: 'user', + width: '80px', + sorter: (a, b) => a.user.localeCompare(b.user), + render: (text, record, index) => { + return ( + + {text} + + ) + } + }, { title: i18next.t("resource:Application"), dataIndex: 'application', diff --git a/web/src/backend/ResourceBackend.js b/web/src/backend/ResourceBackend.js index 9756360f..62d28930 100644 --- a/web/src/backend/ResourceBackend.js +++ b/web/src/backend/ResourceBackend.js @@ -55,11 +55,11 @@ export function deleteResource(resource, provider="") { }).then(res => res.json()); } -export function uploadResource(owner, tag, parent, fullFilePath, file, provider="") { +export function uploadResource(owner, user, tag, parent, fullFilePath, file, provider="") { const application = "app-built-in"; let formData = new FormData(); formData.append("file", file); - return fetch(`${Setting.ServerUrl}/api/upload-resource?owner=${owner}&application=${application}&tag=${tag}&parent=${parent}&fullFilePath=${encodeURIComponent(fullFilePath)}&provider=${provider}`, { + return fetch(`${Setting.ServerUrl}/api/upload-resource?owner=${owner}&user=${user}&application=${application}&tag=${tag}&parent=${parent}&fullFilePath=${encodeURIComponent(fullFilePath)}&provider=${provider}`, { body: formData, method: 'POST', credentials: 'include',