mirror of https://github.com/kone-net/go-chat.git
22 changed files with 354 additions and 60 deletions
@ -0,0 +1,46 @@
@@ -0,0 +1,46 @@
|
||||
package v1 |
||||
|
||||
import ( |
||||
"io/ioutil" |
||||
"net/http" |
||||
"strings" |
||||
|
||||
"chat-room/global/log" |
||||
"chat-room/common/response" |
||||
"chat-room/service" |
||||
|
||||
"github.com/gin-gonic/gin" |
||||
"github.com/google/uuid" |
||||
) |
||||
|
||||
// 前端通过文件名称获取文件流,显示文件
|
||||
func GetFile(c *gin.Context) { |
||||
fileName := c.Param("fileName") |
||||
log.Info(fileName) |
||||
data, _ := ioutil.ReadFile("static/img/" + fileName) |
||||
c.Writer.Write(data) |
||||
} |
||||
|
||||
// 上传头像等文件
|
||||
func SaveFile(c *gin.Context) { |
||||
namePreffix := uuid.New().String() |
||||
|
||||
userUuid := c.PostForm("uuid") |
||||
|
||||
file, _ := c.FormFile("file") |
||||
fileName := file.Filename |
||||
index := strings.LastIndex(fileName, ".") |
||||
suffix := fileName[index:] |
||||
|
||||
newFileName := namePreffix + suffix |
||||
|
||||
log.Info("file", log.Any("file name", "static/img/"+newFileName)) |
||||
log.Info("userUuid", log.Any("userUuid name", userUuid)) |
||||
|
||||
c.SaveUploadedFile(file, "static/img/"+newFileName) |
||||
err := service.UserService.ModifyUserAvatar(newFileName, userUuid) |
||||
if err != nil { |
||||
c.JSON(http.StatusOK, response.FailMsg(err.Error())) |
||||
} |
||||
c.JSON(http.StatusOK, response.SuccessMsg(newFileName)) |
||||
} |
@ -1,17 +0,0 @@
@@ -1,17 +0,0 @@
|
||||
package v1 |
||||
|
||||
import ( |
||||
"io/ioutil" |
||||
|
||||
"chat-room/global/log" |
||||
|
||||
"github.com/gin-gonic/gin" |
||||
) |
||||
|
||||
// 前端通过文件名称获取文件流,显示文件
|
||||
func GetFile(c *gin.Context) { |
||||
fileName := c.Param("fileName") |
||||
log.Info(fileName) |
||||
data, _ := ioutil.ReadFile("static/img/" + fileName) |
||||
c.Writer.Write(data) |
||||
} |
@ -0,0 +1,8 @@
@@ -0,0 +1,8 @@
|
||||
package response |
||||
|
||||
import "chat-room/model" |
||||
|
||||
type SearchResponse struct { |
||||
User model.User `json:"user"` |
||||
Group model.Group `json:"group"` |
||||
} |
After Width: | Height: | Size: 1.1 MiB |
After Width: | Height: | Size: 1.6 MiB |
Loading…
Reference in new issue