102 lines
4.5 KiB
HTML
102 lines
4.5 KiB
HTML
{{ define "download" }}
|
|
<div class="container mt-4">
|
|
<div class="card">
|
|
<div class="card-header">
|
|
<h4 class="mb-0"><i class="bi bi-cloud-download me-2"></i>Add New Download</h4>
|
|
</div>
|
|
<div class="card-body">
|
|
<form id="downloadForm">
|
|
<div class="mb-3">
|
|
<label for="magnetURI" class="form-label">Magnet Link(s) or Torrent URL(s)</label>
|
|
<textarea class="form-control" id="magnetURI" rows="8" placeholder="Paste your magnet links or torrent URLs here, one per line..."></textarea>
|
|
</div>
|
|
|
|
<div class="mb-3">
|
|
<label for="category" class="form-label">Enter Category</label>
|
|
<input type="text" class="form-control" id="category" placeholder="Enter Category(e.g sonarr, radarr, radarr4k)">
|
|
</div>
|
|
|
|
<div class="mb-3">
|
|
<div class="form-check">
|
|
<input class="form-check-input" type="checkbox" id="isSymlink">
|
|
<label class="form-check-label" for="isSymlink">
|
|
Download real files instead of symlinks
|
|
</label>
|
|
</div>
|
|
</div>
|
|
|
|
<button type="submit" class="btn btn-primary" id="submitDownload">
|
|
<i class="bi bi-cloud-upload me-2"></i>Add to Download Queue
|
|
</button>
|
|
</form>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<script>
|
|
document.addEventListener('DOMContentLoaded', () => {
|
|
|
|
// Handle form submission
|
|
document.getElementById('downloadForm').addEventListener('submit', async (e) => {
|
|
e.preventDefault();
|
|
const submitBtn = document.getElementById('submitDownload');
|
|
const originalText = submitBtn.innerHTML;
|
|
|
|
submitBtn.disabled = true;
|
|
submitBtn.innerHTML = '<span class="spinner-border spinner-border-sm me-2"></span>Adding...';
|
|
|
|
try {
|
|
const urls = document.getElementById('magnetURI').value
|
|
.split('\n')
|
|
.map(url => url.trim())
|
|
.filter(url => url.length > 0);
|
|
|
|
if (urls.length === 0) {
|
|
alert('Please submit at least one torrent');
|
|
return;
|
|
}
|
|
if (urls.length >= 100) {
|
|
alert('Please submit less than 100 torrents at a time');
|
|
return;
|
|
}
|
|
|
|
|
|
const response = await fetch('/internal/add', {
|
|
method: 'POST',
|
|
headers: {
|
|
'Content-Type': 'application/json'
|
|
},
|
|
body: JSON.stringify({
|
|
urls: urls,
|
|
arr: document.getElementById('category').value,
|
|
notSymlink: document.getElementById('isSymlink').checked
|
|
})
|
|
});
|
|
|
|
const result = await response.json();
|
|
if (!response.ok) throw new Error(result.error || 'Unknown error');
|
|
if (result.errors && result.errors.length > 0) {
|
|
alert(`Added ${result.results.length} torrents with ${result.errors.length} errors:\n${result.errors.join('\n')}`);
|
|
} else {
|
|
alert(`Successfully added ${result.results.length} torrents!`);
|
|
}
|
|
|
|
document.getElementById('magnetURI').value = '';
|
|
} catch (error) {
|
|
alert(`Error adding downloads: ${error.message}`);
|
|
} finally {
|
|
submitBtn.disabled = false;
|
|
submitBtn.innerHTML = originalText;
|
|
}
|
|
});
|
|
|
|
// Read the URL parameters for a magnet link and add it to the download textarea if found
|
|
const urlParams = new URLSearchParams(window.location.search);
|
|
const magnetURI = urlParams.get('magnet');
|
|
if (magnetURI) {
|
|
document.getElementById('magnetURI').value = magnetURI;
|
|
history.replaceState({}, document.title, window.location.pathname);
|
|
}
|
|
});
|
|
</script>
|
|
{{ end }} |