mirror of
https://github.com/1Panel-dev/1Panel.git
synced 2024-11-27 20:49:03 +08:00
fix: 解决文件下载路径包含 + 下载失败的问题 (#3768)
This commit is contained in:
parent
08a45e9723
commit
7219566273
@ -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)
|
||||
|
@ -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": []
|
||||
}
|
||||
}
|
||||
},
|
||||
|
@ -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": []
|
||||
}
|
||||
}
|
||||
},
|
||||
|
@ -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:
|
||||
|
@ -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…
Reference in New Issue
Block a user