mirror of
https://github.com/RetroShare/RSNewWebUI.git
synced 2026-09-14 11:05:47 +05:00
fix: fixed chunk strategy not working by implementing getChunkStrategy in libretroshare
This commit is contained in:
parent
69935d431a
commit
44de457e55
@ -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: [],
|
||||
|
||||
@ -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 = () => {
|
||||
]),
|
||||
]),
|
||||
]
|
||||
),
|
||||
);
|
||||
},
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user