Change libs routes
This commit is contained in:
parent
139831365a
commit
be13dcd525
@ -2,8 +2,10 @@ package libs
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
|
"net/http"
|
||||||
"personalwebsite/webfilesystem"
|
"personalwebsite/webfilesystem"
|
||||||
|
|
||||||
|
"github.com/gin-gonic/gin"
|
||||||
"go.mongodb.org/mongo-driver/bson/primitive"
|
"go.mongodb.org/mongo-driver/bson/primitive"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -11,6 +13,12 @@ type ImagLib struct {
|
|||||||
fs *webfilesystem.WebFileSystem
|
fs *webfilesystem.WebFileSystem
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func NewImgLib(webfs *webfilesystem.WebFileSystem) *ImagLib {
|
||||||
|
return &ImagLib{
|
||||||
|
fs: webfs,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func ReadImage(img *webfilesystem.WebFSFile) (*Img, error) {
|
func ReadImage(img *webfilesystem.WebFSFile) (*Img, error) {
|
||||||
data, ok := img.Data.(primitive.D).Map()["srcdata"]
|
data, ok := img.Data.(primitive.D).Map()["srcdata"]
|
||||||
if !ok {
|
if !ok {
|
||||||
@ -30,6 +38,25 @@ func ReadImage(img *webfilesystem.WebFSFile) (*Img, error) {
|
|||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (l *ImagLib) Route(route *gin.RouterGroup) {
|
||||||
|
route.GET("get", func(ctx *gin.Context) {
|
||||||
|
path := ctx.Query("path")
|
||||||
|
if path == "" {
|
||||||
|
ctx.JSON(http.StatusBadRequest, "TODO") //TODO json error struct
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
file, err := l.fs.Read(path)
|
||||||
|
if err != nil {
|
||||||
|
ctx.String(http.StatusInternalServerError, "TODO") //TODO
|
||||||
|
}
|
||||||
|
data := file.Data.(primitive.Binary)
|
||||||
|
|
||||||
|
ctx.Data(http.StatusOK, "image/jpeg", data.Data)
|
||||||
|
})
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
func GetBase64Image(img *Base64Img, min string) (string, error) {
|
func GetBase64Image(img *Base64Img, min string) (string, error) {
|
||||||
imgString := ""
|
imgString := ""
|
||||||
switch min {
|
switch min {
|
||||||
|
15
libs/libs.go
Normal file
15
libs/libs.go
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
package libs
|
||||||
|
|
||||||
|
import (
|
||||||
|
"personalwebsite/webfilesystem"
|
||||||
|
)
|
||||||
|
|
||||||
|
type Libs struct {
|
||||||
|
imglib *ImagLib
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewLibs(webfs *webfilesystem.WebFileSystem) Libs {
|
||||||
|
return Libs{
|
||||||
|
imglib: NewImgLib(webfs),
|
||||||
|
}
|
||||||
|
}
|
65
main.go
65
main.go
@ -13,6 +13,7 @@ import (
|
|||||||
"personalwebsite/apps/finder"
|
"personalwebsite/apps/finder"
|
||||||
imgviewer "personalwebsite/apps/img-viewer"
|
imgviewer "personalwebsite/apps/img-viewer"
|
||||||
"personalwebsite/apps/personalprops"
|
"personalwebsite/apps/personalprops"
|
||||||
|
"personalwebsite/libs"
|
||||||
"personalwebsite/routewde"
|
"personalwebsite/routewde"
|
||||||
"personalwebsite/wde"
|
"personalwebsite/wde"
|
||||||
"personalwebsite/webfilesystem"
|
"personalwebsite/webfilesystem"
|
||||||
@ -20,7 +21,6 @@ import (
|
|||||||
"github.com/gin-contrib/location"
|
"github.com/gin-contrib/location"
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
"github.com/joho/godotenv"
|
"github.com/joho/godotenv"
|
||||||
"go.mongodb.org/mongo-driver/bson/primitive"
|
|
||||||
"go.mongodb.org/mongo-driver/mongo"
|
"go.mongodb.org/mongo-driver/mongo"
|
||||||
"go.mongodb.org/mongo-driver/mongo/options"
|
"go.mongodb.org/mongo-driver/mongo/options"
|
||||||
)
|
)
|
||||||
@ -119,52 +119,37 @@ func main() {
|
|||||||
{
|
{
|
||||||
imgLibGroup := libsGroup.Group("img")
|
imgLibGroup := libsGroup.Group("img")
|
||||||
{
|
{
|
||||||
imgLibGroup.GET("get", func(ctx *gin.Context) {
|
imgLib := libs.NewImgLib(webfs)
|
||||||
path := ctx.Query("path")
|
imgLib.Route(imgLibGroup)
|
||||||
if path == "" {
|
|
||||||
ctx.JSON(http.StatusBadRequest, "TODO") //TODO json error struct
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
file, err := webfs.Read(path)
|
|
||||||
if err != nil {
|
|
||||||
ctx.String(http.StatusInternalServerError, "TODO") //TODO
|
|
||||||
}
|
|
||||||
data := file.Data.(primitive.Binary)
|
|
||||||
|
|
||||||
ctx.Data(http.StatusOK, "image/jpeg", data.Data)
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
wdeGroup := system.Group("wde")
|
wdeGroup := system.Group("wde")
|
||||||
{
|
{
|
||||||
routewde.Route(wdeGroup, webde)
|
routewde.Route(wdeGroup, webde)
|
||||||
}
|
}
|
||||||
// apps := system.Group("applications")
|
apps := system.Group("applications")
|
||||||
// {
|
{
|
||||||
// apps.GET("/:appid/:method", func(ctx *gin.Context) {
|
apps.GET("/:appid/:method", func(ctx *gin.Context) {
|
||||||
// appId := ctx.Param("appid")
|
appId := ctx.Param("appid")
|
||||||
// method := ctx.Param("method")
|
method := ctx.Param("method")
|
||||||
|
|
||||||
// app, isExist := appsStorage.Apps[appId]
|
app, isExist := appsStorage.Apps[appId]
|
||||||
// if !isExist {
|
if !isExist {
|
||||||
// ctx.Status(http.StatusNoContent)
|
ctx.Status(http.StatusNoContent)
|
||||||
// return
|
return
|
||||||
// }
|
}
|
||||||
// switch method {
|
switch method {
|
||||||
// case "getmanifest":
|
case "getmanifest":
|
||||||
// ctx.JSON(http.StatusOK, app.GetManifest())
|
ctx.JSON(http.StatusOK, app.GetManifest())
|
||||||
// case "app.js":
|
case "app.js":
|
||||||
// ctx.File("resources/sys/" + appId + "/" + appId + ".js")
|
ctx.File("resources/sys/" + appId + "/" + appId + ".js")
|
||||||
// case "app.css":
|
case "app.css":
|
||||||
// ctx.File("resources/sys/" + appId + "/" + appId + ".css")
|
ctx.File("resources/sys/" + appId + "/" + appId + ".css")
|
||||||
// default:
|
default:
|
||||||
// ctx.Status(http.StatusBadRequest)
|
ctx.Status(http.StatusBadRequest)
|
||||||
// }
|
}
|
||||||
// })
|
})
|
||||||
// }
|
}
|
||||||
|
|
||||||
// apps.Route(apps.Group("/storage"), &appsStorage)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fs := router.Group("fs")
|
fs := router.Group("fs")
|
||||||
|
Loading…
Reference in New Issue
Block a user