diff --git a/webui-src/app/files/files_downloads.js b/webui-src/app/files/files_downloads.js index 50f330d..acb410f 100644 --- a/webui-src/app/files/files_downloads.js +++ b/webui-src/app/files/files_downloads.js @@ -4,9 +4,20 @@ const util = require('files/files_util'); const widget = require('widgets'); const Downloads = { + strategies: {}, statusMap: {}, hashes: [], + loadStrategy() { + rs.rsJsonApiRequest('/rsFiles/FileDownloads', {}, (d) => + d.hashs.map((hash) => { + rs.rsJsonApiRequest('/rsFiles/getChunkStrategy', { hash }).then( + (res) => (Downloads.strategies[hash] = res.body.retval) + ); + }) + ); + }, + async loadHashes() { await rs.rsJsonApiRequest('/rsFiles/FileDownloads', {}, (d) => (Downloads.hashes = d.hashs)); }, @@ -128,6 +139,7 @@ const NewFileDialog = () => { const Component = () => { return { oninit: () => { + Downloads.loadStrategy(); rs.setBackgroundTask(Downloads.loadStatus, 1000, () => { return m.route.get() === '/files/files'; }); @@ -158,6 +170,7 @@ const Component = () => { Object.keys(Downloads.statusMap).map((hash) => m(util.File, { info: Downloads.statusMap[hash], + strategy: Downloads.strategies[hash], direction: 'down', transferred: Downloads.statusMap[hash].transfered.xint64, parts: [], diff --git a/webui-src/app/files/files_util.js b/webui-src/app/files/files_util.js index 9e619f3..1babb62 100644 --- a/webui-src/app/files/files_util.js +++ b/webui-src/app/files/files_util.js @@ -203,19 +203,19 @@ const ProgressBar = () => { }; }; -const chunkStrats = [ - 'CHUNK_STRATEGY_STREAMING', - 'CHUNK_STRATEGY_RANDOM', - 'CHUNK_STRATEGY_PROGRESSIVE', -]; -const chunkStratsOptions = ['Streaming', 'Random', 'Progressive']; +const chunkStrats = { + 0: 'Streaming', // CHUNK_STRATEGY_STREAMING + 1: 'Random', // CHUNK_STRATEGY_RANDOM + 2: 'Progressive', // CHUNK_STRATEGY_PROGRESSIVE +}; // rstypes.h :: 366 const File = () => { let chunkStrat; return { - view: (v) => - m( + view: (v) => { + chunkStrat = v.attrs && v.attrs.strategy; + return m( '.file-view', { key: v.attrs.info.hash, @@ -234,14 +234,18 @@ const File = () => { { value: chunkStrat, onchange: (e) => { - chunkStrat = chunkStrats[e.target.selectedIndex]; + chunkStrat = Object.keys(chunkStrats)[e.target.selectedIndex]; rs.rsJsonApiRequest('/rsFiles/setChunkStrategy', { hash: v.attrs.info.hash, newStrategy: chunkStrat, }); }, }, - [chunkStratsOptions.map((opt) => m('option', { value: opt }, opt))] + [ + Object.keys(chunkStrats).map((opt) => + m('option', { value: opt }, chunkStrats[opt]) + ), + ] ), ]), ], @@ -292,7 +296,8 @@ const File = () => { ]), ]), ] - ), + ); + }, }; };