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
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);
|
||||
})
|
||||
);
|
||||
}
|
||||
}
|
|
@ -1,10 +1,9 @@
|
|||
{{#.}}
|
||||
<div class="row">
|
||||
<div class="col-12">
|
||||
<!-- Recent Order Table -->
|
||||
<div class="card card-table-border-none">
|
||||
<div class="card-header justify-content-between">
|
||||
<h2>{{name}}</h2>
|
||||
<div class="card-header justify-content-between card-header-border-bottom">
|
||||
<h2>Route: {{name}}</h2>
|
||||
</div>
|
||||
<div class="card-body pt-0 pb-5">
|
||||
<table class="table card-table table-responsive table-responsive-large" style="width:100%">
|
||||
|
@ -13,7 +12,7 @@
|
|||
<th style="width: 30%">Name</th>
|
||||
<th style="width: 15%"><i class="mdi mdi-arrow-down"></i> / <i class="mdi mdi-arrow-up"></i>
|
||||
</th>
|
||||
<th style="width: 15%">Peers/Seeders</th>
|
||||
<th style="width: 15%" class="d-none d-lg-table-cell">Peers/Seeders</th>
|
||||
<th style="width: 35%" class="d-none d-lg-table-cell">Status</th>
|
||||
<th style="width: 5%" >Actions</th>
|
||||
</tr>
|
||||
|
@ -24,7 +23,7 @@
|
|||
<td>{{name}}</td>
|
||||
<td>{{ibytes downloadedBytes timePassed}} / {{ibytes
|
||||
uploadedBytes timePassed}}</td>
|
||||
<td>{{{torrent_info peers seeders pieceSize}}}</td>
|
||||
<td class="d-none d-lg-table-cell">{{{torrent_info peers seeders pieceSize}}}</td>
|
||||
<td class="d-none d-lg-table-cell">
|
||||
{{{torrent_status pieceChunks totalPieces}}}
|
||||
</td>
|
||||
|
|
45
assets/templates/servers.html
Normal file
45
assets/templates/servers.html
Normal file
|
@ -0,0 +1,45 @@
|
|||
{{#.}}
|
||||
|
||||
<div class="card card-default">
|
||||
<div class="card-header justify-content-between align-items-center card-header-border-bottom">
|
||||
<h2>{{name}}</h2>
|
||||
</div>
|
||||
<div class="bg-white border rounded">
|
||||
<div class="row no-gutters">
|
||||
<div class="col-lg-4 col-xl-3">
|
||||
<div class="profile-content-left pt-5 pb-3 px-3 px-xl-5">
|
||||
<div class="contact-info pt-4">
|
||||
<h5 class="text-dark mb-1">Server Info:</h5>
|
||||
<p class="text-dark font-weight-medium pt-4 mb-2">State</p>
|
||||
<p>{{state}}</p>
|
||||
<p class="text-dark font-weight-medium pt-4 mb-2">Updated At</p>
|
||||
<p>{{to_date updatedAt}}</p>
|
||||
<p class="text-dark font-weight-medium pt-4 mb-2">Seeds: {{seeds}}</p>
|
||||
<p class="text-dark font-weight-medium pt-4 mb-2">Peers: {{peers}}</p>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-lg-8 col-xl-9">
|
||||
<div class="profile-content-right py-5">
|
||||
<div class="tab-content px-3 px-xl-5">
|
||||
<div class="mt-5">
|
||||
<div class="form-group mb-4">
|
||||
<label for="magnetUri">Magnet URI</label>
|
||||
<input type="text" class="form-control" id="magnetUri" value="{{magnetUri}}">
|
||||
<span class="d-block mt-1">Magnet URI pointing to the actual folder content. If content
|
||||
changes, this URI will change too.</span>
|
||||
</div>
|
||||
|
||||
<div class="form-group mb-4">
|
||||
<label for="folder">Folder</label>
|
||||
<input type="folder" class="form-control" id="folder" value="{{folder}}">
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{{/.}}
|
Loading…
Add table
Add a link
Reference in a new issue