Browse Source

add:上传apk

zoie 10 months ago
parent
commit
f3473a1bee
4 changed files with 49 additions and 2 deletions
  1. 42 1
      app/admin/controller/upload.go
  2. 1 1
      app/admin/model/sys_opera_log.go
  3. 1 0
      app/admin/router/upload.go
  4. 5 0
      conf/extend.go

+ 42 - 1
app/admin/controller/upload.go

@@ -22,7 +22,7 @@ type UploadController struct {
 // @Description 文件上传
 // @Tags 工具
 // @Success 200 {object} response.Response{data=string,id=string,msg=string} "{"code": 200, "data": [...]}"
-// @Router /api/captcha [get]
+// @Router /api/upload [get]
 func (e UploadController) FilesUpload(c *gin.Context) {
 	err := e.MakeContext(c).Errors
 	if err != nil {
@@ -63,3 +63,44 @@ func (e UploadController) FilesUpload(c *gin.Context) {
 		"msg":  "success",
 	})
 }
+
+// ApkUpload 文件上传
+// @Summary 文件上传
+// @Description 文件上传
+// @Tags 工具
+// @Success 200 {object} response.Response{data=string,id=string,msg=string} "{"code": 200, "data": [...]}"
+// @Router /api/apk-upload [get]
+func (e UploadController) ApkUpload(c *gin.Context) {
+	err := e.MakeContext(c).Errors
+	if err != nil {
+		e.Error(500, err, "服务初始化失败!")
+		return
+	}
+
+	// 处理文件上传逻辑
+	file, err := c.FormFile("file")
+	uploadFileName := file.Filename          // 获取文件名
+	fileType := filepath.Ext(uploadFileName) // 获取文件类型(扩展名)
+	if err != nil {
+		c.JSON(500, gin.H{"error": err.Error()})
+		return
+	}
+	if fileType != ".apk" {
+		c.JSON(500, gin.H{"code": 200,
+			"data": conf.ExtConfig.Apk.Path + "/" + uploadFileName,
+			"msg":  "success"})
+		return
+	}
+	filePath := conf.ExtConfig.Apk.Path + "/" + uploadFileName
+	err = c.SaveUploadedFile(file, filePath)
+	if err != nil {
+		c.JSON(500, gin.H{"error": err.Error()})
+		return
+	}
+
+	e.Custom(gin.H{
+		"code": 200,
+		"data": conf.ExtConfig.Apk.Path + "/" + uploadFileName,
+		"msg":  "success",
+	})
+}

+ 1 - 1
app/admin/model/sys_opera_log.go

@@ -74,7 +74,7 @@ func SaveOperaLog(message storage.Messager) (err error) {
 		return nil
 	}
 	// 外部调用获取身份信息,操作频繁,不做日志记录
-	if l.OperaUrl == "/api/service/userinfo" || l.OperaUrl == "/api/upload" || l.OperaUrl == "/api/waybill/import" {
+	if l.OperaUrl == "/api/service/userinfo" || l.OperaUrl == "/api/upload" || l.OperaUrl == "/api/waybill/import" || l.OperaUrl == "/api/apk-upload" {
 		return nil
 	}
 	// 超出100个字符返回值截断

+ 1 - 0
app/admin/router/upload.go

@@ -15,5 +15,6 @@ func registerUploadRouter(v1 *gin.RouterGroup, authMiddleware *jwt.GinJWTMiddlew
 	{
 		cont := controller.UploadController{}
 		r1.POST("/upload", cont.FilesUpload)
+		r1.POST("/apk-upload", cont.ApkUpload)
 	}
 }

+ 5 - 0
conf/extend.go

@@ -15,6 +15,7 @@ type Extend struct {
 	Applet  Applet  `yaml:"applet"`
 	Nats    Nats    `yaml:"nats"`
 	Amap    Amap    `yaml:"amap"`
+	Apk     Apk     `yaml:"apk"`
 }
 
 type SubMail struct {
@@ -43,3 +44,7 @@ type Nats struct {
 type Amap struct {
 	Key string `json:"key"`
 }
+
+type Apk struct {
+	Path string `json:"path"`
+}