up
This commit is contained in:
+3
-2
@@ -89,8 +89,9 @@ func main() {
|
|||||||
ctx.HTML(404, "error_404.html", gin.H{})
|
ctx.HTML(404, "error_404.html", gin.H{})
|
||||||
})
|
})
|
||||||
|
|
||||||
routers.Def_router(r.Group("/")) //分组路由传递到def_routers。go
|
routers.Router_def(r.Group("/"))
|
||||||
routers.Api_router(r.Group("/api/")) //分组路由传递到api_routers。go
|
routers.Router_api(r.Group("/api/"))
|
||||||
|
routers.Router_file(r.Group("/file/"))
|
||||||
|
|
||||||
var http_port = models.Wed_configs.Host + ":" + models.Wed_configs.Port
|
var http_port = models.Wed_configs.Host + ":" + models.Wed_configs.Port
|
||||||
var gin_port = "0.0.0.0" + ":" + models.Wed_configs.Port
|
var gin_port = "0.0.0.0" + ":" + models.Wed_configs.Port
|
||||||
|
|||||||
@@ -1,14 +1,13 @@
|
|||||||
package routers
|
package routers
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
"saas/models"
|
"saas/models"
|
||||||
|
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
"github.com/mitchellh/mapstructure"
|
"github.com/mitchellh/mapstructure"
|
||||||
)
|
)
|
||||||
|
|
||||||
func Api_router(r *gin.RouterGroup) {
|
func Router_api(r *gin.RouterGroup) {
|
||||||
|
|
||||||
r.GET("/", func(ctx *gin.Context) {
|
r.GET("/", func(ctx *gin.Context) {
|
||||||
Return_json(ctx, "api_ok", nil)
|
Return_json(ctx, "api_ok", nil)
|
||||||
@@ -33,8 +32,6 @@ func Api_router(r *gin.RouterGroup) {
|
|||||||
ctx.Set("data", &data_t)
|
ctx.Set("data", &data_t)
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
|
||||||
fmt.Println("jsonerr", err)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Use_login_from_cookie(ctx)
|
Use_login_from_cookie(ctx)
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ import (
|
|||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
)
|
)
|
||||||
|
|
||||||
func Def_router(r *gin.RouterGroup) {
|
func Router_def(r *gin.RouterGroup) {
|
||||||
|
|
||||||
r.Use(func(ctx *gin.Context) {
|
r.Use(func(ctx *gin.Context) {
|
||||||
cookie_vel := ""
|
cookie_vel := ""
|
||||||
|
|||||||
@@ -1 +1,40 @@
|
|||||||
package routers
|
package routers
|
||||||
|
|
||||||
|
//文件路由
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
"github.com/gin-gonic/gin"
|
||||||
|
)
|
||||||
|
|
||||||
|
func Router_file(r *gin.RouterGroup) {
|
||||||
|
|
||||||
|
r.Use(func(ctx *gin.Context) {
|
||||||
|
cookie_value := ctx.PostForm("cookie")
|
||||||
|
//fmt.Println(cookie_value)
|
||||||
|
|
||||||
|
ctx.Set("cookie_value", cookie_value)
|
||||||
|
Use_login_from_cookie(ctx)
|
||||||
|
|
||||||
|
//先判断有没有登录
|
||||||
|
_, is_login := ctx.Get("user_info")
|
||||||
|
if is_login {
|
||||||
|
|
||||||
|
} else {
|
||||||
|
Return_json(ctx, "user_no_sign", nil)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
r.POST("/upload", func(ctx *gin.Context) {
|
||||||
|
file, err := ctx.FormFile("file")
|
||||||
|
if err == nil {
|
||||||
|
fmt.Println("ok")
|
||||||
|
} else {
|
||||||
|
fmt.Println("err:", err)
|
||||||
|
fmt.Println("file:", file)
|
||||||
|
}
|
||||||
|
Return_json(ctx, "api_ok", nil)
|
||||||
|
})
|
||||||
|
|
||||||
|
}
|
||||||
|
|||||||
Vendored
+1
-1
@@ -28,7 +28,7 @@ function load_json(key) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function post_file(path, file, file_name, callback) {
|
function post_file(path, file, file_name, callback) {
|
||||||
var head_path = "/api/v1/file";
|
var head_path = "/file";
|
||||||
// 创建FormData对象
|
// 创建FormData对象
|
||||||
const formData = new FormData();
|
const formData = new FormData();
|
||||||
formData.append("file", file, file_name); // 'file' 是后端接收文件的字段名
|
formData.append("file", file, file_name); // 'file' 是后端接收文件的字段名
|
||||||
|
|||||||
@@ -559,34 +559,34 @@
|
|||||||
canvas.toBlob(resolve, 'image/jpeg', 0.9)
|
canvas.toBlob(resolve, 'image/jpeg', 0.9)
|
||||||
);
|
);
|
||||||
|
|
||||||
// post_file("/upload", blob, `avatar_${Date.now()}.jpg`, (c) => {
|
post_file("/upload", blob, `avatar_${Date.now()}.jpg`, (c) => {
|
||||||
// if (c.statusCode == 200) {
|
if (c.statusCode == 200) {
|
||||||
// if (c.data.err_code == 0) {
|
if (c.data.err_code == 0) {
|
||||||
// //save_json("cookie", c.data.return.cookie)
|
//save_json("cookie", c.data.return.cookie)
|
||||||
// banner_alert('success', "更换成功", 950)
|
banner_alert('success', "更换成功", 950)
|
||||||
// } else {
|
} else {
|
||||||
// banner_alert('warning', "服务错误", 3000)
|
banner_alert('warning', "服务错误", 3000)
|
||||||
// }
|
|
||||||
// } else {
|
|
||||||
// banner_alert('danger', "网络连接错误:" + c.statusCode, 3000)
|
|
||||||
// }
|
|
||||||
// })
|
|
||||||
|
|
||||||
const formData = new FormData();
|
|
||||||
formData.append('file', blob, `avatar_${Date.now()}.jpg`);
|
|
||||||
formData.append('meta', JSON.stringify({
|
|
||||||
width: canvas.width,
|
|
||||||
height: canvas.height,
|
|
||||||
scale: currentScale.toFixed(2)
|
|
||||||
}));
|
|
||||||
|
|
||||||
const response = await fetch('/api/v1/file/upload', {
|
|
||||||
method: 'POST',
|
|
||||||
body: formData,
|
|
||||||
headers: {
|
|
||||||
'X-Requested-With': 'XMLHttpRequest'
|
|
||||||
}
|
}
|
||||||
});
|
} else {
|
||||||
|
banner_alert('danger', "网络连接错误:" + c.statusCode, 3000)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
// const formData = new FormData();
|
||||||
|
// formData.append('file', blob, `avatar_${Date.now()}.jpg`);
|
||||||
|
// formData.append('meta', JSON.stringify({
|
||||||
|
// width: canvas.width,
|
||||||
|
// height: canvas.height,
|
||||||
|
// scale: currentScale.toFixed(2)
|
||||||
|
// }));
|
||||||
|
|
||||||
|
// const response = await fetch('/file/upload', {
|
||||||
|
// method: 'POST',
|
||||||
|
// body: formData,
|
||||||
|
// headers: {
|
||||||
|
// 'X-Requested-With': 'XMLHttpRequest'
|
||||||
|
// }
|
||||||
|
// });
|
||||||
|
|
||||||
if (!response.ok) throw new Error(`服务器错误: ${response.status}`);
|
if (!response.ok) throw new Error(`服务器错误: ${response.status}`);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user