From 72195662738fb8f310d624e952a0d4b413c64f99 Mon Sep 17 00:00:00 2001 From: zhengkunwang <31820853+zhengkunwang223@users.noreply.github.com> Date: Wed, 31 Jan 2024 20:23:59 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E8=A7=A3=E5=86=B3=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E4=B8=8B=E8=BD=BD=E8=B7=AF=E5=BE=84=E5=8C=85=E5=90=AB=20+=20?= =?UTF-8?q?=E4=B8=8B=E8=BD=BD=E5=A4=B1=E8=B4=A5=E7=9A=84=E9=97=AE=E9=A2=98?= =?UTF-8?q?=20(#3768)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/app/api/v1/file.go | 4 +--- cmd/server/docs/docs.go | 26 +++----------------------- cmd/server/docs/swagger.json | 22 +--------------------- cmd/server/docs/swagger.yaml | 16 +--------------- frontend/src/utils/util.ts | 4 ++-- 5 files changed, 8 insertions(+), 64 deletions(-) diff --git a/backend/app/api/v1/file.go b/backend/app/api/v1/file.go index 62dbaa8fa..cc7ee00cd 100644 --- a/backend/app/api/v1/file.go +++ b/backend/app/api/v1/file.go @@ -422,11 +422,9 @@ func (b *BaseApi) MoveFile(c *gin.Context) { // @Summary Download file // @Description 下载文件 // @Accept json -// @Param request body request.FileDownload true "request" // @Success 200 // @Security ApiKeyAuth -// @Router /files/download [post] -// @x-panel-log {"bodyKeys":["name"],"paramKeys":[],"BeforeFunctions":[],"formatZH":"下载文件 [name]","formatEN":"Download file [name]"} +// @Router /files/download [get] func (b *BaseApi) Download(c *gin.Context) { filePath := c.Query("path") file, err := os.Open(filePath) diff --git a/cmd/server/docs/docs.go b/cmd/server/docs/docs.go index c62f967c5..3b59e7f79 100644 --- a/cmd/server/docs/docs.go +++ b/cmd/server/docs/docs.go @@ -1,5 +1,5 @@ -// Code generated by swaggo/swag. DO NOT EDIT. - +// Package docs GENERATED BY SWAG; DO NOT EDIT +// This file was generated by swaggo/swag package docs import "github.com/swaggo/swag" @@ -5972,7 +5972,7 @@ const docTemplate = `{ } }, "/files/download": { - "post": { + "get": { "security": [ { "ApiKeyAuth": [] @@ -5986,30 +5986,10 @@ const docTemplate = `{ "File" ], "summary": "Download file", - "parameters": [ - { - "description": "request", - "name": "request", - "in": "body", - "required": true, - "schema": { - "$ref": "#/definitions/request.FileDownload" - } - } - ], "responses": { "200": { "description": "OK" } - }, - "x-panel-log": { - "BeforeFunctions": [], - "bodyKeys": [ - "name" - ], - "formatEN": "Download file [name]", - "formatZH": "下载文件 [name]", - "paramKeys": [] } } }, diff --git a/cmd/server/docs/swagger.json b/cmd/server/docs/swagger.json index de3a4cf6d..1e2fc0f51 100644 --- a/cmd/server/docs/swagger.json +++ b/cmd/server/docs/swagger.json @@ -5965,7 +5965,7 @@ } }, "/files/download": { - "post": { + "get": { "security": [ { "ApiKeyAuth": [] @@ -5979,30 +5979,10 @@ "File" ], "summary": "Download file", - "parameters": [ - { - "description": "request", - "name": "request", - "in": "body", - "required": true, - "schema": { - "$ref": "#/definitions/request.FileDownload" - } - } - ], "responses": { "200": { "description": "OK" } - }, - "x-panel-log": { - "BeforeFunctions": [], - "bodyKeys": [ - "name" - ], - "formatEN": "Download file [name]", - "formatZH": "下载文件 [name]", - "paramKeys": [] } } }, diff --git a/cmd/server/docs/swagger.yaml b/cmd/server/docs/swagger.yaml index d286015c1..963907bb0 100644 --- a/cmd/server/docs/swagger.yaml +++ b/cmd/server/docs/swagger.yaml @@ -8773,17 +8773,10 @@ paths: formatZH: 删除文件/文件夹 [path] paramKeys: [] /files/download: - post: + get: consumes: - application/json description: 下载文件 - parameters: - - description: request - in: body - name: request - required: true - schema: - $ref: '#/definitions/request.FileDownload' responses: "200": description: OK @@ -8792,13 +8785,6 @@ paths: summary: Download file tags: - File - x-panel-log: - BeforeFunctions: [] - bodyKeys: - - name - formatEN: Download file [name] - formatZH: 下载文件 [name] - paramKeys: [] /files/favorite: post: consumes: diff --git a/frontend/src/utils/util.ts b/frontend/src/utils/util.ts index 6e3f2d242..7752694bb 100644 --- a/frontend/src/utils/util.ts +++ b/frontend/src/utils/util.ts @@ -427,7 +427,8 @@ export function toLowerCase(str: string) { export function downloadFile(filePath: string) { let url = `${import.meta.env.VITE_API_URL as string}/files/download?`; - window.open(url + 'path=' + filePath, '_blank'); + let path = encodeURIComponent(filePath); + window.open(url + 'path=' + path, '_blank'); } export function downloadWithContent(content: string, fileName: string) { @@ -439,7 +440,6 @@ export function downloadWithContent(content: string, fileName: string) { const event = new MouseEvent('click'); a.dispatchEvent(event); } - export function getDateStr() { let now: Date = new Date();