Browse Source

fix: 解决文件下载路径包含 + 下载失败的问题 (#3768)

pull/3771/head
zhengkunwang 10 months ago committed by GitHub
parent
commit
7219566273
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 4
      backend/app/api/v1/file.go
  2. 26
      cmd/server/docs/docs.go
  3. 22
      cmd/server/docs/swagger.json
  4. 16
      cmd/server/docs/swagger.yaml
  5. 4
      frontend/src/utils/util.ts

4
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)

26
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": []
}
}
},

22
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": []
}
}
},

16
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:

4
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();

Loading…
Cancel
Save