@@ -55,69 +55,95 @@ private static async Task DownloadSingleUrlOption()
55
55
{
56
56
try
57
57
{
58
- // Get URL from user and api response
59
- GofileDataModel gofileData = JsonSerializer . Deserialize < GofileDataModel > (
60
- await GetResponse ( ConsoleHelper . PromptUserForUrl ( ) ) ) ;
58
+ // Get URL from user and check if working
59
+ string url = ConsoleHelper . PromptUserForUrl ( ) ;
60
+ string response = await GetResponse ( url ) ;
61
+ GofileDataModel gofileData = JsonSerializer . Deserialize < GofileDataModel > ( response ) ;
61
62
62
63
// Add files to list
63
64
List < GofileDataModel . Child > fileList = [ ] ;
64
65
foreach ( var item in gofileData . Data . Children . Values )
65
66
{
66
67
fileList . Add ( item ) ;
67
68
}
68
-
69
- await DownloadFiles ( fileList ) ;
70
69
70
+ await DownloadFiles ( fileList ) ;
71
71
}
72
72
catch ( InvalidInputException ex )
73
73
{
74
74
ConsoleHelper . WriteError ( ex . Message ) ;
75
+ return ;
76
+ }
77
+ catch ( InvalidTokenException ex )
78
+ {
79
+ ConsoleHelper . WriteError ( ex . Message ) ;
80
+ return ;
75
81
}
76
82
}
77
83
private static async Task DownloadMultipleUrlOption ( )
78
84
{
79
- // Load Urls from file if theres any
80
- List < string > ? urls = UrlHelper . LoadUrlsFromFile ( ) ;
81
- if ( urls == null )
85
+ try
82
86
{
83
- ConsoleHelper . WriteError ( "There are no links in your urls.txt file" ) ;
84
- return ;
85
- }
87
+ // Load Urls from file if theres any
88
+ List < string > ? urls = UrlHelper . LoadUrlsFromFile ( ) ;
89
+ if ( urls == null )
90
+ {
91
+ ConsoleHelper . WriteError ( "There are no links in your urls.txt file" ) ;
92
+ return ;
93
+ }
86
94
87
- // Validate loaded Urls
88
- List < string > validUrls = [ ] ;
89
- foreach ( var url in urls )
90
- {
91
- bool isValid = Regex . Match ( url , Constants . Regex . GOFILE_REGEX ) . Success ;
92
- if ( isValid )
95
+ // Validate loaded Urls
96
+ List < string > validUrls = [ ] ;
97
+ foreach ( var url in urls )
93
98
{
94
- validUrls . Add ( url ) ;
99
+ bool isValid = Regex . Match ( url , Constants . Regex . GOFILE_REGEX ) . Success ;
100
+ if ( isValid )
101
+ {
102
+ validUrls . Add ( url ) ;
103
+ }
95
104
}
96
- }
97
105
98
- // Ask user if wants to continue if any of the links were bad
99
- if ( urls . Count != validUrls . Count && ! AnsiConsole . Confirm ( $ "[red]Only { validUrls . Count } out of { urls . Count } are valid URL's from your urls.txt. Do you wish to continue?[/]" ) )
100
- {
101
- return ;
102
- }
106
+ if ( validUrls . Count <= 0 )
107
+ {
108
+ ConsoleHelper . WriteError ( "There are no valid urls in your urls.txt" ) ;
109
+ return ;
110
+ }
103
111
112
+ // Ask user if wants to continue if any of the links were bad
113
+ if ( urls . Count != validUrls . Count && ! AnsiConsole . Confirm ( $ "[red]Only { validUrls . Count } out of { urls . Count } are valid URL's from your urls.txt. Do you wish to continue?[/]") )
114
+ {
115
+ return ;
116
+ }
104
117
105
- List < GofileDataModel . Child > fileList = [ ] ;
106
- foreach ( var url in validUrls )
107
- {
108
- // Get API responses from urls
109
- GofileDataModel gofileData = JsonSerializer . Deserialize < GofileDataModel > (
110
- await GetResponse ( url ) ) ;
111
118
112
- // Add file download URLs from response
113
- foreach ( var item in gofileData . Data . Children . Values )
119
+ List < GofileDataModel . Child > fileList = [ ] ;
120
+ foreach ( var url in validUrls )
114
121
{
115
- fileList . Add ( item ) ;
122
+ // Get API responses from urls
123
+ GofileDataModel gofileData = JsonSerializer . Deserialize < GofileDataModel > (
124
+ await GetResponse ( url ) ) ;
125
+
126
+ // Add file download URLs from response
127
+ foreach ( var item in gofileData . Data . Children . Values )
128
+ {
129
+ fileList . Add ( item ) ;
130
+ }
131
+
116
132
}
117
133
134
+ await DownloadFiles ( fileList ) ;
118
135
}
119
-
120
- await DownloadFiles ( fileList ) ;
136
+ catch ( InvalidInputException ex )
137
+ {
138
+ ConsoleHelper . WriteError ( ex . Message ) ;
139
+ return ;
140
+ }
141
+ catch ( InvalidTokenException ex )
142
+ {
143
+ ConsoleHelper . WriteError ( ex . Message ) ;
144
+ return ;
145
+ }
146
+
121
147
}
122
148
private static void ChangeToken ( )
123
149
{
@@ -137,17 +163,19 @@ await AnsiConsole.Progress()
137
163
. HideCompleted ( false )
138
164
. Columns ( new ProgressColumn [ ]
139
165
{
140
- new TaskDescriptionColumn { Alignment = Justify . Right } ,
166
+ new TaskDescriptionColumn { Alignment = Justify . Left } ,
141
167
new ProgressBarColumn ( ) ,
142
168
new PercentageColumn ( ) ,
143
169
new RemainingTimeColumn ( ) ,
144
- new SpinnerColumn ( ) ,
145
170
} )
146
171
. StartAsync ( async ctx =>
147
172
{
173
+ var maxLength = fileList . Max ( file => file . Name . Length ) ;
174
+
148
175
var tasks = fileList . Select ( file =>
149
176
{
150
- var progressTask = ctx . AddTask ( $ "[yellow]{ file . Name } [/]", autoStart : false ) ;
177
+ var paddedName = file . Name . PadRight ( maxLength ) ;
178
+ var progressTask = ctx . AddTask ( $ "[yellow]{ paddedName } [/]", autoStart : false ) ;
151
179
152
180
return Task . Run ( async ( ) =>
153
181
{
@@ -178,10 +206,9 @@ private static async Task<string> GetResponse(string url)
178
206
{
179
207
return await APIHelper . GetDataAsync ( url , _config . Token ) ;
180
208
}
181
- catch ( InvalidTokenException ex )
209
+ catch ( InvalidTokenException )
182
210
{
183
- ConsoleHelper . WriteError ( ex . Message ) ;
184
- return string . Empty ;
211
+ throw ;
185
212
}
186
213
}
187
214
}
0 commit comments