-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
⚡ (fileUpload) New visibility option: "Public", "Private" or "Auto" (#…
…1196) <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **New Features** - Introduced file visibility options for uploaded files, allowing users to set files as public or private. - Added a new API endpoint for retrieving temporary URLs for files, enhancing file accessibility. - Expanded file upload documentation to include information on file visibility settings. - Updated URL validation to support URLs with port numbers and "http://localhost". - **Enhancements** - Improved media download functionality by replacing the `got` library with a custom `downloadMedia` function. - Enhanced bot flow continuation and session start logic to support a wider range of reply types, including WhatsApp media messages. - **Bug Fixes** - Adjusted file path and URL construction in the `generateUploadUrl` function to correctly reflect file visibility settings. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
- Loading branch information
1 parent
515fcaf
commit 6215cfb
Showing
17 changed files
with
305 additions
and
76 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
66 changes: 66 additions & 0 deletions
66
apps/builder/src/pages/api/typebots/[typebotId]/results/[resultId]/[fileName].ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import prisma from '@typebot.io/lib/prisma' | ||
import { NextApiRequest, NextApiResponse } from 'next' | ||
import { getAuthenticatedUser } from '@/features/auth/helpers/getAuthenticatedUser' | ||
import { | ||
badRequest, | ||
methodNotAllowed, | ||
notAuthenticated, | ||
notFound, | ||
} from '@typebot.io/lib/api' | ||
import { getFileTempUrl } from '@typebot.io/lib/s3/getFileTempUrl' | ||
import { isReadTypebotForbidden } from '@/features/typebot/helpers/isReadTypebotForbidden' | ||
|
||
const handler = async (req: NextApiRequest, res: NextApiResponse) => { | ||
if (req.method === 'GET') { | ||
const user = await getAuthenticatedUser(req, res) | ||
if (!user) return notAuthenticated(res) | ||
|
||
const typebotId = req.query.typebotId as string | ||
const resultId = req.query.resultId as string | ||
const fileName = req.query.fileName as string | ||
|
||
if (!fileName) return badRequest(res, 'fileName missing not found') | ||
|
||
const typebot = await prisma.typebot.findFirst({ | ||
where: { | ||
id: typebotId, | ||
}, | ||
select: { | ||
whatsAppCredentialsId: true, | ||
collaborators: { | ||
select: { | ||
userId: true, | ||
}, | ||
}, | ||
workspace: { | ||
select: { | ||
id: true, | ||
isSuspended: true, | ||
isPastDue: true, | ||
members: { | ||
select: { | ||
userId: true, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}) | ||
|
||
if (!typebot?.workspace || (await isReadTypebotForbidden(typebot, user))) | ||
return notFound(res, 'Workspace not found') | ||
|
||
if (!typebot) return notFound(res, 'Typebot not found') | ||
|
||
const tmpUrl = await getFileTempUrl({ | ||
key: `private/workspaces/${typebot.workspace.id}/typebots/${typebotId}/results/${resultId}/${fileName}`, | ||
}) | ||
|
||
if (!tmpUrl) return notFound(res, 'File not found') | ||
|
||
return res.redirect(tmpUrl) | ||
} | ||
return methodNotAllowed(res) | ||
} | ||
|
||
export default handler |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
const urlRegex = | ||
/^(https?:\/\/(?:www\.|(?!www))[a-zA-Z0-9][a-zA-Z0-9-]+[a-zA-Z0-9]\.[^\s]{2,}|www\.[a-zA-Z0-9][a-zA-Z0-9-]+[a-zA-Z0-9]\.[^\s]{2,}|https?:\/\/(?:www\.|(?!www))[a-zA-Z0-9]+\.[^\s]{2,}|www\.[a-zA-Z0-9]+\.[^\s]{2,})$/ | ||
/^(https?:\/\/(?:www\.|(?!www))[a-zA-Z0-9][a-zA-Z0-9-]+[a-zA-Z0-9]:[0-9]*\.[^\s]{2,}|www\.[a-zA-Z0-9][a-zA-Z0-9-]+[a-zA-Z0-9]:[0-9]*\.[^\s]{2,}|https?:\/\/(?:www\.|(?!www))[a-zA-Z0-9]+\.[^\s]{2,}|www\.[a-zA-Z0-9]+\.[^\s]{2,})$/ | ||
|
||
export const validateUrl = (url: string) => urlRegex.test(url) | ||
export const validateUrl = (url: string) => | ||
url.startsWith('http://localhost') || urlRegex.test(url) |
Oops, something went wrong.