@@ -31,22 +31,29 @@ import {
3131 listCollections ,
3232 listCollectionsQuerySchema ,
3333 removeCollectionItem ,
34+ resolveCollectionMusicMetadata ,
3435 respondCollectionCollaboratorInvite ,
3536 respondCollectionCollaboratorSchema ,
3637 updateCollection ,
38+ updateCollectionItem ,
39+ updateCollectionItemSchema ,
3740 updateCollectionSchema ,
3841} from "./index.js" ;
3942
4043const collectionParamsSchema = z . object ( {
4144 collectionId : z . string ( ) . trim ( ) . min ( 1 ) ,
4245} ) ;
4346
44- const collectionItemParamsSchema = collectionParamsSchema . extend ( {
45- itemId : z . string ( ) . trim ( ) . min ( 1 ) ,
47+ const collectionItemParamsSchema = collectionParamsSchema . extend ( {
48+ itemId : z . coerce . number ( ) . int ( ) . positive ( ) ,
4649} ) ;
4750
4851const collectionCommentParamsSchema = collectionParamsSchema . extend ( {
49- commentId : z . string ( ) . trim ( ) . min ( 1 ) ,
52+ commentId : z . coerce . number ( ) . int ( ) . positive ( ) ,
53+ } ) ;
54+
55+ const metadataQuerySchema = z . object ( {
56+ url : z . string ( ) . trim ( ) . url ( ) ,
5057} ) ;
5158
5259export function createCollectionsRouter ( ) {
@@ -97,6 +104,16 @@ export function createCollectionsRouter() {
97104 } ) ,
98105 ) ;
99106
107+ router . get (
108+ "/metadata" ,
109+ authUserOptional ,
110+ getUserOptional ,
111+ asyncHandler ( async ( req , res ) => {
112+ const { url } = parseQuery ( req , metadataQuerySchema ) ;
113+ res . json ( await resolveCollectionMusicMetadata ( { url } ) ) ;
114+ } ) ,
115+ ) ;
116+
100117 router . get (
101118 "/:collectionId" ,
102119 authUserOptional ,
@@ -313,5 +330,22 @@ export function createCollectionsRouter() {
313330 } ) ,
314331 ) ;
315332
333+ router . put (
334+ "/:collectionId/items/:itemId" ,
335+ authUser ,
336+ getUser ,
337+ asyncHandler ( async ( req , res ) => {
338+ const { collectionId, itemId } = parseParams ( req , collectionItemParamsSchema ) ;
339+ const input = parseBody ( req , updateCollectionItemSchema ) ;
340+ const result = await updateCollectionItem ( {
341+ collectionId,
342+ itemId,
343+ actor : requireRequestUser ( res ) ,
344+ input,
345+ } ) ;
346+ res . json ( result ) ;
347+ } ) ,
348+ ) ;
349+
316350 return router ;
317351}
0 commit comments