@@ -21,7 +21,7 @@ enum BrandingSubmissionType {
21
21
Thumbnail = "thumbnail"
22
22
}
23
23
24
- export async function getVideoBranding ( res : Response , videoID : VideoID , service : Service , ip : IPAddress , returnUserID : boolean ) : Promise < BrandingResult > {
24
+ export async function getVideoBranding ( res : Response , videoID : VideoID , service : Service , ip : IPAddress , returnUserID : boolean , fetchAll : boolean ) : Promise < BrandingResult > {
25
25
const getTitles = ( ) => db . prepare (
26
26
"all" ,
27
27
`SELECT "titles"."title", "titles"."original", "titleVotes"."votes", "titleVotes"."downvotes", "titleVotes"."locked", "titleVotes"."shadowHidden", "titles"."UUID", "titles"."videoID", "titles"."hashedVideoID", "titleVotes"."verification", "titles"."userID"
@@ -83,10 +83,10 @@ export async function getVideoBranding(res: Response, videoID: VideoID, service:
83
83
currentIP : null as Promise < HashedIP > | null
84
84
} ;
85
85
86
- return filterAndSortBranding ( videoID , returnUserID , branding . titles , branding . thumbnails , branding . segments , ip , cache ) ;
86
+ return filterAndSortBranding ( videoID , returnUserID , fetchAll , branding . titles , branding . thumbnails , branding . segments , ip , cache ) ;
87
87
}
88
88
89
- export async function getVideoBrandingByHash ( videoHashPrefix : VideoIDHash , service : Service , ip : IPAddress , returnUserID : boolean ) : Promise < Record < VideoID , BrandingResult > > {
89
+ export async function getVideoBrandingByHash ( videoHashPrefix : VideoIDHash , service : Service , ip : IPAddress , returnUserID : boolean , fetchAll : boolean ) : Promise < Record < VideoID , BrandingResult > > {
90
90
const getTitles = ( ) => db . prepare (
91
91
"all" ,
92
92
`SELECT "titles"."title", "titles"."original", "titleVotes"."votes", "titleVotes"."downvotes", "titleVotes"."locked", "titleVotes"."shadowHidden", "titles"."UUID", "titles"."videoID", "titles"."hashedVideoID", "titleVotes"."verification"
@@ -158,14 +158,14 @@ export async function getVideoBrandingByHash(videoHashPrefix: VideoIDHash, servi
158
158
const processedResult : Record < VideoID , BrandingResult > = { } ;
159
159
await Promise . all ( Object . keys ( branding ) . map ( async ( key ) => {
160
160
const castedKey = key as VideoID ;
161
- processedResult [ castedKey ] = await filterAndSortBranding ( castedKey , returnUserID , branding [ castedKey ] . titles ,
161
+ processedResult [ castedKey ] = await filterAndSortBranding ( castedKey , returnUserID , fetchAll , branding [ castedKey ] . titles ,
162
162
branding [ castedKey ] . thumbnails , branding [ castedKey ] . segments , ip , cache ) ;
163
163
} ) ) ;
164
164
165
165
return processedResult ;
166
166
}
167
167
168
- async function filterAndSortBranding ( videoID : VideoID , returnUserID : boolean , dbTitles : TitleDBResult [ ] ,
168
+ async function filterAndSortBranding ( videoID : VideoID , returnUserID : boolean , fetchAll : boolean , dbTitles : TitleDBResult [ ] ,
169
169
dbThumbnails : ThumbnailDBResult [ ] , dbSegments : BrandingSegmentDBResult [ ] ,
170
170
ip : IPAddress , cache : { currentIP : Promise < HashedIP > | null } ) : Promise < BrandingResult > {
171
171
@@ -181,6 +181,7 @@ async function filterAndSortBranding(videoID: VideoID, returnUserID: boolean, db
181
181
UUID : r . UUID ,
182
182
userID : returnUserID ? r . userID : undefined
183
183
} ) )
184
+ . filter ( ( a ) => fetchAll || a . votes > 0 || a . locked )
184
185
. sort ( ( a , b ) => b . votes - a . votes )
185
186
. sort ( ( a , b ) => + b . locked - + a . locked ) as TitleResult [ ] ;
186
187
@@ -195,7 +196,8 @@ async function filterAndSortBranding(videoID: VideoID, returnUserID: boolean, db
195
196
locked : r . locked === 1 ,
196
197
UUID : r . UUID ,
197
198
userID : returnUserID ? r . userID : undefined
198
- } ) ) as ThumbnailResult [ ] ;
199
+ } ) )
200
+ . filter ( ( a ) => fetchAll || a . votes > 0 || a . locked ) as ThumbnailResult [ ] ;
199
201
200
202
return {
201
203
titles,
@@ -280,14 +282,15 @@ export async function getBranding(req: Request, res: Response) {
280
282
const videoID : VideoID = req . query . videoID as VideoID ;
281
283
const service : Service = getService ( req . query . service as string ) ;
282
284
const returnUserID = req . query . returnUserID === "true" ;
285
+ const fetchAll = req . query . fetchAll === "true" ;
283
286
284
287
if ( ! videoID ) {
285
288
return res . status ( 400 ) . send ( "Missing parameter: videoID" ) ;
286
289
}
287
290
288
291
const ip = getIP ( req ) ;
289
292
try {
290
- const result = await getVideoBranding ( res , videoID , service , ip , returnUserID ) ;
293
+ const result = await getVideoBranding ( res , videoID , service , ip , returnUserID , fetchAll ) ;
291
294
292
295
const status = result . titles . length > 0 || result . thumbnails . length > 0 ? 200 : 404 ;
293
296
return res . status ( status ) . json ( result ) ;
@@ -307,9 +310,10 @@ export async function getBrandingByHashEndpoint(req: Request, res: Response) {
307
310
const service : Service = getService ( req . query . service as string ) ;
308
311
const ip = getIP ( req ) ;
309
312
const returnUserID = req . query . returnUserID === "true" ;
313
+ const fetchAll = req . query . fetchAll === "true" ;
310
314
311
315
try {
312
- const result = await getVideoBrandingByHash ( hashPrefix , service , ip , returnUserID ) ;
316
+ const result = await getVideoBrandingByHash ( hashPrefix , service , ip , returnUserID , fetchAll ) ;
313
317
314
318
const status = ! isEmpty ( result ) ? 200 : 404 ;
315
319
return res . status ( status ) . json ( result ) ;
0 commit comments