@@ -38,6 +38,7 @@ window.qBittorrent.AddTorrent ??= (() => {
3838 } ;
3939
4040 let table = null ;
41+ let size = "" ;
4142 let defaultSavePath = "" ;
4243 let defaultTempPath = "" ;
4344 let defaultTempPathEnabled = false ;
@@ -146,7 +147,7 @@ window.qBittorrent.AddTorrent ??= (() => {
146147
147148 if ( isAutoTMMEnabled ( ) ) {
148149 document . getElementById ( "savepath" ) . value = defaultSavePath ;
149- document . getElementById ( "size" ) . textContent = window . qBittorrent . freespaceAutofill . showFreeSpace ( { value : defaultSavePath } ) ;
150+ document . getElementById ( "size" ) . textContent = showFreeSpace ( defaultSavePath ) ;
150151
151152 const downloadPathEnabled = categoryDownloadPathEnabled ( categoryName ) ;
152153 document . getElementById ( "useDownloadPath" ) . checked = downloadPathEnabled ;
@@ -161,7 +162,7 @@ window.qBittorrent.AddTorrent ??= (() => {
161162 if ( isAutoTMMEnabled ( ) ) {
162163 const tempCategoryPath = categorySavePath ( categoryName ) ;
163164 document . getElementById ( "savepath" ) . value = tempCategoryPath ;
164- document . getElementById ( "size" ) . textContent = window . qBittorrent . freespaceAutofill . showFreeSpace ( { value : tempCategoryPath } ) ;
165+ document . getElementById ( "size" ) . textContent = showFreeSpace ( tempCategoryPath ) ;
165166
166167 const downloadPathEnabled = categoryDownloadPathEnabled ( categoryName ) ;
167168 document . getElementById ( "useDownloadPath" ) . checked = downloadPathEnabled ;
@@ -195,7 +196,7 @@ window.qBittorrent.AddTorrent ??= (() => {
195196 useDownloadPath . checked = defaultTempPathEnabled ;
196197 }
197198
198- document . getElementById ( "size" ) . textContent = window . qBittorrent . freespaceAutofill . showFreeSpace ( { value : savepath . value } ) ;
199+ document . getElementById ( "size" ) . textContent = showFreeSpace ( savepath . value ) ;
199200 savepath . disabled = autoTMMEnabled ;
200201 useDownloadPath . disabled = autoTMMEnabled ;
201202
@@ -219,6 +220,25 @@ window.qBittorrent.AddTorrent ??= (() => {
219220 }
220221 } ;
221222
223+ const showFreeSpace = ( element ) => {
224+ if ( element === "" )
225+ return ;
226+
227+ fetch ( `api/v2/app/getFreeSpaceAtPath?path=${ element } ` , {
228+ method : "GET" ,
229+ cache : "no-store"
230+ } )
231+ . then ( response => response . text ( ) )
232+ . then ( freeSpace => { filloutFreeSpace ( freeSpace ) ; } )
233+ . catch ( error => { } ) ;
234+ } ;
235+
236+ const filloutFreeSpace = ( freeSpace ) => {
237+ document . getElementById ( "size" ) . textContent = `${ " QBT_TR(%1 (Free space on disk: %2))QBT_TR[CONTEXT=AddNewTorrentDialog]"
238+ . replace ( "%1" , size )
239+ . replace ( "%2" , window . qBittorrent . Misc . friendlyUnit ( freeSpace , false ) ) } `;
240+ } ;
241+
222242 let loadMetadataTimer = - 1 ;
223243 const loadMetadata = ( sourceUrl = undefined , downloaderName = undefined ) => {
224244 if ( sourceUrl !== undefined )
@@ -285,9 +305,8 @@ window.qBittorrent.AddTorrent ??= (() => {
285305 document . getElementById ( "infoHashV2" ) . textContent = ( metadata . infohash_v2 === undefined ) ? notAvailable : ( metadata . infohash_v2 || notApplicable ) ;
286306
287307 if ( metadata . info ?. length !== undefined ) {
288- const size = document . getElementById ( "size" ) ;
289- size . setAttribute ( "size" , window . qBittorrent . Misc . friendlyUnit ( metadata . info . length , false ) ) ;
290- size . textContent = window . qBittorrent . freespaceAutofill . showFreeSpace ( { value : document . getElementById ( "savepath" ) . value } ) ;
308+ size = window . qBittorrent . Misc . friendlyUnit ( metadata . info . length , false ) ;
309+ document . getElementById ( "size" ) . textContent = showFreeSpace ( document . getElementById ( "savepath" ) . value ) ;
291310 }
292311 if ( ( metadata . creation_date !== undefined ) && ( metadata . creation_date > 1 ) )
293312 document . getElementById ( "createdDate" ) . textContent = window . qBittorrent . Misc . formatDate ( new Date ( metadata . creation_date * 1000 ) ) ;
@@ -333,6 +352,7 @@ window.qBittorrent.AddTorrent ??= (() => {
333352
334353 const init = ( source , downloader , fetchMetadata ) => {
335354 table = window . qBittorrent . TorrentContent . init ( "addTorrentFilesTableDiv" , window . qBittorrent . DynamicTable . AddTorrentFilesTable ) ;
355+ document . getElementById ( "savepath" ) . addEventListener ( "input" , function ( event ) { showFreeSpace ( this . value ) ; } ) ;
336356 if ( fetchMetadata )
337357 loadMetadata ( source , downloader ) ;
338358 } ;
0 commit comments