@@ -8,11 +8,25 @@ const router = Router();
88
99type Format = 'gif' | 'mp4' ;
1010
11- const UUID = / ^ [ 0 - 9 a - f ] { 8 } - [ 0 - 9 a - f ] { 4 } - [ 0 - 9 a - f ] { 4 } - [ 0 - 9 a - f ] { 4 } - [ 0 - 9 a - f ] { 12 } $ / i;
11+ const SLUG = / ^ [ a - z 0 - 9 - ] + $ / i;
1212
13- function readProjectId ( req : Request ) : string | null {
14- const id : unknown = typeof req . body === 'object' && req . body ? req . body . projectId : undefined ;
15- return typeof id === 'string' && UUID . test ( id ) ? id . toLowerCase ( ) : null ;
13+ interface ProjectRef {
14+ userSlug : string ;
15+ projectSlug : string ;
16+ }
17+
18+ function readProjectRef ( req : Request ) : ProjectRef | null {
19+ const body = typeof req . body === 'object' && req . body ? req . body : { } ;
20+ const { userSlug, projectSlug } = body ;
21+ if (
22+ typeof userSlug === 'string' &&
23+ typeof projectSlug === 'string' &&
24+ SLUG . test ( userSlug ) &&
25+ SLUG . test ( projectSlug )
26+ ) {
27+ return { userSlug : userSlug . toLowerCase ( ) , projectSlug : projectSlug . toLowerCase ( ) } ;
28+ }
29+ return null ;
1630}
1731
1832/**
@@ -23,13 +37,13 @@ function readProjectId(req: Request): string | null {
2337 */
2438async function handle ( format : Format , req : Request , res : Response ) : Promise < void > {
2539 try {
26- const projectId = readProjectId ( req ) ;
27- if ( ! projectId ) {
28- res . status ( 400 ) . json ( { error : 'No valid projectId provided' } ) ;
40+ const ref = readProjectRef ( req ) ;
41+ if ( ! ref ) {
42+ res . status ( 400 ) . json ( { error : 'No valid project reference provided' } ) ;
2943 return ;
3044 }
3145
32- const project = await fetchProject ( projectId ) ;
46+ const project = await fetchProject ( ref . userSlug , ref . projectSlug ) ;
3347 if ( ! project ) {
3448 res . status ( 404 ) . json ( { error : 'Project not found or not public' } ) ;
3549 return ;
@@ -59,7 +73,7 @@ async function handle(format: Format, req: Request, res: Response): Promise<void
5973 await generator . initialize ( ) ;
6074
6175 console . log (
62- `Generating ${ format . toUpperCase ( ) } from project ${ projectId } (lang=${ project . lang } )...` ,
76+ `Generating ${ format . toUpperCase ( ) } from project ${ ref . userSlug } / ${ ref . projectSlug } (lang=${ project . lang } )...` ,
6377 ) ;
6478 if ( format === 'mp4' ) {
6579 const mp4 = await generator . generateMp4FromTAP ( tap , machineType ) ;
0 commit comments