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
|
// @Summary Download file
|
||||||
// @Description 下载文件
|
// @Description 下载文件
|
||||||
// @Accept json
|
// @Accept json
|
||||||
// @Param request body request.FileDownload true "request"
|
|
||||||
// @Success 200
|
// @Success 200
|
||||||
// @Security ApiKeyAuth
|
// @Security ApiKeyAuth
|
||||||
// @Router /files/download [post]
|
// @Router /files/download [get]
|
||||||
// @x-panel-log {"bodyKeys":["name"],"paramKeys":[],"BeforeFunctions":[],"formatZH":"下载文件 [name]","formatEN":"Download file [name]"}
|
|
||||||
func (b *BaseApi) Download(c *gin.Context) {
|
func (b *BaseApi) Download(c *gin.Context) {
|
||||||
filePath := c.Query("path")
|
filePath := c.Query("path")
|
||||||
file, err := os.Open(filePath)
|
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
|
package docs
|
||||||
|
|
||||||
import "github.com/swaggo/swag"
|
import "github.com/swaggo/swag"
|
||||||
@ -5972,7 +5972,7 @@ const docTemplate = `{
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"/files/download": {
|
"/files/download": {
|
||||||
"post": {
|
"get": {
|
||||||
"security": [
|
"security": [
|
||||||
{
|
{
|
||||||
"ApiKeyAuth": []
|
"ApiKeyAuth": []
|
||||||
@ -5986,30 +5986,10 @@ const docTemplate = `{
|
|||||||
"File"
|
"File"
|
||||||
],
|
],
|
||||||
"summary": "Download file",
|
"summary": "Download file",
|
||||||
"parameters": [
|
|
||||||
{
|
|
||||||
"description": "request",
|
|
||||||
"name": "request",
|
|
||||||
"in": "body",
|
|
||||||
"required": true,
|
|
||||||
"schema": {
|
|
||||||
"$ref": "#/definitions/request.FileDownload"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"responses": {
|
"responses": {
|
||||||
"200": {
|
"200": {
|
||||||
"description": "OK"
|
"description": "OK"
|
||||||
}
|
}
|
||||||
},
|
|
||||||
"x-panel-log": {
|
|
||||||
"BeforeFunctions": [],
|
|
||||||
"bodyKeys": [
|
|
||||||
"name"
|
|
||||||
],
|
|
||||||
"formatEN": "Download file [name]",
|
|
||||||
"formatZH": "下载文件 [name]",
|
|
||||||
"paramKeys": []
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -5965,7 +5965,7 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"/files/download": {
|
"/files/download": {
|
||||||
"post": {
|
"get": {
|
||||||
"security": [
|
"security": [
|
||||||
{
|
{
|
||||||
"ApiKeyAuth": []
|
"ApiKeyAuth": []
|
||||||
@ -5979,30 +5979,10 @@
|
|||||||
"File"
|
"File"
|
||||||
],
|
],
|
||||||
"summary": "Download file",
|
"summary": "Download file",
|
||||||
"parameters": [
|
|
||||||
{
|
|
||||||
"description": "request",
|
|
||||||
"name": "request",
|
|
||||||
"in": "body",
|
|
||||||
"required": true,
|
|
||||||
"schema": {
|
|
||||||
"$ref": "#/definitions/request.FileDownload"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"responses": {
|
"responses": {
|
||||||
"200": {
|
"200": {
|
||||||
"description": "OK"
|
"description": "OK"
|
||||||
}
|
}
|
||||||
},
|
|
||||||
"x-panel-log": {
|
|
||||||
"BeforeFunctions": [],
|
|
||||||
"bodyKeys": [
|
|
||||||
"name"
|
|
||||||
],
|
|
||||||
"formatEN": "Download file [name]",
|
|
||||||
"formatZH": "下载文件 [name]",
|
|
||||||
"paramKeys": []
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -8773,17 +8773,10 @@ paths:
|
|||||||
formatZH: 删除文件/文件夹 [path]
|
formatZH: 删除文件/文件夹 [path]
|
||||||
paramKeys: []
|
paramKeys: []
|
||||||
/files/download:
|
/files/download:
|
||||||
post:
|
get:
|
||||||
consumes:
|
consumes:
|
||||||
- application/json
|
- application/json
|
||||||
description: 下载文件
|
description: 下载文件
|
||||||
parameters:
|
|
||||||
- description: request
|
|
||||||
in: body
|
|
||||||
name: request
|
|
||||||
required: true
|
|
||||||
schema:
|
|
||||||
$ref: '#/definitions/request.FileDownload'
|
|
||||||
responses:
|
responses:
|
||||||
"200":
|
"200":
|
||||||
description: OK
|
description: OK
|
||||||
@ -8792,13 +8785,6 @@ paths:
|
|||||||
summary: Download file
|
summary: Download file
|
||||||
tags:
|
tags:
|
||||||
- File
|
- File
|
||||||
x-panel-log:
|
|
||||||
BeforeFunctions: []
|
|
||||||
bodyKeys:
|
|
||||||
- name
|
|
||||||
formatEN: Download file [name]
|
|
||||||
formatZH: 下载文件 [name]
|
|
||||||
paramKeys: []
|
|
||||||
/files/favorite:
|
/files/favorite:
|
||||||
post:
|
post:
|
||||||
consumes:
|
consumes:
|
||||||
|
@ -427,7 +427,8 @@ export function toLowerCase(str: string) {
|
|||||||
|
|
||||||
export function downloadFile(filePath: string) {
|
export function downloadFile(filePath: string) {
|
||||||
let url = `${import.meta.env.VITE_API_URL as string}/files/download?`;
|
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) {
|
export function downloadWithContent(content: string, fileName: string) {
|
||||||
@ -439,7 +440,6 @@ export function downloadWithContent(content: string, fileName: string) {
|
|||||||
const event = new MouseEvent('click');
|
const event = new MouseEvent('click');
|
||||||
a.dispatchEvent(event);
|
a.dispatchEvent(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getDateStr() {
|
export function getDateStr() {
|
||||||
let now: Date = new Date();
|
let now: Date = new Date();
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user