mirror of
https://github.com/documenso/documenso.git
synced 2025-11-13 08:13:56 +10:00
fix: universal upload hitting cache
This commit is contained in:
@ -1,5 +1,8 @@
|
|||||||
'use server';
|
'use server';
|
||||||
|
|
||||||
|
import { headers } from 'next/headers';
|
||||||
|
import { NextRequest } from 'next/server';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
DeleteObjectCommand,
|
DeleteObjectCommand,
|
||||||
GetObjectCommand,
|
GetObjectCommand,
|
||||||
@ -7,10 +10,11 @@ import {
|
|||||||
S3Client,
|
S3Client,
|
||||||
} from '@aws-sdk/client-s3';
|
} from '@aws-sdk/client-s3';
|
||||||
import slugify from '@sindresorhus/slugify';
|
import slugify from '@sindresorhus/slugify';
|
||||||
|
import { type JWT, getToken } from 'next-auth/jwt';
|
||||||
import path from 'node:path';
|
import path from 'node:path';
|
||||||
|
|
||||||
|
import { APP_BASE_URL } from '../../constants/app';
|
||||||
import { ONE_HOUR, ONE_SECOND } from '../../constants/time';
|
import { ONE_HOUR, ONE_SECOND } from '../../constants/time';
|
||||||
import { getServerComponentSession } from '../../next-auth/get-server-component-session';
|
|
||||||
import { alphaid } from '../id';
|
import { alphaid } from '../id';
|
||||||
|
|
||||||
export const getPresignPostUrl = async (fileName: string, contentType: string) => {
|
export const getPresignPostUrl = async (fileName: string, contentType: string) => {
|
||||||
@ -18,15 +22,25 @@ export const getPresignPostUrl = async (fileName: string, contentType: string) =
|
|||||||
|
|
||||||
const { getSignedUrl } = await import('@aws-sdk/s3-request-presigner');
|
const { getSignedUrl } = await import('@aws-sdk/s3-request-presigner');
|
||||||
|
|
||||||
const { user } = await getServerComponentSession();
|
let token: JWT | null = null;
|
||||||
|
|
||||||
|
try {
|
||||||
|
token = await getToken({
|
||||||
|
req: new NextRequest(APP_BASE_URL ?? 'http://localhost:3000', {
|
||||||
|
headers: headers(),
|
||||||
|
}),
|
||||||
|
});
|
||||||
|
} catch (err) {
|
||||||
|
// Non server-component environment
|
||||||
|
}
|
||||||
|
|
||||||
// Get the basename and extension for the file
|
// Get the basename and extension for the file
|
||||||
const { name, ext } = path.parse(fileName);
|
const { name, ext } = path.parse(fileName);
|
||||||
|
|
||||||
let key = `${alphaid(12)}/${slugify(name)}${ext}`;
|
let key = `${alphaid(12)}/${slugify(name)}${ext}`;
|
||||||
|
|
||||||
if (user) {
|
if (token) {
|
||||||
key = `${user.id}/${key}`;
|
key = `${token.id}/${key}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
const putObjectCommand = new PutObjectCommand({
|
const putObjectCommand = new PutObjectCommand({
|
||||||
|
|||||||
@ -1,5 +1,3 @@
|
|||||||
'use server';
|
|
||||||
|
|
||||||
import { createElement } from 'react';
|
import { createElement } from 'react';
|
||||||
|
|
||||||
import { PDFDocument } from 'pdf-lib';
|
import { PDFDocument } from 'pdf-lib';
|
||||||
|
|||||||
Reference in New Issue
Block a user