make contentDisposition optional
This commit is contained in:
@@ -153,6 +153,7 @@ export async function fileDownloadHandler(
|
|||||||
res: FastifyReply
|
res: FastifyReply
|
||||||
) {
|
) {
|
||||||
const { fileId } = req.params as { fileId: string };
|
const { fileId } = req.params as { fileId: string };
|
||||||
|
const { contentDisposition } = req.query as { contentDisposition: boolean };
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const file = await getFile(fileId, req.user.tenantId);
|
const file = await getFile(fileId, req.user.tenantId);
|
||||||
@@ -162,7 +163,11 @@ export async function fileDownloadHandler(
|
|||||||
if (file.mimeType == "folder")
|
if (file.mimeType == "folder")
|
||||||
return res.code(400).send({ error: "cannot download a folder" });
|
return res.code(400).send({ error: "cannot download a folder" });
|
||||||
|
|
||||||
const signedUrl = await getFileUrlS3(file.pid, file.name);
|
const signedUrl = await getFileUrlS3(
|
||||||
|
file.pid,
|
||||||
|
file.name,
|
||||||
|
contentDisposition
|
||||||
|
);
|
||||||
return res.code(200).send({ url: signedUrl });
|
return res.code(200).send({ url: signedUrl });
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
return err;
|
return err;
|
||||||
|
|||||||
@@ -87,12 +87,18 @@ export async function completeMultiPartUpload(
|
|||||||
await client.send(command);
|
await client.send(command);
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function getFileUrlS3(key: string, name: string | null) {
|
export async function getFileUrlS3(
|
||||||
|
key: string,
|
||||||
|
name: string | null,
|
||||||
|
contentDisposition: boolean
|
||||||
|
) {
|
||||||
const command = new GetObjectCommand({
|
const command = new GetObjectCommand({
|
||||||
Bucket: BUCKET,
|
Bucket: BUCKET,
|
||||||
Key: key,
|
Key: key,
|
||||||
ResponseContentDisposition:
|
ResponseContentDisposition:
|
||||||
name !== null ? `attachment; filename=${name}` : undefined,
|
contentDisposition && name !== null
|
||||||
|
? `attachment; filename=${name}`
|
||||||
|
: undefined,
|
||||||
});
|
});
|
||||||
|
|
||||||
return await getSignedUrl(client, command, { expiresIn: 300 });
|
return await getSignedUrl(client, command, { expiresIn: 300 });
|
||||||
|
|||||||
Reference in New Issue
Block a user