Server implementation. (#90)
* Server implementation. - Share the content of a folder as a magnet file. - Web interface with all data needed for sharing data. - New configuration to add several servers - Every time the content of the server folder is changed, the magnet file will be generated again. Signed-off-by: Antonio Navarro Perez <antnavper@gmail.com> * Update dependencies Signed-off-by: Antonio Navarro Perez <antnavper@gmail.com> * Use boltdb piece completion storage. Signed-off-by: Antonio Navarro Perez <antnavper@gmail.com>
This commit is contained in:
parent
5d4e48f0f9
commit
ddda39b22a
15 changed files with 541 additions and 67 deletions
assets/js
54
assets/js/servers.js
Normal file
54
assets/js/servers.js
Normal file
|
@ -0,0 +1,54 @@
|
|||
Handlebars.registerHelper("to_date", function (timestamp) {
|
||||
return new Date(timestamp * 1000).toLocaleString()
|
||||
});
|
||||
|
||||
Distribyted.servers = {
|
||||
_template: null,
|
||||
|
||||
_getTemplate: function () {
|
||||
if (this._template != null) {
|
||||
return this._template
|
||||
}
|
||||
|
||||
const tTemplate = fetch('/assets/templates/servers.html')
|
||||
.then((response) => {
|
||||
if (response.ok) {
|
||||
return response.text();
|
||||
} else {
|
||||
Distribyted.message.error('Error getting data from server. Response: ' + response.status);
|
||||
}
|
||||
})
|
||||
.then((t) => {
|
||||
return Handlebars.compile(t);
|
||||
})
|
||||
.catch(error => {
|
||||
Distribyted.message.error('Error getting servers template: ' + error.message);
|
||||
});
|
||||
|
||||
this._template = tTemplate;
|
||||
return tTemplate;
|
||||
},
|
||||
|
||||
_getRoutesJson: function () {
|
||||
return fetch('/api/servers')
|
||||
.then(function (response) {
|
||||
if (response.ok) {
|
||||
return response.json();
|
||||
} else {
|
||||
Distribyted.message.error('Error getting data from server. Response: ' + response.status)
|
||||
}
|
||||
})
|
||||
.catch(function (error) {
|
||||
Distribyted.message.error('Error getting status info: ' + error.message)
|
||||
});
|
||||
},
|
||||
|
||||
loadView: function () {
|
||||
this._getTemplate()
|
||||
.then(t =>
|
||||
this._getRoutesJson().then(routes => {
|
||||
document.getElementById('template_target').innerHTML = t(routes);
|
||||
})
|
||||
);
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue