mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-18 02:21:13 +00:00
fix(core): Handle missing binary metadata in download urls (#5242)
This commit is contained in:
committed by
GitHub
parent
ac460aa841
commit
21579a8a2a
@@ -95,6 +95,7 @@ import {
|
||||
import { credentialsController } from '@/credentials/credentials.controller';
|
||||
import { oauth2CredentialController } from '@/credentials/oauth2Credential.api';
|
||||
import type {
|
||||
BinaryDataRequest,
|
||||
CurlHelper,
|
||||
ExecutionRequest,
|
||||
NodeListSearchRequest,
|
||||
@@ -1305,19 +1306,24 @@ class Server extends AbstractServer {
|
||||
// Download binary
|
||||
this.app.get(
|
||||
`/${this.restEndpoint}/data/:path`,
|
||||
async (req: express.Request, res: express.Response): Promise<void> => {
|
||||
async (req: BinaryDataRequest, res: express.Response): Promise<void> => {
|
||||
// TODO UM: check if this needs permission check for UM
|
||||
const identifier = req.params.path;
|
||||
const binaryDataManager = BinaryDataManager.getInstance();
|
||||
const binaryPath = binaryDataManager.getBinaryPath(identifier);
|
||||
const { mimeType, fileName, fileSize } = await binaryDataManager.getBinaryMetadata(
|
||||
identifier,
|
||||
);
|
||||
let { mode, fileName, mimeType } = req.query;
|
||||
if (!fileName || !mimeType) {
|
||||
try {
|
||||
const metadata = await binaryDataManager.getBinaryMetadata(identifier);
|
||||
fileName = metadata.fileName;
|
||||
mimeType = metadata.mimeType;
|
||||
res.setHeader('Content-Length', metadata.fileSize);
|
||||
} catch {}
|
||||
}
|
||||
if (mimeType) res.setHeader('Content-Type', mimeType);
|
||||
if (req.query.mode === 'download' && fileName) {
|
||||
if (mode === 'download') {
|
||||
res.setHeader('Content-Disposition', `attachment; filename="${fileName}"`);
|
||||
}
|
||||
res.setHeader('Content-Length', fileSize);
|
||||
res.sendFile(binaryPath);
|
||||
},
|
||||
);
|
||||
|
||||
11
packages/cli/src/requests.d.ts
vendored
11
packages/cli/src/requests.d.ts
vendored
@@ -350,3 +350,14 @@ export declare namespace CurlHelper {
|
||||
export declare namespace LicenseRequest {
|
||||
type Activate = AuthenticatedRequest<{}, {}, { activationKey: string }, {}>;
|
||||
}
|
||||
|
||||
export type BinaryDataRequest = AuthenticatedRequest<
|
||||
{ path: string },
|
||||
{},
|
||||
{},
|
||||
{
|
||||
mode: 'view' | 'download';
|
||||
fileName?: string;
|
||||
mimeType?: string;
|
||||
}
|
||||
>;
|
||||
|
||||
Reference in New Issue
Block a user