@@ -9,6 +9,15 @@ import Comment from "../schema/comment";
99import Group from "../schema/group" ;
1010import { createGroup , addToGroup , removeFromGroup } from "./group" ;
1111
12+ const urlReservedCharRegex = / [ & $ + , / : ; = ? @ # < > \[ \] { } | \\ \^ % ] / g;
13+
14+ const formatTag = ( tag ) =>
15+ tag
16+ . trim ( )
17+ . toLowerCase ( )
18+ . replaceAll ( urlReservedCharRegex , "" )
19+ . replaceAll ( " " , "-" ) ;
20+
1221export const embellishTorrentsWithTrackerScrape = async ( tracker , torrents ) => {
1322 if ( ! torrents . length ) return [ ] ;
1423
@@ -127,9 +136,7 @@ export const uploadTorrent = async (req, res, next) => {
127136 upvotes : [ ] ,
128137 downvotes : [ ] ,
129138 freeleech : false ,
130- tags : ( req . body . tags ?? "" )
131- . split ( "," )
132- . map ( ( t ) => slugify ( t . trim ( ) , { lower : true } ) ) ,
139+ tags : ( req . body . tags ?? "" ) . split ( "," ) . map ( ( t ) => formatTag ( t ) ) ,
133140 group : groupId ,
134141 mediaInfo : req . body . mediaInfo ,
135142 } ) ;
@@ -200,9 +207,7 @@ export const editTorrent = async (req, res, next) => {
200207 type : req . body . type ,
201208 source : req . body . source ,
202209 description : req . body . description ,
203- tags : ( req . body . tags ?? "" )
204- . split ( "," )
205- . map ( ( t ) => slugify ( t . trim ( ) , { lower : true } ) ) ,
210+ tags : ( req . body . tags ?? "" ) . split ( "," ) . map ( ( t ) => formatTag ( t ) ) ,
206211 } ,
207212 mediaInfo : req . body . mediaInfo ,
208213 }
@@ -684,7 +689,7 @@ export const searchTorrents = (tracker) => async (req, res, next) => {
684689 query : query ? decodeURIComponent ( query ) : undefined ,
685690 category,
686691 source,
687- tag,
692+ tag : tag ? decodeURIComponent ( tag ) : undefined ,
688693 userId : req . userId ,
689694 tracker,
690695 } ) ;
0 commit comments