|
@@ -2,7 +2,10 @@ package controllers
|
|
|
|
|
|
import (
|
|
|
"sparrow/pkg/models"
|
|
|
+ "sparrow/pkg/rpcs"
|
|
|
+ "sparrow/pkg/server"
|
|
|
"sparrow/services/knowoapi/services"
|
|
|
+ "strings"
|
|
|
|
|
|
"github.com/kataras/iris"
|
|
|
)
|
|
@@ -23,6 +26,21 @@ func (a *AppController) Post() {
|
|
|
return
|
|
|
}
|
|
|
app.VendorID = a.Token.getVendorID(a.Ctx)
|
|
|
+ if app.AppIcon != "" {
|
|
|
+ //move image
|
|
|
+ args := &rpcs.ArgsMoveFile{
|
|
|
+ Source: app.AppIcon,
|
|
|
+ Target: "application",
|
|
|
+ }
|
|
|
+ reply := &rpcs.ReplyMoveFile{}
|
|
|
+ err := server.RPCCallByName("fileaccess", "FileAccess.MoveFile", args, reply)
|
|
|
+ if err != nil {
|
|
|
+ server.Log.Error(err)
|
|
|
+ app.AppIcon = ""
|
|
|
+ } else {
|
|
|
+ app.AppIcon = reply.FilePath
|
|
|
+ }
|
|
|
+ }
|
|
|
err := a.Service.Create(app)
|
|
|
if err != nil {
|
|
|
responseError(a.Ctx, ErrDatabase, err.Error())
|
|
@@ -91,6 +109,22 @@ func (a *AppController) Put() {
|
|
|
badRequest(a.Ctx, err)
|
|
|
return
|
|
|
}
|
|
|
+ // check update image
|
|
|
+ if strings.Contains(app.AppIcon, "tmp") {
|
|
|
+ //move image
|
|
|
+ args := &rpcs.ArgsMoveFile{
|
|
|
+ Source: app.AppIcon,
|
|
|
+ Target: "application",
|
|
|
+ }
|
|
|
+ reply := &rpcs.ReplyMoveFile{}
|
|
|
+ err := server.RPCCallByName("fileaccess", "FileAccess.MoveFile", args, reply)
|
|
|
+ if err != nil {
|
|
|
+ server.Log.Error(err)
|
|
|
+ app.AppIcon = ""
|
|
|
+ } else {
|
|
|
+ app.AppIcon = reply.FilePath
|
|
|
+ }
|
|
|
+ }
|
|
|
result, err := a.Service.Update(app)
|
|
|
if err != nil {
|
|
|
responseError(a.Ctx, ErrDatabase, err.Error())
|