@@ -5,7 +5,6 @@ import slugify from 'slugify'
55import Torrent from '../schema/torrent'
66import User from '../schema/user'
77import Comment from '../schema/comment'
8- import { tracker } from '../index'
98
109export const embellishTorrentsWithTrackerScrape = async ( tracker , torrents ) => {
1110 if ( ! torrents . length ) return [ ]
@@ -46,6 +45,23 @@ export const uploadTorrent = async (req, res) => {
4645 return
4746 }
4847
48+ if ( process . env . SQ_TORRENT_CATEGORIES . length ) {
49+ const sources =
50+ process . env . SQ_TORRENT_CATEGORIES [
51+ Object . keys ( process . env . SQ_TORRENT_CATEGORIES ) . find (
52+ ( cat ) => slugify ( cat , { lower : true } ) === req . body . type
53+ )
54+ ]
55+ if (
56+ ! sources
57+ . map ( ( source ) => slugify ( source , { lower : true } ) )
58+ . includes ( req . body . source )
59+ ) {
60+ res . status ( 400 ) . send ( 'Torrent must have a source' )
61+ return
62+ }
63+ }
64+
4965 const user = await User . findOne ( { _id : req . userId } ) . lean ( )
5066
5167 if (
@@ -87,6 +103,7 @@ export const uploadTorrent = async (req, res) => {
87103 name : req . body . name ,
88104 description : req . body . description ,
89105 type : req . body . type ,
106+ source : req . body . source ,
90107 infoHash,
91108 binary : req . body . torrent ,
92109 uploadedBy : req . userId ,
@@ -157,6 +174,7 @@ export const fetchTorrent = (tracker) => async (req, res) => {
157174 name : 1 ,
158175 description : 1 ,
159176 type : 1 ,
177+ source : 1 ,
160178 infoHash : 1 ,
161179 uploadedBy : 1 ,
162180 downloads : 1 ,
@@ -441,7 +459,7 @@ export const searchTorrents = (tracker) => async (req, res) => {
441459 try {
442460 const torrents = await getTorrentsPage ( {
443461 skip : page ? parseInt ( page ) : 0 ,
444- query : decodeURIComponent ( query ) ,
462+ query : query ? decodeURIComponent ( query ) : undefined ,
445463 category,
446464 tag,
447465 tracker,
0 commit comments