mirror of
https://github.com/lrnselfreliance/wrolpi.git
synced 2026-12-04 13:49:57 -05:00
Torrents over a fail-closed VPN (#1026)
Torrents reach the Internet only through a fail-closed VPN (WireGuard or OpenVPN, any provider), so peers never see a WROLPi's own address. - A network namespace (Pi/Debian) or the vpn container (Docker) with an nftables kill switch; NAT-PMP or fixed port forwarding. - qBittorrent inside it, sandboxed; torrents kept in config/torrents/. - Torrent download form, Torrents page, Share as torrent, nav warning, and VPN settings in both Controller UIs. - Help docs: Torrents, and The VPN for Torrents. QA'd on a Raspberry Pi with a real provider over WireGuard and OpenVPN. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
633b125dc6
commit
2c3300b8b0
80 changed files with 7516 additions and 45 deletions
|
|
@ -2969,3 +2969,63 @@ export async function importRepo(repo) {
|
|||
}
|
||||
await reposError(response, 'Failed to import the repo.');
|
||||
}
|
||||
|
||||
// --- Torrents (they reach the Internet only through the VPN) ---
|
||||
|
||||
const TORRENTS_API = `${API_URI}/torrents`;
|
||||
|
||||
async function torrentsRequest(response, fallbackMessage) {
|
||||
if (!response.ok) {
|
||||
throw new Error(await getErrorMessage(response, fallbackMessage));
|
||||
}
|
||||
return response.status === 204 ? null : response;
|
||||
}
|
||||
|
||||
export async function getTorrents() {
|
||||
const response = await torrentsRequest(await apiGet(`${TORRENTS_API}/`), 'Failed to get torrents');
|
||||
return await response.json();
|
||||
}
|
||||
|
||||
export async function uploadTorrent(file, destination) {
|
||||
const form = new FormData();
|
||||
form.append('torrent', file);
|
||||
if (destination) {
|
||||
form.append('destination', destination);
|
||||
}
|
||||
const response = await torrentsRequest(await fetch(`${TORRENTS_API}/upload`, {method: 'POST', body: form}),
|
||||
'Failed to add the .torrent file');
|
||||
return await response.json();
|
||||
}
|
||||
|
||||
export async function pauseTorrent(hash) {
|
||||
await torrentsRequest(await apiPost(`${TORRENTS_API}/${hash}/pause`), 'Failed to pause the torrent');
|
||||
}
|
||||
|
||||
export async function resumeTorrent(hash) {
|
||||
await torrentsRequest(await apiPost(`${TORRENTS_API}/${hash}/resume`), 'Failed to resume the torrent');
|
||||
}
|
||||
|
||||
export async function removeTorrent(hash, deleteFiles = false) {
|
||||
await torrentsRequest(await apiDelete(`${TORRENTS_API}/${hash}?delete_files=${deleteFiles ? 'true' : 'false'}`),
|
||||
'Failed to remove the torrent');
|
||||
}
|
||||
|
||||
export async function setTorrentShareLimits(hash, seedRatioLimit, seedTimeLimit) {
|
||||
await torrentsRequest(await apiPut(`${TORRENTS_API}/${hash}/limits`,
|
||||
{seed_ratio_limit: seedRatioLimit, seed_time_limit: seedTimeLimit}), 'Failed to save the limits');
|
||||
}
|
||||
|
||||
export async function setTorrentSpeedLimits(upload, download) {
|
||||
await torrentsRequest(await apiPut(`${TORRENTS_API}/limits`, {upload, download}),
|
||||
'Failed to save the speed limits');
|
||||
}
|
||||
|
||||
export function torrentFileUrl(hash) {
|
||||
return `${TORRENTS_API}/${hash}/torrent`;
|
||||
}
|
||||
|
||||
export async function shareTorrent(path, trackers, webSeeds, rememberTrackers = false) {
|
||||
const response = await torrentsRequest(await apiPost(`${TORRENTS_API}/share`,
|
||||
{path, trackers, web_seeds: webSeeds, remember_trackers: rememberTrackers}), 'Failed to share as a torrent');
|
||||
return (await response.json()).job_id;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue