mirror of
https://github.com/NapNeko/NapCatQQ.git
synced 2025-07-19 12:03:37 +00:00
fix: 文件下载
This commit is contained in:
@@ -9,6 +9,7 @@ import {
|
|||||||
import { Spinner } from '@heroui/spinner'
|
import { Spinner } from '@heroui/spinner'
|
||||||
import { useRequest } from 'ahooks'
|
import { useRequest } from 'ahooks'
|
||||||
import path from 'path-browserify'
|
import path from 'path-browserify'
|
||||||
|
import { useEffect } from 'react'
|
||||||
|
|
||||||
import FileManager from '@/controllers/file_manager'
|
import FileManager from '@/controllers/file_manager'
|
||||||
|
|
||||||
@@ -33,6 +34,7 @@ export default function FilePreviewModal({
|
|||||||
async () => FileManager.downloadToURL(filePath),
|
async () => FileManager.downloadToURL(filePath),
|
||||||
{
|
{
|
||||||
refreshDeps: [filePath],
|
refreshDeps: [filePath],
|
||||||
|
manual: true,
|
||||||
refreshDepsAction: () => {
|
refreshDepsAction: () => {
|
||||||
const ext = path.extname(filePath).toLowerCase()
|
const ext = path.extname(filePath).toLowerCase()
|
||||||
if (!filePath || !supportedPreviewExts.includes(ext)) {
|
if (!filePath || !supportedPreviewExts.includes(ext)) {
|
||||||
@@ -66,6 +68,12 @@ export default function FilePreviewModal({
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (filePath) {
|
||||||
|
run()
|
||||||
|
}
|
||||||
|
}, [])
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Modal isOpen={isOpen} onClose={onClose} scrollBehavior="inside" size="3xl">
|
<Modal isOpen={isOpen} onClose={onClose} scrollBehavior="inside" size="3xl">
|
||||||
<ModalContent>
|
<ModalContent>
|
||||||
|
@@ -33,6 +33,7 @@ export default function ImageNameButton({
|
|||||||
async () => FileManager.downloadToURL(filePath),
|
async () => FileManager.downloadToURL(filePath),
|
||||||
{
|
{
|
||||||
refreshDeps: [filePath],
|
refreshDeps: [filePath],
|
||||||
|
manual: true,
|
||||||
refreshDepsAction: () => {
|
refreshDepsAction: () => {
|
||||||
const ext = path.extname(filePath).toLowerCase()
|
const ext = path.extname(filePath).toLowerCase()
|
||||||
if (!filePath || !imageExts.includes(ext)) {
|
if (!filePath || !imageExts.includes(ext)) {
|
||||||
@@ -52,6 +53,11 @@ export default function ImageNameButton({
|
|||||||
}
|
}
|
||||||
}, [data, name, onAddPreview])
|
}, [data, name, onAddPreview])
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (filePath) {
|
||||||
|
run()
|
||||||
|
}
|
||||||
|
}, [])
|
||||||
return (
|
return (
|
||||||
<Button
|
<Button
|
||||||
variant="light"
|
variant="light"
|
||||||
|
@@ -268,7 +268,11 @@ export const BatchMoveHandler: RequestHandler = async (req, res) => {
|
|||||||
// 新增:文件下载处理方法(注意流式传输,不将整个文件读入内存)
|
// 新增:文件下载处理方法(注意流式传输,不将整个文件读入内存)
|
||||||
export const DownloadHandler: RequestHandler = async (req, res) => {
|
export const DownloadHandler: RequestHandler = async (req, res) => {
|
||||||
try {
|
try {
|
||||||
const filePath = normalizePath(req.query['path'] as string);
|
const filePath = normalizePath( req.query[ 'path' ] as string );
|
||||||
|
if (!filePath) {
|
||||||
|
return sendError( res, '参数错误' );
|
||||||
|
}
|
||||||
|
|
||||||
const stat = await fsProm.stat(filePath);
|
const stat = await fsProm.stat(filePath);
|
||||||
|
|
||||||
res.setHeader('Content-Type', 'application/octet-stream');
|
res.setHeader('Content-Type', 'application/octet-stream');
|
||||||
|
Reference in New Issue
Block a user