1+ import { NextRouter } from "next/router" ;
2+
13import slugify from "@sindresorhus/slugify" ;
24import { upload } from "@vercel/blob/client" ;
35import { Message } from "ai" ;
@@ -6,7 +8,6 @@ import { type ClassValue, clsx } from "clsx";
68import crypto from "crypto" ;
79import ms from "ms" ;
810import { customAlphabet } from "nanoid" ;
9- import { NextRouter } from "next/router" ;
1011import { ThreadMessage } from "openai/resources/beta/threads/messages/messages" ;
1112import { rgb } from "pdf-lib" ;
1213import { ParsedUrlQuery } from "querystring" ;
@@ -394,6 +395,10 @@ export function constructMetadata({
394395 } ;
395396}
396397
398+ export const isDataUrl = ( str : string ) : boolean => {
399+ return str ?. startsWith ( "data:" ) ;
400+ } ;
401+
397402export const convertDataUrlToFile = ( {
398403 dataUrl,
399404 filename = "logo.png" ,
@@ -422,6 +427,30 @@ export const convertDataUrlToFile = ({
422427 return new File ( [ u8arr ] , filename , { type : mime } ) ;
423428} ;
424429
430+ export const convertDataUrlToBuffer = (
431+ dataUrl : string ,
432+ ) : { buffer : Buffer ; mimeType : string ; filename : string } => {
433+ // Extract mime type
434+ const match = dataUrl . match ( / : ( .* ?) ; / ) ;
435+ const mimeType = match ? match [ 1 ] : "" ;
436+
437+ // Extract base64 data
438+ const base64Data = dataUrl . split ( "," ) [ 1 ] ;
439+ const buffer = Buffer . from ( base64Data , "base64" ) ;
440+
441+ // Determine filename based on mime type
442+ const filename =
443+ mimeType === "image/png"
444+ ? "image.png"
445+ : mimeType === "image/jpeg"
446+ ? "image.jpg"
447+ : mimeType === "image/x-icon" || mimeType === "image/vnd.microsoft.icon"
448+ ? "favicon.ico"
449+ : "image" ;
450+
451+ return { buffer, mimeType, filename } ;
452+ } ;
453+
425454export const validateImageDimensions = (
426455 image : string ,
427456 minSize : number ,
@@ -563,15 +592,15 @@ export const getBreadcrumbPath = (path: string[]) => {
563592} ;
564593
565594export const handleInvitationStatus = (
566- invitationStatus : ' accepted' | ' teamMember' ,
595+ invitationStatus : " accepted" | " teamMember" ,
567596 queryParams : ParsedUrlQuery ,
568597 router : NextRouter ,
569598) => {
570599 switch ( invitationStatus ) {
571- case ' accepted' :
600+ case " accepted" :
572601 toast . success ( "Welcome to the team! You've successfully joined." ) ;
573602 break ;
574- case ' teamMember' :
603+ case " teamMember" :
575604 toast . error ( "You've already accepted this invitation!" ) ;
576605 break ;
577606 default :
0 commit comments