|
|
@ -4,6 +4,7 @@ import (
|
|
|
|
//"fmt"
|
|
|
|
//"fmt"
|
|
|
|
"fmt"
|
|
|
|
"fmt"
|
|
|
|
"os"
|
|
|
|
"os"
|
|
|
|
|
|
|
|
"path/filepath"
|
|
|
|
|
|
|
|
|
|
|
|
_ "github.com/go-sql-driver/mysql" // для связи с mysql
|
|
|
|
_ "github.com/go-sql-driver/mysql" // для связи с mysql
|
|
|
|
"github.com/jmoiron/sqlx"
|
|
|
|
"github.com/jmoiron/sqlx"
|
|
|
@ -127,6 +128,7 @@ func albums(db *sqlx.DB) func(iris.Party) {
|
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func images(db *sqlx.DB) func(iris.Party) {
|
|
|
|
func images(db *sqlx.DB) func(iris.Party) {
|
|
|
|
return func(r iris.Party) {
|
|
|
|
return func(r iris.Party) {
|
|
|
|
r.Get("/list", func(ctx iris.Context) {
|
|
|
|
r.Get("/list", func(ctx iris.Context) {
|
|
|
@ -138,20 +140,38 @@ func images(db *sqlx.DB) func(iris.Party) {
|
|
|
|
id := ctx.Params().Get("id")
|
|
|
|
id := ctx.Params().Get("id")
|
|
|
|
filename := ctx.Request().URL.Query().Get("filename")
|
|
|
|
filename := ctx.Request().URL.Query().Get("filename")
|
|
|
|
ctx.Application().Logger().Infof("удаление картинки[%s]: %s", id, filename)
|
|
|
|
ctx.Application().Logger().Infof("удаление картинки[%s]: %s", id, filename)
|
|
|
|
|
|
|
|
err := moveFile(filename, "trash")
|
|
|
|
ctx.JSON(iris.Map{"filename": filename})
|
|
|
|
checkError("trash file", err)
|
|
|
|
|
|
|
|
ctx.JSON(iris.Map{"status": iris.StatusOK})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
r.Get("/move/{id}", func(ctx iris.Context) {
|
|
|
|
r.Get("/move/{id}", func(ctx iris.Context) {
|
|
|
|
id := ctx.Params().Get("id")
|
|
|
|
id := ctx.Params().Get("id")
|
|
|
|
filename := ctx.Request().URL.Query().Get("filename")
|
|
|
|
filename := ctx.Request().URL.Query().Get("filename")
|
|
|
|
ctx.Application().Logger().Infof("перемещение картинки[%s]: %s в [%s]",
|
|
|
|
ctx.Application().Logger().Infof("перемещение картинки[%s]: %s в [%s]",
|
|
|
|
id, filename, selected)
|
|
|
|
id, filename, selected)
|
|
|
|
|
|
|
|
err := moveFile(filename, selected)
|
|
|
|
ctx.JSON(iris.Map{"filename": filename})
|
|
|
|
checkError("move file", err)
|
|
|
|
|
|
|
|
ctx.JSON(iris.Map{"status": iris.StatusOK})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// перемещает файл из oldLocation в newLocation
|
|
|
|
|
|
|
|
func moveFile(filename, album string) error {
|
|
|
|
|
|
|
|
albumDir := filepath.Join("d:/pics-move", album)
|
|
|
|
|
|
|
|
if _, err := os.Stat(albumDir); os.IsNotExist(err) {
|
|
|
|
|
|
|
|
err := os.Mkdir(albumDir, 0755)
|
|
|
|
|
|
|
|
checkError("mkdir", err)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
oldLocation := filepath.Join("d:/pics", filename)
|
|
|
|
|
|
|
|
newLocation := filepath.Join(albumDir, filename)
|
|
|
|
|
|
|
|
err := os.Rename(oldLocation, newLocation)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
|
|
return err
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func getLocalImages() []Image {
|
|
|
|
func getLocalImages() []Image {
|
|
|
|
images := []Image{}
|
|
|
|
images := []Image{}
|
|
|
|
list, err := os.ReadDir("d:/pics")
|
|
|
|
list, err := os.ReadDir("d:/pics")
|
|
|
@ -168,15 +188,15 @@ type Image struct {
|
|
|
|
Url string
|
|
|
|
Url string
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func list(ctx iris.Context) {
|
|
|
|
// func list(ctx iris.Context) {
|
|
|
|
images := []Image{
|
|
|
|
// images := []Image{
|
|
|
|
{Id: 1, Url: "первый"},
|
|
|
|
// {Id: 1, Url: "первый"},
|
|
|
|
{Id: 2, Url: "второй"},
|
|
|
|
// {Id: 2, Url: "второй"},
|
|
|
|
}
|
|
|
|
// }
|
|
|
|
ctx.Application().Logger().Infof("Person: %#+v", "Проверка")
|
|
|
|
// ctx.Application().Logger().Infof("Person: %#+v", "Проверка")
|
|
|
|
|
|
|
|
|
|
|
|
ctx.JSON(images)
|
|
|
|
// ctx.JSON(images)
|
|
|
|
}
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
// ============================ разные утилиты ==========================
|
|
|
|
// ============================ разные утилиты ==========================
|
|
|
|
|
|
|
|
|
|
|
|