Spaces:
Paused
Paused
Upload 29 files
Browse files- app.py +28 -5
- static/app.js +174 -28
- templates/index.html +15 -4
app.py
CHANGED
|
@@ -387,6 +387,19 @@ def selected_rclone_remote(config: dict | None = None) -> str:
|
|
| 387 |
return str(remotes[0]) if remotes else ""
|
| 388 |
|
| 389 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 390 |
def rclone_remote_label() -> str:
|
| 391 |
remote = selected_rclone_remote()
|
| 392 |
return remote or "rclone"
|
|
@@ -2286,7 +2299,13 @@ def start_pixeldrain_upload_background(torrent_hash: str, torrent_name: str, fil
|
|
| 2286 |
thread.start()
|
| 2287 |
|
| 2288 |
|
| 2289 |
-
def start_rclone_upload_background(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2290 |
def worker():
|
| 2291 |
upload_path = file_path
|
| 2292 |
cleanup_upload_path = False
|
|
@@ -2297,7 +2316,7 @@ def start_rclone_upload_background(torrent_hash: str, torrent_name: str, file_pa
|
|
| 2297 |
raise ValueError(str(config.get("error") or "rclone.conf tidak berisi remote aktif."))
|
| 2298 |
|
| 2299 |
config_path = Path(str(config["path"]))
|
| 2300 |
-
remote =
|
| 2301 |
remote_label = remote or "rclone"
|
| 2302 |
|
| 2303 |
if file_path.is_dir() and mode == "raw":
|
|
@@ -2786,7 +2805,11 @@ def upload_torrent_to_rclone(torrent_hash: str):
|
|
| 2786 |
if config.get("error") or not config.get("remotes"):
|
| 2787 |
return action_response(f"rclone belum siap: {config.get('error') or 'remote tidak ditemukan.'}", ok=False, status_code=400)
|
| 2788 |
|
| 2789 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2790 |
if is_aria2_task(torrent_hash):
|
| 2791 |
state = load_monitor_state()
|
| 2792 |
entry = state.get("aria2", {}).get(torrent_hash)
|
|
@@ -2808,7 +2831,7 @@ def upload_torrent_to_rclone(torrent_hash: str):
|
|
| 2808 |
entry["gofile_status"] = f"Sedang upload ke rclone remote {remote}..."
|
| 2809 |
entry["status_message"] = ""
|
| 2810 |
save_monitor_state(state)
|
| 2811 |
-
start_rclone_upload_background(torrent_hash, entry.get("name", file_path.name), file_path, mode="zip")
|
| 2812 |
return action_response("Upload Aria2 ke rclone dimulai.")
|
| 2813 |
|
| 2814 |
try:
|
|
@@ -2850,7 +2873,7 @@ def upload_torrent_to_rclone(torrent_hash: str):
|
|
| 2850 |
entry["status_message"] = ""
|
| 2851 |
save_monitor_state(state)
|
| 2852 |
|
| 2853 |
-
start_rclone_upload_background(torrent_hash, torrent.name, content_path, mode=mode)
|
| 2854 |
return action_response("Upload ke rclone dimulai." if mode == "zip" else "Upload raw folder ke rclone dimulai.")
|
| 2855 |
except qbittorrentapi.APIError as exc:
|
| 2856 |
return action_response(f"Gagal memulai upload rclone: {exc}", ok=False, status_code=502)
|
|
|
|
| 387 |
return str(remotes[0]) if remotes else ""
|
| 388 |
|
| 389 |
|
| 390 |
+
def requested_rclone_remote(config: dict, raw_remote: str) -> str:
|
| 391 |
+
remotes = [str(remote) for remote in list(config.get("remotes", []) or [])]
|
| 392 |
+
remote = raw_remote.strip().rstrip(":")
|
| 393 |
+
if not remote:
|
| 394 |
+
remote = selected_rclone_remote(config)
|
| 395 |
+
if not remote:
|
| 396 |
+
raise ValueError("Remote rclone belum dipilih.")
|
| 397 |
+
if remote not in remotes:
|
| 398 |
+
available = ", ".join(remotes) if remotes else "-"
|
| 399 |
+
raise ValueError(f"Remote rclone '{remote}' tidak ditemukan. Remote tersedia: {available}")
|
| 400 |
+
return remote
|
| 401 |
+
|
| 402 |
+
|
| 403 |
def rclone_remote_label() -> str:
|
| 404 |
remote = selected_rclone_remote()
|
| 405 |
return remote or "rclone"
|
|
|
|
| 2299 |
thread.start()
|
| 2300 |
|
| 2301 |
|
| 2302 |
+
def start_rclone_upload_background(
|
| 2303 |
+
torrent_hash: str,
|
| 2304 |
+
torrent_name: str,
|
| 2305 |
+
file_path: Path,
|
| 2306 |
+
mode: str = "zip",
|
| 2307 |
+
remote_name: str = "",
|
| 2308 |
+
) -> None:
|
| 2309 |
def worker():
|
| 2310 |
upload_path = file_path
|
| 2311 |
cleanup_upload_path = False
|
|
|
|
| 2316 |
raise ValueError(str(config.get("error") or "rclone.conf tidak berisi remote aktif."))
|
| 2317 |
|
| 2318 |
config_path = Path(str(config["path"]))
|
| 2319 |
+
remote = requested_rclone_remote(config, remote_name)
|
| 2320 |
remote_label = remote or "rclone"
|
| 2321 |
|
| 2322 |
if file_path.is_dir() and mode == "raw":
|
|
|
|
| 2805 |
if config.get("error") or not config.get("remotes"):
|
| 2806 |
return action_response(f"rclone belum siap: {config.get('error') or 'remote tidak ditemukan.'}", ok=False, status_code=400)
|
| 2807 |
|
| 2808 |
+
try:
|
| 2809 |
+
remote = requested_rclone_remote(config, request.args.get("remote", ""))
|
| 2810 |
+
except ValueError as exc:
|
| 2811 |
+
return action_response(str(exc), ok=False, status_code=400, rclone=rclone_config_summary(force_refresh=False))
|
| 2812 |
+
|
| 2813 |
if is_aria2_task(torrent_hash):
|
| 2814 |
state = load_monitor_state()
|
| 2815 |
entry = state.get("aria2", {}).get(torrent_hash)
|
|
|
|
| 2831 |
entry["gofile_status"] = f"Sedang upload ke rclone remote {remote}..."
|
| 2832 |
entry["status_message"] = ""
|
| 2833 |
save_monitor_state(state)
|
| 2834 |
+
start_rclone_upload_background(torrent_hash, entry.get("name", file_path.name), file_path, mode="zip", remote_name=remote)
|
| 2835 |
return action_response("Upload Aria2 ke rclone dimulai.")
|
| 2836 |
|
| 2837 |
try:
|
|
|
|
| 2873 |
entry["status_message"] = ""
|
| 2874 |
save_monitor_state(state)
|
| 2875 |
|
| 2876 |
+
start_rclone_upload_background(torrent_hash, torrent.name, content_path, mode=mode, remote_name=remote)
|
| 2877 |
return action_response("Upload ke rclone dimulai." if mode == "zip" else "Upload raw folder ke rclone dimulai.")
|
| 2878 |
except qbittorrentapi.APIError as exc:
|
| 2879 |
return action_response(f"Gagal memulai upload rclone: {exc}", ok=False, status_code=502)
|
static/app.js
CHANGED
|
@@ -71,8 +71,16 @@
|
|
| 71 |
folderUploadConfirm: document.getElementById("folder-upload-confirm"),
|
| 72 |
rawUploadDescription: document.getElementById("raw-upload-description"),
|
| 73 |
rcloneConfigModal: document.getElementById("rclone-config-modal"),
|
|
|
|
| 74 |
rcloneConfigText: document.getElementById("rclone-config-text"),
|
|
|
|
| 75 |
rcloneConfigUrl: document.getElementById("rclone-config-url"),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 76 |
rcloneConfigClose: document.getElementById("rclone-config-close"),
|
| 77 |
rcloneConfigCancel: document.getElementById("rclone-config-cancel"),
|
| 78 |
rcloneConfigSave: document.getElementById("rclone-config-save"),
|
|
@@ -82,6 +90,8 @@
|
|
| 82 |
let pendingDelete = null;
|
| 83 |
let pendingFolderUpload = null;
|
| 84 |
let pendingRcloneUpload = null;
|
|
|
|
|
|
|
| 85 |
let pendingTorrentFileSelection = null;
|
| 86 |
let torrentFileSelectionPollTimer = null;
|
| 87 |
let selectedFolderUploadMode = "zip";
|
|
@@ -1037,10 +1047,10 @@
|
|
| 1037 |
hideModal(elements.deleteModal);
|
| 1038 |
}
|
| 1039 |
|
| 1040 |
-
function openFolderUploadModal(action, hash, provider, rawEnabled) {
|
| 1041 |
-
pendingFolderUpload = { action, hash, provider, rawEnabled };
|
| 1042 |
-
selectedFolderUploadMode = "zip";
|
| 1043 |
-
elements.folderUploadText.textContent = `Torrent ini berisi folder. Pilih cara upload ke ${provider}.`;
|
| 1044 |
elements.rawUploadDescription.textContent = rawEnabled
|
| 1045 |
? "Upload file satu per satu tanpa zip."
|
| 1046 |
: "Mode raw tidak tersedia untuk pilihan ini.";
|
|
@@ -1068,21 +1078,126 @@
|
|
| 1068 |
hideModal(elements.folderUploadModal);
|
| 1069 |
}
|
| 1070 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1071 |
function openRcloneConfigModal(uploadRequest = null, errorMessage = "") {
|
| 1072 |
pendingRcloneUpload = uploadRequest;
|
| 1073 |
-
|
| 1074 |
-
|
| 1075 |
-
: "Masukkan raw URL rclone.conf untuk mengaktifkan upload rclone.";
|
| 1076 |
elements.rcloneConfigUrl.value = "";
|
| 1077 |
showModal(elements.rcloneConfigModal);
|
|
|
|
| 1078 |
}
|
| 1079 |
|
| 1080 |
function closeRcloneConfigModal() {
|
| 1081 |
pendingRcloneUpload = null;
|
|
|
|
| 1082 |
hideModal(elements.rcloneConfigModal);
|
| 1083 |
}
|
| 1084 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1085 |
async function saveRcloneConfigUrl() {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1086 |
const configUrl = String(elements.rcloneConfigUrl.value || "").trim();
|
| 1087 |
if (!configUrl) {
|
| 1088 |
showToast("Raw URL rclone.conf wajib diisi.", "error");
|
|
@@ -1107,16 +1222,15 @@
|
|
| 1107 |
|
| 1108 |
showToast(payload.message || "rclone.conf valid.");
|
| 1109 |
const uploadRequest = pendingRcloneUpload;
|
| 1110 |
-
closeRcloneConfigModal();
|
| 1111 |
await refreshTorrents();
|
| 1112 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1113 |
return;
|
| 1114 |
}
|
| 1115 |
-
|
| 1116 |
-
openFolderUploadModal(uploadRequest.action, uploadRequest.hash, "rclone", true);
|
| 1117 |
-
return;
|
| 1118 |
-
}
|
| 1119 |
-
await triggerTorrentAction(uploadRequest.action, uploadRequest.hash);
|
| 1120 |
} finally {
|
| 1121 |
elements.rcloneConfigSave.disabled = false;
|
| 1122 |
}
|
|
@@ -1389,9 +1503,16 @@
|
|
| 1389 |
return false;
|
| 1390 |
}
|
| 1391 |
|
| 1392 |
-
async function triggerTorrentAction(action, hash, mode = null) {
|
| 1393 |
-
const method = action === "delete" ? "DELETE" : "POST";
|
| 1394 |
-
const
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1395 |
const target = action === "delete"
|
| 1396 |
? `/api/torrents/${hash}?with_files=${elements.deleteWithFiles.checked}`
|
| 1397 |
: action === "upload-gofile"
|
|
@@ -1428,7 +1549,14 @@
|
|
| 1428 |
clearOptimisticTorrentState(hash);
|
| 1429 |
await refreshTorrents();
|
| 1430 |
}
|
| 1431 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1432 |
openRcloneConfigModal({ action, hash, isFolder: false }, payload.message || "");
|
| 1433 |
return;
|
| 1434 |
}
|
|
@@ -1580,22 +1708,23 @@
|
|
| 1580 |
return;
|
| 1581 |
}
|
| 1582 |
|
| 1583 |
-
if (action === "upload-rclone"
|
| 1584 |
openRcloneConfigModal(
|
| 1585 |
{
|
| 1586 |
action,
|
| 1587 |
hash: button.dataset.hash,
|
| 1588 |
isFolder: button.dataset.isFolder === "true",
|
|
|
|
| 1589 |
},
|
| 1590 |
-
button.dataset.rcloneError || "",
|
| 1591 |
);
|
| 1592 |
return;
|
| 1593 |
}
|
| 1594 |
|
| 1595 |
-
if ((action === "upload-gofile" || action === "upload-pixeldrain"
|
| 1596 |
openFolderUploadModal(
|
| 1597 |
-
action,
|
| 1598 |
-
button.dataset.hash,
|
| 1599 |
button.dataset.provider || "provider ini",
|
| 1600 |
button.dataset.rawEnabled === "true",
|
| 1601 |
);
|
|
@@ -1717,11 +1846,16 @@
|
|
| 1717 |
if (!pendingFolderUpload) {
|
| 1718 |
return;
|
| 1719 |
}
|
| 1720 |
-
elements.folderUploadConfirm.disabled = true;
|
| 1721 |
-
try {
|
| 1722 |
-
await triggerTorrentAction(
|
| 1723 |
-
|
| 1724 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1725 |
elements.folderUploadConfirm.disabled = false;
|
| 1726 |
}
|
| 1727 |
});
|
|
@@ -1729,6 +1863,18 @@
|
|
| 1729 |
elements.rcloneConfigClose?.addEventListener("click", closeRcloneConfigModal);
|
| 1730 |
elements.rcloneConfigCancel?.addEventListener("click", closeRcloneConfigModal);
|
| 1731 |
elements.rcloneConfigSave?.addEventListener("click", saveRcloneConfigUrl);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1732 |
elements.rcloneConfigUrl?.addEventListener("keydown", (event) => {
|
| 1733 |
if (event.key === "Enter") {
|
| 1734 |
event.preventDefault();
|
|
|
|
| 71 |
folderUploadConfirm: document.getElementById("folder-upload-confirm"),
|
| 72 |
rawUploadDescription: document.getElementById("raw-upload-description"),
|
| 73 |
rcloneConfigModal: document.getElementById("rclone-config-modal"),
|
| 74 |
+
rcloneConfigTitle: document.getElementById("rclone-config-title"),
|
| 75 |
rcloneConfigText: document.getElementById("rclone-config-text"),
|
| 76 |
+
rcloneConfigUrlSection: document.getElementById("rclone-config-url-section"),
|
| 77 |
rcloneConfigUrl: document.getElementById("rclone-config-url"),
|
| 78 |
+
rcloneConfigHelp: document.getElementById("rclone-config-help"),
|
| 79 |
+
rcloneConfigRefresh: document.getElementById("rclone-config-refresh"),
|
| 80 |
+
rcloneRemoteSection: document.getElementById("rclone-remote-section"),
|
| 81 |
+
rcloneRemoteLoading: document.getElementById("rclone-remote-loading"),
|
| 82 |
+
rcloneRemoteList: document.getElementById("rclone-remote-list"),
|
| 83 |
+
rcloneRemoteEmpty: document.getElementById("rclone-remote-empty"),
|
| 84 |
rcloneConfigClose: document.getElementById("rclone-config-close"),
|
| 85 |
rcloneConfigCancel: document.getElementById("rclone-config-cancel"),
|
| 86 |
rcloneConfigSave: document.getElementById("rclone-config-save"),
|
|
|
|
| 90 |
let pendingDelete = null;
|
| 91 |
let pendingFolderUpload = null;
|
| 92 |
let pendingRcloneUpload = null;
|
| 93 |
+
let rcloneModalMode = "config";
|
| 94 |
+
let selectedRcloneRemote = "";
|
| 95 |
let pendingTorrentFileSelection = null;
|
| 96 |
let torrentFileSelectionPollTimer = null;
|
| 97 |
let selectedFolderUploadMode = "zip";
|
|
|
|
| 1047 |
hideModal(elements.deleteModal);
|
| 1048 |
}
|
| 1049 |
|
| 1050 |
+
function openFolderUploadModal(action, hash, provider, rawEnabled, remote = "") {
|
| 1051 |
+
pendingFolderUpload = { action, hash, provider, rawEnabled, remote };
|
| 1052 |
+
selectedFolderUploadMode = "zip";
|
| 1053 |
+
elements.folderUploadText.textContent = `Torrent ini berisi folder. Pilih cara upload ke ${provider}.`;
|
| 1054 |
elements.rawUploadDescription.textContent = rawEnabled
|
| 1055 |
? "Upload file satu per satu tanpa zip."
|
| 1056 |
: "Mode raw tidak tersedia untuk pilihan ini.";
|
|
|
|
| 1078 |
hideModal(elements.folderUploadModal);
|
| 1079 |
}
|
| 1080 |
|
| 1081 |
+
function setRcloneModalMode(mode) {
|
| 1082 |
+
rcloneModalMode = mode;
|
| 1083 |
+
const isRemoteMode = mode === "remote";
|
| 1084 |
+
elements.rcloneConfigTitle.textContent = isRemoteMode ? "Pilih remote" : "Set raw URL";
|
| 1085 |
+
elements.rcloneConfigUrlSection.classList.toggle("hidden", isRemoteMode);
|
| 1086 |
+
elements.rcloneConfigHelp.textContent = isRemoteMode
|
| 1087 |
+
? "Remote diambil langsung dari rclone.conf yang aktif."
|
| 1088 |
+
: "URL akan divalidasi dengan `rclone listremotes` sebelum upload dimulai.";
|
| 1089 |
+
elements.rcloneRemoteSection.classList.toggle("hidden", !isRemoteMode);
|
| 1090 |
+
elements.rcloneConfigSave.textContent = isRemoteMode ? "Upload ke remote" : "Simpan & lanjutkan";
|
| 1091 |
+
}
|
| 1092 |
+
|
| 1093 |
+
function renderRcloneRemoteList(remotes, selectedRemote = "") {
|
| 1094 |
+
const remoteNames = Array.isArray(remotes) ? remotes.filter(Boolean) : [];
|
| 1095 |
+
selectedRcloneRemote = selectedRemote || remoteNames[0] || "";
|
| 1096 |
+
|
| 1097 |
+
elements.rcloneRemoteLoading.classList.add("hidden");
|
| 1098 |
+
elements.rcloneRemoteList.classList.toggle("hidden", remoteNames.length === 0);
|
| 1099 |
+
elements.rcloneRemoteEmpty.classList.toggle("hidden", remoteNames.length > 0);
|
| 1100 |
+
|
| 1101 |
+
if (!remoteNames.length) {
|
| 1102 |
+
elements.rcloneRemoteList.innerHTML = "";
|
| 1103 |
+
elements.rcloneRemoteEmpty.textContent = "Tidak ada remote aktif di rclone.conf.";
|
| 1104 |
+
return;
|
| 1105 |
+
}
|
| 1106 |
+
|
| 1107 |
+
elements.rcloneRemoteList.innerHTML = remoteNames.map((remote) => {
|
| 1108 |
+
const active = remote === selectedRcloneRemote;
|
| 1109 |
+
const tone = active
|
| 1110 |
+
? "border-lime/30 bg-lime/10 text-lime"
|
| 1111 |
+
: "border-white/10 bg-white/[0.03] text-stone-200 hover:bg-white/[0.06]";
|
| 1112 |
+
return `
|
| 1113 |
+
<button type="button" data-rclone-remote="${escapeHtml(remote)}" class="rclone-remote-choice flex w-full items-center justify-between rounded-2xl border px-4 py-3 text-left text-sm transition ${tone}">
|
| 1114 |
+
<span class="min-w-0 truncate font-medium">${escapeHtml(remote)}</span>
|
| 1115 |
+
<i class="fa-solid ${active ? "fa-circle-check" : "fa-circle"} ml-3 text-xs"></i>
|
| 1116 |
+
</button>
|
| 1117 |
+
`;
|
| 1118 |
+
}).join("");
|
| 1119 |
+
}
|
| 1120 |
+
|
| 1121 |
+
async function loadRcloneRemoteOptions(errorMessage = "") {
|
| 1122 |
+
setRcloneModalMode("remote");
|
| 1123 |
+
selectedRcloneRemote = "";
|
| 1124 |
+
elements.rcloneConfigText.textContent = "Memuat daftar remote dari rclone.conf...";
|
| 1125 |
+
elements.rcloneRemoteLoading.classList.remove("hidden");
|
| 1126 |
+
elements.rcloneRemoteList.classList.add("hidden");
|
| 1127 |
+
elements.rcloneRemoteEmpty.classList.add("hidden");
|
| 1128 |
+
|
| 1129 |
+
try {
|
| 1130 |
+
const response = await fetch("/api/rclone/config", {
|
| 1131 |
+
method: "GET",
|
| 1132 |
+
headers: { Accept: "application/json" },
|
| 1133 |
+
});
|
| 1134 |
+
const payload = await response.json();
|
| 1135 |
+
const summary = payload.rclone || {};
|
| 1136 |
+
const remotes = Array.isArray(summary.remotes) ? summary.remotes : [];
|
| 1137 |
+
if (!response.ok || !payload.success || !summary.available || !remotes.length) {
|
| 1138 |
+
setRcloneModalMode("config");
|
| 1139 |
+
elements.rcloneConfigText.textContent = errorMessage
|
| 1140 |
+
? `rclone.conf belum siap: ${errorMessage}`
|
| 1141 |
+
: `rclone.conf belum siap: ${summary.error || payload.message || "remote tidak ditemukan."}`;
|
| 1142 |
+
return;
|
| 1143 |
+
}
|
| 1144 |
+
|
| 1145 |
+
elements.rcloneConfigText.textContent = "Pilih remote tujuan upload dari rclone.conf.";
|
| 1146 |
+
renderRcloneRemoteList(remotes, summary.selected_remote || remotes[0]);
|
| 1147 |
+
} catch (error) {
|
| 1148 |
+
setRcloneModalMode("config");
|
| 1149 |
+
elements.rcloneConfigText.textContent = errorMessage
|
| 1150 |
+
? `rclone.conf belum siap: ${errorMessage}`
|
| 1151 |
+
: "Gagal membaca daftar remote rclone.";
|
| 1152 |
+
}
|
| 1153 |
+
}
|
| 1154 |
+
|
| 1155 |
function openRcloneConfigModal(uploadRequest = null, errorMessage = "") {
|
| 1156 |
pendingRcloneUpload = uploadRequest;
|
| 1157 |
+
selectedRcloneRemote = "";
|
| 1158 |
+
setRcloneModalMode("remote");
|
|
|
|
| 1159 |
elements.rcloneConfigUrl.value = "";
|
| 1160 |
showModal(elements.rcloneConfigModal);
|
| 1161 |
+
loadRcloneRemoteOptions(errorMessage);
|
| 1162 |
}
|
| 1163 |
|
| 1164 |
function closeRcloneConfigModal() {
|
| 1165 |
pendingRcloneUpload = null;
|
| 1166 |
+
selectedRcloneRemote = "";
|
| 1167 |
hideModal(elements.rcloneConfigModal);
|
| 1168 |
}
|
| 1169 |
|
| 1170 |
+
async function confirmRcloneRemoteSelection() {
|
| 1171 |
+
const remote = String(selectedRcloneRemote || "").trim();
|
| 1172 |
+
if (!remote) {
|
| 1173 |
+
showToast("Pilih remote rclone dulu.", "error");
|
| 1174 |
+
return;
|
| 1175 |
+
}
|
| 1176 |
+
|
| 1177 |
+
const uploadRequest = pendingRcloneUpload;
|
| 1178 |
+
closeRcloneConfigModal();
|
| 1179 |
+
await refreshTorrents();
|
| 1180 |
+
if (!uploadRequest) {
|
| 1181 |
+
return;
|
| 1182 |
+
}
|
| 1183 |
+
if (uploadRequest.isFolder) {
|
| 1184 |
+
openFolderUploadModal(uploadRequest.action, uploadRequest.hash, `rclone (${remote})`, uploadRequest.rawEnabled, remote);
|
| 1185 |
+
return;
|
| 1186 |
+
}
|
| 1187 |
+
await triggerTorrentAction(uploadRequest.action, uploadRequest.hash, null, remote);
|
| 1188 |
+
}
|
| 1189 |
+
|
| 1190 |
async function saveRcloneConfigUrl() {
|
| 1191 |
+
if (rcloneModalMode === "remote") {
|
| 1192 |
+
elements.rcloneConfigSave.disabled = true;
|
| 1193 |
+
try {
|
| 1194 |
+
await confirmRcloneRemoteSelection();
|
| 1195 |
+
} finally {
|
| 1196 |
+
elements.rcloneConfigSave.disabled = false;
|
| 1197 |
+
}
|
| 1198 |
+
return;
|
| 1199 |
+
}
|
| 1200 |
+
|
| 1201 |
const configUrl = String(elements.rcloneConfigUrl.value || "").trim();
|
| 1202 |
if (!configUrl) {
|
| 1203 |
showToast("Raw URL rclone.conf wajib diisi.", "error");
|
|
|
|
| 1222 |
|
| 1223 |
showToast(payload.message || "rclone.conf valid.");
|
| 1224 |
const uploadRequest = pendingRcloneUpload;
|
|
|
|
| 1225 |
await refreshTorrents();
|
| 1226 |
+
const remotes = Array.isArray(payload.rclone?.remotes) ? payload.rclone.remotes : [];
|
| 1227 |
+
if (uploadRequest && remotes.length) {
|
| 1228 |
+
setRcloneModalMode("remote");
|
| 1229 |
+
elements.rcloneConfigText.textContent = "Pilih remote tujuan upload dari rclone.conf.";
|
| 1230 |
+
renderRcloneRemoteList(remotes, payload.rclone?.selected_remote || remotes[0]);
|
| 1231 |
return;
|
| 1232 |
}
|
| 1233 |
+
closeRcloneConfigModal();
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1234 |
} finally {
|
| 1235 |
elements.rcloneConfigSave.disabled = false;
|
| 1236 |
}
|
|
|
|
| 1503 |
return false;
|
| 1504 |
}
|
| 1505 |
|
| 1506 |
+
async function triggerTorrentAction(action, hash, mode = null, remote = null) {
|
| 1507 |
+
const method = action === "delete" ? "DELETE" : "POST";
|
| 1508 |
+
const params = new URLSearchParams();
|
| 1509 |
+
if (mode) {
|
| 1510 |
+
params.set("mode", mode);
|
| 1511 |
+
}
|
| 1512 |
+
if (action === "upload-rclone" && remote) {
|
| 1513 |
+
params.set("remote", remote);
|
| 1514 |
+
}
|
| 1515 |
+
const query = params.toString() ? `?${params.toString()}` : "";
|
| 1516 |
const target = action === "delete"
|
| 1517 |
? `/api/torrents/${hash}?with_files=${elements.deleteWithFiles.checked}`
|
| 1518 |
: action === "upload-gofile"
|
|
|
|
| 1549 |
clearOptimisticTorrentState(hash);
|
| 1550 |
await refreshTorrents();
|
| 1551 |
}
|
| 1552 |
+
const rcloneMessage = String(payload.message || "").toLowerCase();
|
| 1553 |
+
const shouldPickRcloneRemote = action === "upload-rclone" && (
|
| 1554 |
+
payload.rclone ||
|
| 1555 |
+
rcloneMessage.includes("rclone belum siap") ||
|
| 1556 |
+
rcloneMessage.includes("rclone.conf") ||
|
| 1557 |
+
rcloneMessage.includes("remote rclone")
|
| 1558 |
+
);
|
| 1559 |
+
if (shouldPickRcloneRemote) {
|
| 1560 |
openRcloneConfigModal({ action, hash, isFolder: false }, payload.message || "");
|
| 1561 |
return;
|
| 1562 |
}
|
|
|
|
| 1708 |
return;
|
| 1709 |
}
|
| 1710 |
|
| 1711 |
+
if (action === "upload-rclone") {
|
| 1712 |
openRcloneConfigModal(
|
| 1713 |
{
|
| 1714 |
action,
|
| 1715 |
hash: button.dataset.hash,
|
| 1716 |
isFolder: button.dataset.isFolder === "true",
|
| 1717 |
+
rawEnabled: button.dataset.rawEnabled === "true",
|
| 1718 |
},
|
| 1719 |
+
button.dataset.rcloneReady === "true" ? "" : button.dataset.rcloneError || "",
|
| 1720 |
);
|
| 1721 |
return;
|
| 1722 |
}
|
| 1723 |
|
| 1724 |
+
if ((action === "upload-gofile" || action === "upload-pixeldrain") && button.dataset.isFolder === "true") {
|
| 1725 |
openFolderUploadModal(
|
| 1726 |
+
action,
|
| 1727 |
+
button.dataset.hash,
|
| 1728 |
button.dataset.provider || "provider ini",
|
| 1729 |
button.dataset.rawEnabled === "true",
|
| 1730 |
);
|
|
|
|
| 1846 |
if (!pendingFolderUpload) {
|
| 1847 |
return;
|
| 1848 |
}
|
| 1849 |
+
elements.folderUploadConfirm.disabled = true;
|
| 1850 |
+
try {
|
| 1851 |
+
await triggerTorrentAction(
|
| 1852 |
+
pendingFolderUpload.action,
|
| 1853 |
+
pendingFolderUpload.hash,
|
| 1854 |
+
selectedFolderUploadMode,
|
| 1855 |
+
pendingFolderUpload.remote || null,
|
| 1856 |
+
);
|
| 1857 |
+
closeFolderUploadModal();
|
| 1858 |
+
} finally {
|
| 1859 |
elements.folderUploadConfirm.disabled = false;
|
| 1860 |
}
|
| 1861 |
});
|
|
|
|
| 1863 |
elements.rcloneConfigClose?.addEventListener("click", closeRcloneConfigModal);
|
| 1864 |
elements.rcloneConfigCancel?.addEventListener("click", closeRcloneConfigModal);
|
| 1865 |
elements.rcloneConfigSave?.addEventListener("click", saveRcloneConfigUrl);
|
| 1866 |
+
elements.rcloneConfigRefresh?.addEventListener("click", () => {
|
| 1867 |
+
loadRcloneRemoteOptions();
|
| 1868 |
+
});
|
| 1869 |
+
elements.rcloneRemoteList?.addEventListener("click", (event) => {
|
| 1870 |
+
const button = event.target.closest("[data-rclone-remote]");
|
| 1871 |
+
if (!button) {
|
| 1872 |
+
return;
|
| 1873 |
+
}
|
| 1874 |
+
selectedRcloneRemote = button.dataset.rcloneRemote || "";
|
| 1875 |
+
const remotes = Array.from(elements.rcloneRemoteList.querySelectorAll("[data-rclone-remote]")).map((item) => item.dataset.rcloneRemote || "");
|
| 1876 |
+
renderRcloneRemoteList(remotes, selectedRcloneRemote);
|
| 1877 |
+
});
|
| 1878 |
elements.rcloneConfigUrl?.addEventListener("keydown", (event) => {
|
| 1879 |
if (event.key === "Enter") {
|
| 1880 |
event.preventDefault();
|
templates/index.html
CHANGED
|
@@ -444,7 +444,7 @@
|
|
| 444 |
<div class="flex items-start justify-between border-b border-white/5 px-5 py-5">
|
| 445 |
<div>
|
| 446 |
<p class="text-[11px] uppercase tracking-[0.25em] text-lime/80">rclone Config</p>
|
| 447 |
-
<h3 class="font-display mt-2 text-xl font-semibold text-white">
|
| 448 |
</div>
|
| 449 |
<button id="rclone-config-close" type="button" class="rounded-2xl border border-white/10 px-3 py-2 text-sm text-stone-400 transition hover:bg-white/10 hover:text-white">
|
| 450 |
<i class="fa-solid fa-xmark"></i>
|
|
@@ -452,14 +452,25 @@
|
|
| 452 |
</div>
|
| 453 |
<div class="p-5">
|
| 454 |
<p id="rclone-config-text" class="text-sm text-stone-300"></p>
|
| 455 |
-
<
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 456 |
<span class="mb-2 block text-sm text-stone-300">Raw rclone.conf URL</span>
|
| 457 |
<input id="rclone-config-url" type="url" placeholder="https://gist.githubusercontent.com/.../raw/rclone.conf" class="w-full rounded-2xl border border-white/10 bg-black/30 px-4 py-3 font-mono text-xs text-white outline-none transition placeholder:text-stone-500 focus:border-lime/40" />
|
| 458 |
</label>
|
| 459 |
-
<p class="mt-3 text-xs text-stone-500">URL akan divalidasi dengan `rclone listremotes` sebelum upload dimulai.</p>
|
| 460 |
<div class="mt-6 flex flex-wrap justify-end gap-3">
|
| 461 |
<button id="rclone-config-cancel" type="button" class="rounded-2xl border border-white/10 bg-white/[0.04] px-4 py-3 text-sm font-medium text-white transition hover:bg-white/[0.08]">Batal</button>
|
| 462 |
-
<button id="rclone-config-save" type="button" class="rounded-2xl border border-lime/30 bg-lime/10 px-4 py-3 text-sm font-medium text-lime transition hover:bg-lime/15">
|
| 463 |
</div>
|
| 464 |
</div>
|
| 465 |
</div>
|
|
|
|
| 444 |
<div class="flex items-start justify-between border-b border-white/5 px-5 py-5">
|
| 445 |
<div>
|
| 446 |
<p class="text-[11px] uppercase tracking-[0.25em] text-lime/80">rclone Config</p>
|
| 447 |
+
<h3 id="rclone-config-title" class="font-display mt-2 text-xl font-semibold text-white">Pilih remote</h3>
|
| 448 |
</div>
|
| 449 |
<button id="rclone-config-close" type="button" class="rounded-2xl border border-white/10 px-3 py-2 text-sm text-stone-400 transition hover:bg-white/10 hover:text-white">
|
| 450 |
<i class="fa-solid fa-xmark"></i>
|
|
|
|
| 452 |
</div>
|
| 453 |
<div class="p-5">
|
| 454 |
<p id="rclone-config-text" class="text-sm text-stone-300"></p>
|
| 455 |
+
<div id="rclone-remote-section" class="mt-5 hidden">
|
| 456 |
+
<div class="mb-3 flex items-center justify-between gap-3">
|
| 457 |
+
<span class="text-sm text-stone-300">Remote tersedia</span>
|
| 458 |
+
<button id="rclone-config-refresh" type="button" class="rounded-xl border border-white/10 bg-white/[0.04] px-3 py-2 text-xs font-medium text-stone-200 transition hover:bg-white/[0.08]">
|
| 459 |
+
<i class="fa-solid fa-rotate mr-2 text-[11px]"></i>Refresh
|
| 460 |
+
</button>
|
| 461 |
+
</div>
|
| 462 |
+
<div id="rclone-remote-loading" class="rounded-2xl border border-white/10 bg-black/20 px-4 py-4 text-sm text-stone-300">Memuat remote rclone...</div>
|
| 463 |
+
<div id="rclone-remote-list" class="hidden max-h-[34vh] space-y-2 overflow-y-auto pr-1"></div>
|
| 464 |
+
<p id="rclone-remote-empty" class="hidden rounded-2xl border border-amber/20 bg-amber/10 px-4 py-3 text-sm text-amber-100"></p>
|
| 465 |
+
</div>
|
| 466 |
+
<label id="rclone-config-url-section" class="mt-5 block">
|
| 467 |
<span class="mb-2 block text-sm text-stone-300">Raw rclone.conf URL</span>
|
| 468 |
<input id="rclone-config-url" type="url" placeholder="https://gist.githubusercontent.com/.../raw/rclone.conf" class="w-full rounded-2xl border border-white/10 bg-black/30 px-4 py-3 font-mono text-xs text-white outline-none transition placeholder:text-stone-500 focus:border-lime/40" />
|
| 469 |
</label>
|
| 470 |
+
<p id="rclone-config-help" class="mt-3 text-xs text-stone-500">URL akan divalidasi dengan `rclone listremotes` sebelum upload dimulai.</p>
|
| 471 |
<div class="mt-6 flex flex-wrap justify-end gap-3">
|
| 472 |
<button id="rclone-config-cancel" type="button" class="rounded-2xl border border-white/10 bg-white/[0.04] px-4 py-3 text-sm font-medium text-white transition hover:bg-white/[0.08]">Batal</button>
|
| 473 |
+
<button id="rclone-config-save" type="button" class="rounded-2xl border border-lime/30 bg-lime/10 px-4 py-3 text-sm font-medium text-lime transition hover:bg-lime/15">Lanjutkan</button>
|
| 474 |
</div>
|
| 475 |
</div>
|
| 476 |
</div>
|