@@ -9,7 +9,7 @@ import { response } from "..";
99import * as configuration from "../../configuration" ;
1010import { AvailableMirror , CommentReply } from "../../entity" ;
1111import { redditapi } from "../../services" ;
12- import { CommentReplyStatus } from "../../structures" ;
12+ import { CommentReplyStatus , LinkType } from "../../structures" ;
1313
1414const router : Router = Router ( ) ;
1515
@@ -47,25 +47,58 @@ async function hasStickiedReplies(submissionId: string) {
4747 return false ;
4848}
4949
50+ const generateFormattedDownloads = ( downloads : AvailableMirror [ ] ) => {
51+ const formattedDownloads = [ ] ;
52+
53+ downloads . forEach ( ( download ) => {
54+ const [ mirrorUrl , botUsername ] = [
55+ download . mirrorUrl ,
56+ download . bot . username ,
57+ ] ;
58+
59+ formattedDownloads . push ( ) ;
60+ } ) ;
61+ } ;
62+
5063/**
5164 * Generates a formatted comment reply string containing all available mirrors
5265 * @param mirrors An array of AvailableMirror objects
5366 */
54- function generateFormattedMirrors ( mirrors : AvailableMirror [ ] ) : string {
55- let formattedMirrors : string [ ] = [ ] ;
56-
57- for ( let i = 0 ; i < mirrors . length ; i ++ ) {
58- const mirror = mirrors [ i ] ;
67+ function generateFormattedMirrors ( allMirrors : AvailableMirror [ ] ) : string {
68+ const [ mirrors , downloads ] = [
69+ allMirrors . filter ( ( obj ) => obj . linkType === LinkType . Mirror ) ,
70+ allMirrors . filter ( ( obj ) => obj . linkType === LinkType . Download ) ,
71+ ] ;
72+ const hasMirrorsAndLinks = mirrors . length > 0 && downloads . length > 0 ;
73+ const formattedLinks : string [ ] = [ ] ;
74+
75+ const appendAll = ( links : AvailableMirror [ ] ) =>
76+ links . forEach ( ( link , idx ) => {
77+ const prefix =
78+ link . linkType === null || link . linkType === LinkType . Mirror
79+ ? "Mirror"
80+ : "Download" ;
81+ const [ mirrorUrl , botUsername ] = [ link . mirrorUrl , link . bot . username ] ;
82+
83+ formattedLinks . push (
84+ `* [${ prefix } #${
85+ idx + 1
86+ } ](${ mirrorUrl } ) (provided by /u/${ botUsername } )`
87+ ) ;
88+ } ) ;
5989
60- let mirrorUrl = mirror . mirrorUrl ;
61- let botUsername = mirror . bot . username ;
90+ if ( mirrors . length > 0 ) {
91+ formattedLinks . push ( `**Mirrors**` , `\n` ) ;
92+ appendAll ( mirrors ) ;
93+ }
6294
63- formattedMirrors . push (
64- `* [Mirror #${ i + 1 } ](${ mirrorUrl } ) (provided by /u/${ botUsername } )`
65- ) ;
95+ if ( downloads . length > 0 ) {
96+ if ( hasMirrorsAndLinks ) formattedLinks . push ( "\n" ) ;
97+ formattedLinks . push ( `**Downloads**` , `\n` ) ;
98+ appendAll ( downloads ) ;
6699 }
67100
68- return TEMPLATE_COMMENTREPLY . replace ( "%s" , formattedMirrors . join ( "\n" ) ) ;
101+ return TEMPLATE_COMMENTREPLY . replace ( "%s" , formattedLinks . join ( "\n" ) ) ;
69102}
70103
71104/**
0 commit comments