1
+ import { NextRouter } from "next/router" ;
2
+
1
3
import slugify from "@sindresorhus/slugify" ;
2
4
import { upload } from "@vercel/blob/client" ;
3
5
import { Message } from "ai" ;
@@ -6,7 +8,6 @@ import { type ClassValue, clsx } from "clsx";
6
8
import crypto from "crypto" ;
7
9
import ms from "ms" ;
8
10
import { customAlphabet } from "nanoid" ;
9
- import { NextRouter } from "next/router" ;
10
11
import { ThreadMessage } from "openai/resources/beta/threads/messages/messages" ;
11
12
import { rgb } from "pdf-lib" ;
12
13
import { ParsedUrlQuery } from "querystring" ;
@@ -394,6 +395,10 @@ export function constructMetadata({
394
395
} ;
395
396
}
396
397
398
+ export const isDataUrl = ( str : string ) : boolean => {
399
+ return str ?. startsWith ( "data:" ) ;
400
+ } ;
401
+
397
402
export const convertDataUrlToFile = ( {
398
403
dataUrl,
399
404
filename = "logo.png" ,
@@ -422,6 +427,30 @@ export const convertDataUrlToFile = ({
422
427
return new File ( [ u8arr ] , filename , { type : mime } ) ;
423
428
} ;
424
429
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
+
425
454
export const validateImageDimensions = (
426
455
image : string ,
427
456
minSize : number ,
@@ -563,15 +592,15 @@ export const getBreadcrumbPath = (path: string[]) => {
563
592
} ;
564
593
565
594
export const handleInvitationStatus = (
566
- invitationStatus : ' accepted' | ' teamMember' ,
595
+ invitationStatus : " accepted" | " teamMember" ,
567
596
queryParams : ParsedUrlQuery ,
568
597
router : NextRouter ,
569
598
) => {
570
599
switch ( invitationStatus ) {
571
- case ' accepted' :
600
+ case " accepted" :
572
601
toast . success ( "Welcome to the team! You've successfully joined." ) ;
573
602
break ;
574
- case ' teamMember' :
603
+ case " teamMember" :
575
604
toast . error ( "You've already accepted this invitation!" ) ;
576
605
break ;
577
606
default :
0 commit comments