/
server_client.js
38 lines (36 loc) · 1020 Bytes
/
server_client.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
//this is the script that interfaces the browser to the backend server
Cors = [
function(apiurl){
return `cors_proxy.php?url=${encodeURIComponent(apiurl)}`;
}
];
function get_torrent(link){
htm = render_top_menu(active_type);
document.body.innerHTML = htm+`<h2>Downloading torrent</h2>`;
fetch(`?add_torrent=${encodeURIComponent(link)}`)
.then(response => {
if (response) return response.json()
throw new Error('Network response was not ok.')
})
.then(data => {
document.title = AppName+": "+data.name;
document.body.innerHTML += data.body;
if(!data.done){
render_update = setTimeout(render, 10000)
}
});
}
function render_active_list(){
var torrents = "";
htm = render_top_menu(active_type);
document.body.innerHTML = htm+`<h2>Active Torrents</h2>
<div></div>`;
fetch(`?list_torrents`)
.then(response => {
if (response) return response.text()
throw new Error('Network response was not ok.')
})
.then(data => {
document.body.innerHTML += data;
});
}