@@ -159,7 +159,7 @@ func V1_user_api(r *gin.RouterGroup) {
|
|||||||
_, is_login := ctx.Get("user_info")
|
_, is_login := ctx.Get("user_info")
|
||||||
//fmt.Println(is_login)
|
//fmt.Println(is_login)
|
||||||
//fmt.Println(user_info)
|
//fmt.Println(user_info)
|
||||||
if is_login == true {
|
if is_login {
|
||||||
//fmt.Println("loged")
|
//fmt.Println("loged")
|
||||||
cookie_any, _ := ctx.Get("cookie") //这个cookie在中间件已经判断为有效的,否则is_login不可能为true,所以直接在数据库删除应该是安全的
|
cookie_any, _ := ctx.Get("cookie") //这个cookie在中间件已经判断为有效的,否则is_login不可能为true,所以直接在数据库删除应该是安全的
|
||||||
//删除数据库里的cookie
|
//删除数据库里的cookie
|
||||||
|
|||||||
@@ -185,7 +185,7 @@ func Router_def(r *gin.RouterGroup) {
|
|||||||
user_info, is_login := ctx.Get("user_info")
|
user_info, is_login := ctx.Get("user_info")
|
||||||
|
|
||||||
//判断是否登录
|
//判断是否登录
|
||||||
if is_login == true {
|
if is_login {
|
||||||
|
|
||||||
ctx.HTML(http.StatusOK, "setting-my.html", gin.H{
|
ctx.HTML(http.StatusOK, "setting-my.html", gin.H{
|
||||||
"is_login": is_login,
|
"is_login": is_login,
|
||||||
@@ -201,7 +201,7 @@ func Router_def(r *gin.RouterGroup) {
|
|||||||
user_info, is_login := ctx.Get("user_info")
|
user_info, is_login := ctx.Get("user_info")
|
||||||
user, _ := ctx.Get("user")
|
user, _ := ctx.Get("user")
|
||||||
//判断是否登录
|
//判断是否登录
|
||||||
if is_login == true {
|
if is_login {
|
||||||
|
|
||||||
ctx.HTML(http.StatusOK, "setting-security.html", gin.H{
|
ctx.HTML(http.StatusOK, "setting-security.html", gin.H{
|
||||||
"is_login": is_login,
|
"is_login": is_login,
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ func Router_file(r *gin.RouterGroup) {
|
|||||||
upload := r.Group("/upload") //定义上传组
|
upload := r.Group("/upload") //定义上传组
|
||||||
//4大媒体上传接口,严格判断文件类型,可以直接被前端引用
|
//4大媒体上传接口,严格判断文件类型,可以直接被前端引用
|
||||||
upload.POST("/image", func(ctx *gin.Context) {
|
upload.POST("/image", func(ctx *gin.Context) {
|
||||||
|
Return_json(ctx, "api_ok", nil)
|
||||||
})
|
})
|
||||||
upload.POST("/video", func(ctx *gin.Context) {
|
upload.POST("/video", func(ctx *gin.Context) {
|
||||||
|
|
||||||
|
|||||||
Vendored
+2
-1
@@ -28,7 +28,8 @@ function load_json(key) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function post_file(path, file, file_name, callback) {
|
function post_file(path, file, file_name, callback) {
|
||||||
var head_path = "/file";
|
//console.log(file)
|
||||||
|
var head_path = "/file/upload";
|
||||||
// 创建FormData对象
|
// 创建FormData对象
|
||||||
const formData = new FormData();
|
const formData = new FormData();
|
||||||
formData.append("file", file, file_name); // 'file' 是后端接收文件的字段名
|
formData.append("file", file, file_name); // 'file' 是后端接收文件的字段名
|
||||||
|
|||||||
@@ -503,7 +503,7 @@
|
|||||||
document.getElementById('preview-img').src = previewUrl;
|
document.getElementById('preview-img').src = previewUrl;
|
||||||
// 清理旧URL
|
// 清理旧URL
|
||||||
setTimeout(() => URL.revokeObjectURL(previewUrl), 1000);
|
setTimeout(() => URL.revokeObjectURL(previewUrl), 1000);
|
||||||
}, 'image/jpeg', 0.85);
|
}, 'image/png', 0.85);
|
||||||
updateImageInfo();
|
updateImageInfo();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -556,10 +556,10 @@
|
|||||||
});
|
});
|
||||||
|
|
||||||
const blob = await new Promise(resolve =>
|
const blob = await new Promise(resolve =>
|
||||||
canvas.toBlob(resolve, 'image/jpeg', 0.9)
|
canvas.toBlob(resolve, 'image/png', 0.9)
|
||||||
);
|
);
|
||||||
|
|
||||||
post_file("/upload", blob, `avatar_${Date.now()}.jpg`, (c) => {
|
post_file("/image", 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)
|
||||||
@@ -588,17 +588,17 @@
|
|||||||
// }
|
// }
|
||||||
// });
|
// });
|
||||||
|
|
||||||
if (!response.ok) throw new Error(`服务器错误: ${response.status}`);
|
// if (!response.ok) throw new Error(`服务器错误: ${response.status}`);
|
||||||
|
|
||||||
const result = await response.json();
|
// const result = await response.json();
|
||||||
if (result.err_code == 0) {
|
// if (result.err_code == 0) {
|
||||||
showMessage(`✅ 上传成功!`, 'success');
|
// showMessage(`✅ 上传成功!`, 'success');
|
||||||
set_user_avatar(result.data.path);
|
// set_user_avatar(result.data.path);
|
||||||
console.log(get_user_avatar());
|
// console.log(get_user_avatar());
|
||||||
avatar_toolt.hide();
|
// avatar_toolt.hide();
|
||||||
} else {
|
// } else {
|
||||||
showMessage(`❌ 上传失败: ${result.err_msg}`, 'error');
|
// showMessage(`❌ 上传失败: ${result.err_msg}`, 'error');
|
||||||
}
|
// }
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user