7373 <v-btn
7474 v-tooltip =" 'Frees up space on the SD card'"
7575 class =" ma-2"
76- :disabled =" disable_remove"
76+ :disabled =" disable_remove || deletion_in_progress "
7777 @click =" remove_service_log_files"
7878 >
7979 <v-icon left >
8383 </v-btn >
8484 </v-card-actions >
8585
86+ <v-expand-transition >
87+ <div v-if =" deletion_in_progress" class =" pa-4" >
88+ <v-progress-linear
89+ indeterminate
90+ color =" primary"
91+ />
92+ <div class =" mt-2" >
93+ <div class =" text-subtitle-2" >
94+ Deleting: {{ current_deletion_path }}
95+ </div >
96+ <div class =" text-caption" >
97+ Size: {{ formatSize(current_deletion_size / 1024) }}
98+ </div >
99+ <div class =" text-caption" >
100+ Status: {{ current_deletion_status }}
101+ </div >
102+ </div >
103+ </div >
104+ </v-expand-transition >
105+
86106 <v-divider />
87107
88108 <v-card-title class =" align-center" >
@@ -180,6 +200,10 @@ export default Vue.extend({
180200 operation_in_progress: false ,
181201 operation_description: ' ' ,
182202 operation_error: undefined as undefined | string ,
203+ deletion_in_progress: false ,
204+ current_deletion_path: ' ' ,
205+ current_deletion_size: 0 ,
206+ current_deletion_status: ' ' ,
183207 }
184208 },
185209 computed: {
@@ -197,6 +221,9 @@ export default Vue.extend({
197221 this .operation_in_progress = true
198222 this .operation_description = description
199223 },
224+ formatSize(bytes : number ): string {
225+ return prettifySize (bytes )
226+ },
200227 async download_service_log_files(): Promise <void > {
201228 const folder = await filebrowser .fetchFolder (' system_logs' )
202229 await filebrowser .downloadFolder (folder )
@@ -216,7 +243,7 @@ export default Vue.extend({
216243 const folder_data_bytes = response .data
217244 const one_hundred_MB = 100 * 2 ** 20
218245 this .disable_remove = folder_data_bytes < one_hundred_MB
219- this .log_folder_size = prettifySize (folder_data_bytes / 1024 )
246+ this .log_folder_size = this . formatSize (folder_data_bytes / 1024 )
220247 })
221248 .catch ((error ) => {
222249 this .operation_error = String (error )
@@ -235,7 +262,7 @@ export default Vue.extend({
235262 const folder_data_bytes = response .data
236263 const one_hundred_MB = 100 * 2 ** 20
237264 this .disable_remove_mavlink = folder_data_bytes < one_hundred_MB
238- this .mavlink_log_folder_size = prettifySize (folder_data_bytes / 1024 )
265+ this .mavlink_log_folder_size = this . formatSize (folder_data_bytes / 1024 )
239266 })
240267 .catch ((error ) => {
241268 this .operation_error = String (error )
@@ -265,23 +292,54 @@ export default Vue.extend({
265292 },
266293 async remove_service_log_files(): Promise <void > {
267294 this .prepare_operation (' Removing system log files...' )
295+ this .deletion_in_progress = true
296+ this .current_deletion_path = ' '
297+ this .current_deletion_size = 0
298+ this .current_deletion_status = ' Starting deletion...'
268299
269- await back_axios ({
270- url: ` ${API_URL }/services/remove_log ` ,
271- method: ' post' ,
272- params: {
273- i_know_what_i_am_doing: true ,
274- },
275- timeout: 20000 ,
276- })
277- .then (() => {
278- this .get_log_folder_size ()
300+ try {
301+ const response = await back_axios ({
302+ url: ` ${API_URL }/services/remove_log_stream ` ,
303+ method: ' post' ,
304+ params: {
305+ i_know_what_i_am_doing: true ,
306+ },
307+ responseType: ' stream' ,
308+ timeout: 60000 ,
279309 })
280- .catch ((error ) => {
281- this .operation_error = String (error )
282- notifier .pushBackError (' REMOVE_SERVICES_LOG_FAIL' , error )
283- })
284- this .operation_in_progress = false
310+
311+ const reader = response .data .getReader ()
312+ const decoder = new TextDecoder ()
313+
314+ let readResult = await reader .read ()
315+ while (! readResult .done ) {
316+ const chunk = decoder .decode (readResult .value )
317+ const lines = chunk .split (' \n ' ).filter ((line ) => { line .trim () })
318+
319+ for (const line of lines ) {
320+ try {
321+ const info = JSON .parse (line )
322+ this .current_deletion_path = info .path
323+ this .current_deletion_size = info .size
324+ this .current_deletion_status = info .success ? ' Successfully deleted' : ' Failed to delete'
325+ } catch (e ) {
326+ console .error (' Error parsing deletion info:' , e )
327+ }
328+ }
329+ readResult = await reader .read ()
330+ }
331+
332+ await this .get_log_folder_size ()
333+ } catch (error ) {
334+ this .operation_error = String (error )
335+ notifier .pushBackError (' REMOVE_SERVICES_LOG_FAIL' , error )
336+ } finally {
337+ this .operation_in_progress = false
338+ this .deletion_in_progress = false
339+ this .current_deletion_path = ' '
340+ this .current_deletion_size = 0
341+ this .current_deletion_status = ' '
342+ }
285343 },
286344 async remove_mavlink_log_files(): Promise <void > {
287345 this .prepare_operation (' Removing MAVLink log files...' )
0 commit comments