nexus33rd commited on
Commit
0f7abfd
·
verified ·
1 Parent(s): 0e7dc9f

Upload 18 files

Browse files
Files changed (4) hide show
  1. Dockerfile +1 -1
  2. README.md +1 -0
  3. app.py +210 -15
  4. templates/index.html +117 -6
Dockerfile CHANGED
@@ -8,7 +8,7 @@ ENV PYTHONUNBUFFERED=1 \
8
  PORT=5000
9
 
10
  RUN apt-get update \
11
- && apt-get install -y --no-install-recommends qbittorrent-nox ca-certificates bash tini curl \
12
  && rm -rf /var/lib/apt/lists/*
13
 
14
  RUN useradd -m -u 1000 qbittorrent
 
8
  PORT=5000
9
 
10
  RUN apt-get update \
11
+ && apt-get install -y --no-install-recommends qbittorrent-nox ca-certificates bash tini curl p7zip-full \
12
  && rm -rf /var/lib/apt/lists/*
13
 
14
  RUN useradd -m -u 1000 qbittorrent
README.md CHANGED
@@ -19,6 +19,7 @@ Fitur utama:
19
  - pause, resume, delete
20
  - auto cancel untuk torrent stuck
21
  - upload file atau folder hasil torrent ke GoFile atau PixelDrain
 
22
  - panel ringkasan server dan speedtest
23
 
24
  ## Jalankan Dengan Docker
 
19
  - pause, resume, delete
20
  - auto cancel untuk torrent stuck
21
  - upload file atau folder hasil torrent ke GoFile atau PixelDrain
22
+ mode folder: ZIP dengan 7-Zip atau raw files melalui modal pilihan
23
  - panel ringkasan server dan speedtest
24
 
25
  ## Jalankan Dengan Docker
app.py CHANGED
@@ -8,7 +8,6 @@ import socket
8
  import subprocess
9
  import threading
10
  import time
11
- import zipfile
12
  from pathlib import Path
13
  from urllib.parse import quote, urlparse
14
 
@@ -75,6 +74,11 @@ def safe_filename(value: str) -> str:
75
  return sanitized or "archive"
76
 
77
 
 
 
 
 
 
78
  def parse_size_token(token: str) -> int | None:
79
  cleaned = token.strip()
80
  if not cleaned or cleaned in {"-", "--", "--:--:--"}:
@@ -398,6 +402,7 @@ def serialize_torrent(torrent, state_entry: dict | None = None) -> dict:
398
  state_entry = state_entry or {}
399
  status_message = state_entry.get("status_message", "")
400
  content_path = Path(getattr(torrent, "content_path", "") or "")
 
401
  gofile_uploading = bool(state_entry.get("gofile_uploading"))
402
  upload_provider = state_entry.get("gofile_provider", "GoFile")
403
  gofile_progress = int(state_entry.get("gofile_progress", 0) or 0)
@@ -455,6 +460,9 @@ def serialize_torrent(torrent, state_entry: dict | None = None) -> dict:
455
  "can_copy_link": bool(state_entry.get("gofile_link")),
456
  "can_cancel_gofile_upload": gofile_uploading,
457
  "can_pixeldrain_upload": can_gofile_upload and bool(PIXELDRAIN_API_KEY),
 
 
 
458
  }
459
 
460
 
@@ -475,26 +483,179 @@ def prepare_upload_source(source_path: Path, torrent_hash: str, provider_name: s
475
 
476
  update_torrent_entry(
477
  torrent_hash,
478
- gofile_status=f"Menyiapkan arsip folder untuk {provider_name}...",
479
- status_message=f"Menyiapkan arsip folder untuk {provider_name}...",
480
  gofile_progress=0,
481
  gofile_speed="",
482
  gofile_eta_seconds=0,
483
  )
484
 
485
- with zipfile.ZipFile(archive_path, "w", compression=zipfile.ZIP_DEFLATED) as archive:
486
- for file_path in source_path.rglob("*"):
487
- if file_path.is_file():
488
- archive.write(file_path, file_path.relative_to(source_path))
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
489
 
490
  update_torrent_entry(
491
  torrent_hash,
492
- gofile_status=f"Arsip siap, memulai upload ke {provider_name}...",
493
  status_message="",
494
  )
495
  return archive_path, True
496
 
497
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
498
  def clear_gofile_runtime_fields(entry: dict) -> None:
499
  entry["gofile_uploading"] = False
500
  entry["gofile_progress"] = 0
@@ -1031,11 +1192,25 @@ def pixeldrain_upload_attempt(torrent_hash: str, file_path: Path, started_at: fl
1031
  return payload
1032
 
1033
 
1034
- def start_gofile_upload_background(torrent_hash: str, torrent_name: str, file_path: Path) -> None:
1035
  def worker():
1036
  upload_path = file_path
1037
  cleanup_upload_path = False
1038
  try:
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1039
  upload_path, cleanup_upload_path = prepare_upload_source(file_path, torrent_hash, "GoFile")
1040
  started_at = time.time()
1041
  payload = None
@@ -1105,11 +1280,25 @@ def start_gofile_upload_background(torrent_hash: str, torrent_name: str, file_pa
1105
  thread.start()
1106
 
1107
 
1108
- def start_pixeldrain_upload_background(torrent_hash: str, torrent_name: str, file_path: Path) -> None:
1109
  def worker():
1110
  upload_path = file_path
1111
  cleanup_upload_path = False
1112
  try:
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1113
  upload_path, cleanup_upload_path = prepare_upload_source(file_path, torrent_hash, "PixelDrain")
1114
  payload = pixeldrain_upload_attempt(torrent_hash, upload_path, time.time())
1115
  file_id = payload.get("id")
@@ -1136,7 +1325,7 @@ def start_pixeldrain_upload_background(torrent_hash: str, torrent_name: str, fil
1136
  add_event(state, "warning", f"Upload PixelDrain dibatalkan untuk {torrent_name}.")
1137
 
1138
  update_state(cancel_mutator)
1139
- except ValueError as exc:
1140
  def error_mutator(state: dict):
1141
  entry = state.setdefault("torrents", {}).setdefault(torrent_hash, {})
1142
  clear_gofile_runtime_fields(entry)
@@ -1280,6 +1469,7 @@ def upload_torrent_to_gofile(torrent_hash: str):
1280
  return action_response("Torrent tidak ditemukan.", ok=False, status_code=404)
1281
 
1282
  torrent = torrents[0]
 
1283
  progress = float(getattr(torrent, "progress", 0) or 0)
1284
  if progress < 1:
1285
  return action_response("Upload ke GoFile hanya tersedia setelah download selesai.", ok=False, status_code=400)
@@ -1287,6 +1477,8 @@ def upload_torrent_to_gofile(torrent_hash: str):
1287
  content_path = Path(getattr(torrent, "content_path", "") or "")
1288
  if not content_path.exists():
1289
  return action_response("File hasil download tidak ditemukan di storage.", ok=False, status_code=404)
 
 
1290
 
1291
  state = load_monitor_state()
1292
  entry = state.setdefault("torrents", {}).setdefault(torrent_hash, {})
@@ -1305,8 +1497,8 @@ def upload_torrent_to_gofile(torrent_hash: str):
1305
  entry["status_message"] = ""
1306
  save_monitor_state(state)
1307
 
1308
- start_gofile_upload_background(torrent_hash, torrent.name, content_path)
1309
- return action_response("Upload ke GoFile dimulai.")
1310
  except qbittorrentapi.APIError as exc:
1311
  return action_response(f"Gagal memulai upload GoFile: {exc}", ok=False, status_code=502)
1312
 
@@ -1338,6 +1530,7 @@ def upload_torrent_to_pixeldrain(torrent_hash: str):
1338
  return action_response("Torrent tidak ditemukan.", ok=False, status_code=404)
1339
 
1340
  torrent = torrents[0]
 
1341
  progress = float(getattr(torrent, "progress", 0) or 0)
1342
  if progress < 1:
1343
  return action_response("Upload ke PixelDrain hanya tersedia setelah download selesai.", ok=False, status_code=400)
@@ -1345,6 +1538,8 @@ def upload_torrent_to_pixeldrain(torrent_hash: str):
1345
  content_path = Path(getattr(torrent, "content_path", "") or "")
1346
  if not content_path.exists():
1347
  return action_response("File hasil download tidak ditemukan di storage.", ok=False, status_code=404)
 
 
1348
 
1349
  state = load_monitor_state()
1350
  entry = state.setdefault("torrents", {}).setdefault(torrent_hash, {})
@@ -1363,8 +1558,8 @@ def upload_torrent_to_pixeldrain(torrent_hash: str):
1363
  entry["status_message"] = ""
1364
  save_monitor_state(state)
1365
 
1366
- start_pixeldrain_upload_background(torrent_hash, torrent.name, content_path)
1367
- return action_response("Upload ke PixelDrain dimulai.")
1368
  except qbittorrentapi.APIError as exc:
1369
  return action_response(f"Gagal memulai upload PixelDrain: {exc}", ok=False, status_code=502)
1370
 
 
8
  import subprocess
9
  import threading
10
  import time
 
11
  from pathlib import Path
12
  from urllib.parse import quote, urlparse
13
 
 
74
  return sanitized or "archive"
75
 
76
 
77
+ def flatten_relative_name(relative_path: Path) -> str:
78
+ flattened = "__".join(relative_path.parts)
79
+ return safe_filename(flattened)
80
+
81
+
82
  def parse_size_token(token: str) -> int | None:
83
  cleaned = token.strip()
84
  if not cleaned or cleaned in {"-", "--", "--:--:--"}:
 
402
  state_entry = state_entry or {}
403
  status_message = state_entry.get("status_message", "")
404
  content_path = Path(getattr(torrent, "content_path", "") or "")
405
+ is_folder = bool(content_path and content_path.exists() and content_path.is_dir())
406
  gofile_uploading = bool(state_entry.get("gofile_uploading"))
407
  upload_provider = state_entry.get("gofile_provider", "GoFile")
408
  gofile_progress = int(state_entry.get("gofile_progress", 0) or 0)
 
460
  "can_copy_link": bool(state_entry.get("gofile_link")),
461
  "can_cancel_gofile_upload": gofile_uploading,
462
  "can_pixeldrain_upload": can_gofile_upload and bool(PIXELDRAIN_API_KEY),
463
+ "is_folder": is_folder,
464
+ "can_raw_gofile_upload": is_folder,
465
+ "can_raw_pixeldrain_upload": is_folder and bool(PIXELDRAIN_API_KEY),
466
  }
467
 
468
 
 
483
 
484
  update_torrent_entry(
485
  torrent_hash,
486
+ gofile_status=f"Archiving folder for {provider_name}...",
487
+ status_message=f"Archiving folder for {provider_name}...",
488
  gofile_progress=0,
489
  gofile_speed="",
490
  gofile_eta_seconds=0,
491
  )
492
 
493
+ process = subprocess.Popen(
494
+ ["7z", "a", "-tzip", "-mx=5", str(archive_path), source_path.name],
495
+ cwd=str(source_path.parent),
496
+ stdout=subprocess.PIPE,
497
+ stderr=subprocess.PIPE,
498
+ text=True,
499
+ )
500
+
501
+ update_torrent_entry(torrent_hash, gofile_pid=process.pid)
502
+ while True:
503
+ return_code = process.poll()
504
+ current_state = load_monitor_state()
505
+ current_entry = current_state.setdefault("torrents", {}).setdefault(torrent_hash, {})
506
+ if current_entry.get("gofile_cancel_requested"):
507
+ cancel_upload_process(process.pid)
508
+
509
+ if return_code is not None:
510
+ break
511
+ time.sleep(1)
512
+
513
+ stdout, stderr = process.communicate()
514
+ if current_entry.get("gofile_cancel_requested") or process.returncode == -15:
515
+ archive_path.unlink(missing_ok=True)
516
+ raise GofileUploadCancelled(f"Archiving {provider_name} dibatalkan.")
517
+ if process.returncode != 0:
518
+ archive_path.unlink(missing_ok=True)
519
+ raise ValueError(stderr.strip() or stdout.strip() or "7z gagal membuat arsip.")
520
 
521
  update_torrent_entry(
522
  torrent_hash,
523
+ gofile_status=f"Archive ready, memulai upload ke {provider_name}...",
524
  status_message="",
525
  )
526
  return archive_path, True
527
 
528
 
529
+ def list_folder_files(source_path: Path) -> list[tuple[Path, Path]]:
530
+ return [(file_path, file_path.relative_to(source_path)) for file_path in source_path.rglob("*") if file_path.is_file()]
531
+
532
+
533
+ def upload_folder_raw_gofile(torrent_hash: str, source_path: Path) -> tuple[str, str]:
534
+ file_entries = list_folder_files(source_path)
535
+ if not file_entries:
536
+ raise ValueError("Folder tidak berisi file yang bisa diupload.")
537
+
538
+ total_files = len(file_entries)
539
+ total_bytes = sum(file_path.stat().st_size for file_path, _ in file_entries)
540
+ uploaded_bytes = 0
541
+ folder_id = ""
542
+ folder_link = ""
543
+ guest_token = ""
544
+
545
+ for index, (file_path, relative_path) in enumerate(file_entries, start=1):
546
+ current_state = load_monitor_state()
547
+ current_entry = current_state.setdefault("torrents", {}).setdefault(torrent_hash, {})
548
+ if current_entry.get("gofile_cancel_requested"):
549
+ raise GofileUploadCancelled("Upload GoFile dibatalkan.")
550
+
551
+ progress = int((uploaded_bytes / total_bytes) * 100) if total_bytes else 0
552
+ update_torrent_entry(
553
+ torrent_hash,
554
+ gofile_progress=progress,
555
+ gofile_speed="",
556
+ gofile_eta_seconds=0,
557
+ gofile_status=f"Uploading raw folder to GoFile... {index}/{total_files}",
558
+ status_message=f"Uploading raw folder to GoFile... {index}/{total_files}",
559
+ )
560
+
561
+ with file_path.open("rb") as handle:
562
+ files = {"file": (flatten_relative_name(relative_path), handle)}
563
+ data: dict[str, str] = {}
564
+ headers = {}
565
+ if folder_id:
566
+ data["folderId"] = folder_id
567
+ if guest_token:
568
+ headers["X-GuestToken"] = guest_token
569
+ if GOFILE_API_TOKEN:
570
+ headers["Authorization"] = f"Bearer {GOFILE_API_TOKEN}"
571
+
572
+ response = requests.post(GOFILE_UPLOAD_URLS[0], files=files, data=data, headers=headers, timeout=3600)
573
+ response.raise_for_status()
574
+ payload = response.json()
575
+
576
+ data_payload = payload.get("data", payload)
577
+ folder_id = data_payload.get("parentFolder", folder_id)
578
+ folder_link = data_payload.get("downloadPage", folder_link)
579
+ guest_token = data_payload.get("guestToken", guest_token)
580
+ uploaded_bytes += file_path.stat().st_size
581
+ progress = int((uploaded_bytes / total_bytes) * 100) if total_bytes else 100
582
+ update_torrent_entry(
583
+ torrent_hash,
584
+ gofile_progress=progress,
585
+ gofile_status=f"Uploading raw folder to GoFile... {index}/{total_files}",
586
+ status_message=f"Uploading raw folder to GoFile... {index}/{total_files}",
587
+ )
588
+
589
+ if not folder_link:
590
+ raise ValueError("GoFile tidak mengembalikan link folder.")
591
+ return folder_link, folder_id
592
+
593
+
594
+ def upload_folder_raw_pixeldrain(torrent_hash: str, source_path: Path) -> str:
595
+ file_entries = list_folder_files(source_path)
596
+ if not file_entries:
597
+ raise ValueError("Folder tidak berisi file yang bisa diupload.")
598
+
599
+ total_files = len(file_entries)
600
+ total_bytes = sum(file_path.stat().st_size for file_path, _ in file_entries)
601
+ uploaded_bytes = 0
602
+ uploaded_files: list[dict[str, str]] = []
603
+
604
+ for index, (file_path, relative_path) in enumerate(file_entries, start=1):
605
+ current_state = load_monitor_state()
606
+ current_entry = current_state.setdefault("torrents", {}).setdefault(torrent_hash, {})
607
+ if current_entry.get("gofile_cancel_requested"):
608
+ raise GofileUploadCancelled("Upload PixelDrain dibatalkan.")
609
+
610
+ progress = int((uploaded_bytes / total_bytes) * 100) if total_bytes else 0
611
+ update_torrent_entry(
612
+ torrent_hash,
613
+ gofile_progress=progress,
614
+ gofile_speed="",
615
+ gofile_eta_seconds=0,
616
+ gofile_status=f"Uploading raw folder to PixelDrain... {index}/{total_files}",
617
+ status_message=f"Uploading raw folder to PixelDrain... {index}/{total_files}",
618
+ )
619
+
620
+ with file_path.open("rb") as handle:
621
+ encoded_name = quote(flatten_relative_name(relative_path), safe="")
622
+ response = requests.put(
623
+ f"{PIXELDRAIN_API_URL}/file/{encoded_name}",
624
+ data=handle,
625
+ auth=("", PIXELDRAIN_API_KEY),
626
+ timeout=3600,
627
+ )
628
+ response.raise_for_status()
629
+ payload = response.json()
630
+
631
+ file_id = payload.get("id")
632
+ if not file_id:
633
+ raise ValueError("Respons PixelDrain tidak mengandung file id.")
634
+
635
+ uploaded_files.append({"id": file_id, "description": relative_path.as_posix()})
636
+ uploaded_bytes += file_path.stat().st_size
637
+ progress = int((uploaded_bytes / total_bytes) * 100) if total_bytes else 100
638
+ update_torrent_entry(
639
+ torrent_hash,
640
+ gofile_progress=progress,
641
+ gofile_status=f"Uploading raw folder to PixelDrain... {index}/{total_files}",
642
+ status_message=f"Uploading raw folder to PixelDrain... {index}/{total_files}",
643
+ )
644
+
645
+ response = requests.post(
646
+ f"{PIXELDRAIN_API_URL}/list",
647
+ json={"title": source_path.name, "anonymous": False, "files": uploaded_files},
648
+ auth=("", PIXELDRAIN_API_KEY),
649
+ timeout=60,
650
+ )
651
+ response.raise_for_status()
652
+ payload = response.json()
653
+ list_id = payload.get("id")
654
+ if not list_id:
655
+ raise ValueError("Respons PixelDrain tidak mengandung list id.")
656
+ return f"https://pixeldrain.com/l/{list_id}"
657
+
658
+
659
  def clear_gofile_runtime_fields(entry: dict) -> None:
660
  entry["gofile_uploading"] = False
661
  entry["gofile_progress"] = 0
 
1192
  return payload
1193
 
1194
 
1195
+ def start_gofile_upload_background(torrent_hash: str, torrent_name: str, file_path: Path, mode: str = "zip") -> None:
1196
  def worker():
1197
  upload_path = file_path
1198
  cleanup_upload_path = False
1199
  try:
1200
+ if file_path.is_dir() and mode == "raw":
1201
+ folder_link, _folder_id = upload_folder_raw_gofile(torrent_hash, file_path)
1202
+
1203
+ def success_raw_mutator(state: dict):
1204
+ entry = state.setdefault("torrents", {}).setdefault(torrent_hash, {})
1205
+ clear_gofile_runtime_fields(entry)
1206
+ entry["gofile_link"] = folder_link
1207
+ entry["gofile_provider"] = "GoFile"
1208
+ entry["gofile_status"] = f"Upload raw folder GoFile berhasil: {folder_link}"
1209
+ entry["status_message"] = "Upload raw folder GoFile selesai. Link siap disalin."
1210
+
1211
+ update_state(success_raw_mutator)
1212
+ return
1213
+
1214
  upload_path, cleanup_upload_path = prepare_upload_source(file_path, torrent_hash, "GoFile")
1215
  started_at = time.time()
1216
  payload = None
 
1280
  thread.start()
1281
 
1282
 
1283
+ def start_pixeldrain_upload_background(torrent_hash: str, torrent_name: str, file_path: Path, mode: str = "zip") -> None:
1284
  def worker():
1285
  upload_path = file_path
1286
  cleanup_upload_path = False
1287
  try:
1288
+ if file_path.is_dir() and mode == "raw":
1289
+ download_page = upload_folder_raw_pixeldrain(torrent_hash, file_path)
1290
+
1291
+ def success_raw_mutator(state: dict):
1292
+ entry = state.setdefault("torrents", {}).setdefault(torrent_hash, {})
1293
+ clear_gofile_runtime_fields(entry)
1294
+ entry["gofile_link"] = download_page
1295
+ entry["gofile_provider"] = "PixelDrain"
1296
+ entry["gofile_status"] = f"Upload raw folder PixelDrain berhasil: {download_page}"
1297
+ entry["status_message"] = "Upload raw folder PixelDrain selesai. Link siap disalin."
1298
+
1299
+ update_state(success_raw_mutator)
1300
+ return
1301
+
1302
  upload_path, cleanup_upload_path = prepare_upload_source(file_path, torrent_hash, "PixelDrain")
1303
  payload = pixeldrain_upload_attempt(torrent_hash, upload_path, time.time())
1304
  file_id = payload.get("id")
 
1325
  add_event(state, "warning", f"Upload PixelDrain dibatalkan untuk {torrent_name}.")
1326
 
1327
  update_state(cancel_mutator)
1328
+ except (ValueError, requests.RequestException) as exc:
1329
  def error_mutator(state: dict):
1330
  entry = state.setdefault("torrents", {}).setdefault(torrent_hash, {})
1331
  clear_gofile_runtime_fields(entry)
 
1469
  return action_response("Torrent tidak ditemukan.", ok=False, status_code=404)
1470
 
1471
  torrent = torrents[0]
1472
+ mode = request.args.get("mode", "zip").lower()
1473
  progress = float(getattr(torrent, "progress", 0) or 0)
1474
  if progress < 1:
1475
  return action_response("Upload ke GoFile hanya tersedia setelah download selesai.", ok=False, status_code=400)
 
1477
  content_path = Path(getattr(torrent, "content_path", "") or "")
1478
  if not content_path.exists():
1479
  return action_response("File hasil download tidak ditemukan di storage.", ok=False, status_code=404)
1480
+ if mode not in {"zip", "raw"}:
1481
+ return action_response("Mode upload tidak valid.", ok=False, status_code=400)
1482
 
1483
  state = load_monitor_state()
1484
  entry = state.setdefault("torrents", {}).setdefault(torrent_hash, {})
 
1497
  entry["status_message"] = ""
1498
  save_monitor_state(state)
1499
 
1500
+ start_gofile_upload_background(torrent_hash, torrent.name, content_path, mode=mode)
1501
+ return action_response("Upload ke GoFile dimulai." if mode == "zip" else "Upload raw folder ke GoFile dimulai.")
1502
  except qbittorrentapi.APIError as exc:
1503
  return action_response(f"Gagal memulai upload GoFile: {exc}", ok=False, status_code=502)
1504
 
 
1530
  return action_response("Torrent tidak ditemukan.", ok=False, status_code=404)
1531
 
1532
  torrent = torrents[0]
1533
+ mode = request.args.get("mode", "zip").lower()
1534
  progress = float(getattr(torrent, "progress", 0) or 0)
1535
  if progress < 1:
1536
  return action_response("Upload ke PixelDrain hanya tersedia setelah download selesai.", ok=False, status_code=400)
 
1538
  content_path = Path(getattr(torrent, "content_path", "") or "")
1539
  if not content_path.exists():
1540
  return action_response("File hasil download tidak ditemukan di storage.", ok=False, status_code=404)
1541
+ if mode not in {"zip", "raw"}:
1542
+ return action_response("Mode upload tidak valid.", ok=False, status_code=400)
1543
 
1544
  state = load_monitor_state()
1545
  entry = state.setdefault("torrents", {}).setdefault(torrent_hash, {})
 
1558
  entry["status_message"] = ""
1559
  save_monitor_state(state)
1560
 
1561
+ start_pixeldrain_upload_background(torrent_hash, torrent.name, content_path, mode=mode)
1562
+ return action_response("Upload ke PixelDrain dimulai." if mode == "zip" else "Upload raw folder ke PixelDrain dimulai.")
1563
  except qbittorrentapi.APIError as exc:
1564
  return action_response(f"Gagal memulai upload PixelDrain: {exc}", ok=False, status_code=502)
1565
 
templates/index.html CHANGED
@@ -127,12 +127,12 @@
127
  </button>
128
  {% endif %}
129
  {% if torrent.can_gofile_upload %}
130
- <button type="button" data-action="upload-gofile" data-hash="{{ torrent.hash }}" class="inline-flex w-full items-center justify-center rounded-2xl border border-sky-400/30 bg-sky-400/10 px-4 py-2 text-sm font-medium text-sky-100 transition hover:bg-sky-400/20 sm:w-auto">
131
  <i class="fa-solid fa-cloud-arrow-up mr-2"></i>Upload GoFile
132
  </button>
133
  {% endif %}
134
  {% if torrent.can_pixeldrain_upload %}
135
- <button type="button" data-action="upload-pixeldrain" data-hash="{{ torrent.hash }}" class="inline-flex w-full items-center justify-center rounded-2xl border border-fuchsia-400/30 bg-fuchsia-400/10 px-4 py-2 text-sm font-medium text-fuchsia-100 transition hover:bg-fuchsia-400/20 sm:w-auto">
136
  <i class="fa-solid fa-hard-drive mr-2"></i>Upload PixelDrain
137
  </button>
138
  {% endif %}
@@ -290,6 +290,33 @@
290
  </div>
291
  </div>
292
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
293
  <script>
294
  const torrentList = document.getElementById("torrent-list");
295
  const eventList = document.getElementById("event-list");
@@ -307,8 +334,16 @@
307
  const modalClose = document.getElementById("modal-close");
308
  const modalCancel = document.getElementById("modal-cancel");
309
  const modalConfirm = document.getElementById("modal-confirm");
 
 
 
 
 
 
310
  const speedtestButton = document.getElementById("speedtest-button");
311
  let pendingDelete = null;
 
 
312
 
313
  function escapeHtml(value) {
314
  return String(value).replace(/[&<>"']/g, (char) => ({
@@ -400,10 +435,10 @@
400
  buttons.push(`<button type="button" data-action="cancel-gofile" data-hash="${escapeHtml(torrent.hash)}" class="inline-flex w-full items-center justify-center rounded-2xl border border-amber-400/30 bg-amber-400/10 px-4 py-2 text-sm font-medium text-amber-100 transition hover:bg-amber-400/20 sm:w-auto"><i class="fa-solid fa-ban mr-2"></i>Cancel Upload</button>`);
401
  }
402
  if (torrent.can_gofile_upload) {
403
- buttons.push(`<button type="button" data-action="upload-gofile" data-hash="${escapeHtml(torrent.hash)}" class="inline-flex w-full items-center justify-center rounded-2xl border border-sky-400/30 bg-sky-400/10 px-4 py-2 text-sm font-medium text-sky-100 transition hover:bg-sky-400/20 sm:w-auto"><i class="fa-solid fa-cloud-arrow-up mr-2"></i>Upload GoFile</button>`);
404
  }
405
  if (torrent.can_pixeldrain_upload) {
406
- buttons.push(`<button type="button" data-action="upload-pixeldrain" data-hash="${escapeHtml(torrent.hash)}" class="inline-flex w-full items-center justify-center rounded-2xl border border-fuchsia-400/30 bg-fuchsia-400/10 px-4 py-2 text-sm font-medium text-fuchsia-100 transition hover:bg-fuchsia-400/20 sm:w-auto"><i class="fa-solid fa-hard-drive mr-2"></i>Upload PixelDrain</button>`);
407
  }
408
  return buttons.join("");
409
  }
@@ -550,12 +585,58 @@
550
  }
551
  }
552
 
553
- async function triggerTorrentAction(action, hash) {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
554
  const method = action === "delete" ? "DELETE" : "POST";
 
555
  const target = action === "delete"
556
  ? `/api/torrents/${hash}?with_files=${deleteWithFiles.checked}`
557
  : action === "upload-gofile"
558
- ? `/api/torrents/${hash}/upload-gofile`
 
 
559
  : action === "cancel-gofile"
560
  ? `/api/torrents/${hash}/cancel-gofile`
561
  : `/api/torrents/${hash}/${action}`;
@@ -629,6 +710,16 @@
629
  return;
630
  }
631
 
 
 
 
 
 
 
 
 
 
 
632
  if (button.dataset.action === "copy-link") {
633
  try {
634
  await navigator.clipboard.writeText(button.dataset.link || "");
@@ -658,11 +749,18 @@
658
  });
659
  modalClose.addEventListener("click", closeDeleteModal);
660
  modalCancel.addEventListener("click", closeDeleteModal);
 
 
661
  deleteModal.addEventListener("click", (event) => {
662
  if (event.target === deleteModal) {
663
  closeDeleteModal();
664
  }
665
  });
 
 
 
 
 
666
  modalConfirm.addEventListener("click", async () => {
667
  if (!pendingDelete) {
668
  return;
@@ -675,6 +773,19 @@
675
  modalConfirm.disabled = false;
676
  }
677
  });
 
 
 
 
 
 
 
 
 
 
 
 
 
678
 
679
  refreshTorrents();
680
  applyProgressBars();
 
127
  </button>
128
  {% endif %}
129
  {% if torrent.can_gofile_upload %}
130
+ <button type="button" data-action="upload-gofile" data-hash="{{ torrent.hash }}" data-is-folder="{{ 'true' if torrent.is_folder else 'false' }}" data-provider="GoFile" data-raw-enabled="{{ 'true' if torrent.can_raw_gofile_upload else 'false' }}" class="inline-flex w-full items-center justify-center rounded-2xl border border-sky-400/30 bg-sky-400/10 px-4 py-2 text-sm font-medium text-sky-100 transition hover:bg-sky-400/20 sm:w-auto">
131
  <i class="fa-solid fa-cloud-arrow-up mr-2"></i>Upload GoFile
132
  </button>
133
  {% endif %}
134
  {% if torrent.can_pixeldrain_upload %}
135
+ <button type="button" data-action="upload-pixeldrain" data-hash="{{ torrent.hash }}" data-is-folder="{{ 'true' if torrent.is_folder else 'false' }}" data-provider="PixelDrain" data-raw-enabled="{{ 'true' if torrent.can_raw_pixeldrain_upload else 'false' }}" class="inline-flex w-full items-center justify-center rounded-2xl border border-fuchsia-400/30 bg-fuchsia-400/10 px-4 py-2 text-sm font-medium text-fuchsia-100 transition hover:bg-fuchsia-400/20 sm:w-auto">
136
  <i class="fa-solid fa-hard-drive mr-2"></i>Upload PixelDrain
137
  </button>
138
  {% endif %}
 
290
  </div>
291
  </div>
292
 
293
+ <div id="folder-upload-modal" class="fixed inset-0 z-50 hidden items-center justify-center bg-black/70 px-4">
294
+ <div class="w-full max-w-lg rounded-3xl border border-white/10 bg-stone-900 p-6 shadow-2xl shadow-black/40">
295
+ <div class="flex items-start justify-between gap-4">
296
+ <div>
297
+ <p class="text-sm uppercase tracking-[0.25em] text-sky-300/80">Folder Upload</p>
298
+ <h3 class="mt-2 text-xl font-semibold text-white">Pilih mode upload</h3>
299
+ </div>
300
+ <button id="folder-upload-close" type="button" class="rounded-full border border-white/10 px-3 py-1 text-sm text-stone-300 hover:bg-white/10">X</button>
301
+ </div>
302
+ <p id="folder-upload-text" class="mt-4 text-sm text-stone-300"></p>
303
+ <div class="mt-5 grid gap-3">
304
+ <button type="button" data-upload-mode="zip" class="folder-upload-choice rounded-2xl border border-emerald-400/30 bg-emerald-400/10 px-4 py-4 text-left transition hover:bg-emerald-400/20">
305
+ <span class="block text-sm font-semibold text-emerald-100"><i class="fa-solid fa-file-zipper mr-2"></i>ZIP with 7-Zip</span>
306
+ <span class="mt-1 block text-xs text-emerald-50/80">Direkomendasikan. Struktur folder tetap utuh dan upload lebih konsisten.</span>
307
+ </button>
308
+ <button type="button" data-upload-mode="raw" class="folder-upload-choice rounded-2xl border border-white/10 bg-white/5 px-4 py-4 text-left transition hover:bg-white/10">
309
+ <span class="block text-sm font-semibold text-white"><i class="fa-solid fa-folder-tree mr-2"></i>Raw Files</span>
310
+ <span id="raw-upload-description" class="mt-1 block text-xs text-stone-300">Upload file satu per satu tanpa zip.</span>
311
+ </button>
312
+ </div>
313
+ <div class="mt-6 flex flex-wrap justify-end gap-3">
314
+ <button id="folder-upload-cancel" type="button" class="rounded-2xl border border-white/10 bg-white/10 px-4 py-2 text-sm font-medium text-white transition hover:bg-white/15">Batal</button>
315
+ <button id="folder-upload-confirm" type="button" class="rounded-2xl border border-sky-400/30 bg-sky-400/10 px-4 py-2 text-sm font-medium text-sky-100 transition hover:bg-sky-400/20">Lanjutkan</button>
316
+ </div>
317
+ </div>
318
+ </div>
319
+
320
  <script>
321
  const torrentList = document.getElementById("torrent-list");
322
  const eventList = document.getElementById("event-list");
 
334
  const modalClose = document.getElementById("modal-close");
335
  const modalCancel = document.getElementById("modal-cancel");
336
  const modalConfirm = document.getElementById("modal-confirm");
337
+ const folderUploadModal = document.getElementById("folder-upload-modal");
338
+ const folderUploadText = document.getElementById("folder-upload-text");
339
+ const folderUploadClose = document.getElementById("folder-upload-close");
340
+ const folderUploadCancel = document.getElementById("folder-upload-cancel");
341
+ const folderUploadConfirm = document.getElementById("folder-upload-confirm");
342
+ const rawUploadDescription = document.getElementById("raw-upload-description");
343
  const speedtestButton = document.getElementById("speedtest-button");
344
  let pendingDelete = null;
345
+ let pendingFolderUpload = null;
346
+ let selectedFolderUploadMode = "zip";
347
 
348
  function escapeHtml(value) {
349
  return String(value).replace(/[&<>"']/g, (char) => ({
 
435
  buttons.push(`<button type="button" data-action="cancel-gofile" data-hash="${escapeHtml(torrent.hash)}" class="inline-flex w-full items-center justify-center rounded-2xl border border-amber-400/30 bg-amber-400/10 px-4 py-2 text-sm font-medium text-amber-100 transition hover:bg-amber-400/20 sm:w-auto"><i class="fa-solid fa-ban mr-2"></i>Cancel Upload</button>`);
436
  }
437
  if (torrent.can_gofile_upload) {
438
+ buttons.push(`<button type="button" data-action="upload-gofile" data-hash="${escapeHtml(torrent.hash)}" data-is-folder="${torrent.is_folder ? "true" : "false"}" data-provider="GoFile" data-raw-enabled="${torrent.can_raw_gofile_upload ? "true" : "false"}" class="inline-flex w-full items-center justify-center rounded-2xl border border-sky-400/30 bg-sky-400/10 px-4 py-2 text-sm font-medium text-sky-100 transition hover:bg-sky-400/20 sm:w-auto"><i class="fa-solid fa-cloud-arrow-up mr-2"></i>Upload GoFile</button>`);
439
  }
440
  if (torrent.can_pixeldrain_upload) {
441
+ buttons.push(`<button type="button" data-action="upload-pixeldrain" data-hash="${escapeHtml(torrent.hash)}" data-is-folder="${torrent.is_folder ? "true" : "false"}" data-provider="PixelDrain" data-raw-enabled="${torrent.can_raw_pixeldrain_upload ? "true" : "false"}" class="inline-flex w-full items-center justify-center rounded-2xl border border-fuchsia-400/30 bg-fuchsia-400/10 px-4 py-2 text-sm font-medium text-fuchsia-100 transition hover:bg-fuchsia-400/20 sm:w-auto"><i class="fa-solid fa-hard-drive mr-2"></i>Upload PixelDrain</button>`);
442
  }
443
  return buttons.join("");
444
  }
 
585
  }
586
  }
587
 
588
+ function openFolderUploadModal(action, hash, provider, rawEnabled) {
589
+ pendingFolderUpload = { action, hash, provider, rawEnabled };
590
+ selectedFolderUploadMode = "zip";
591
+ folderUploadText.textContent = `Torrent ini berisi folder. Pilih cara upload ke ${provider}.`;
592
+ rawUploadDescription.textContent = rawEnabled
593
+ ? "Upload file satu per satu tanpa zip."
594
+ : "Mode raw tidak tersedia untuk pilihan ini.";
595
+ document.querySelectorAll(".folder-upload-choice").forEach((button) => {
596
+ const mode = button.dataset.uploadMode;
597
+ const disabled = mode === "raw" && !rawEnabled;
598
+ button.disabled = disabled;
599
+ button.classList.toggle("opacity-40", disabled);
600
+ button.classList.toggle("cursor-not-allowed", disabled);
601
+ button.classList.toggle("border-sky-400/40", mode === "zip");
602
+ button.classList.toggle("bg-sky-400/10", mode === "zip");
603
+ });
604
+ folderUploadModal.classList.remove("hidden");
605
+ folderUploadModal.classList.add("flex");
606
+ }
607
+
608
+ function closeFolderUploadModal() {
609
+ pendingFolderUpload = null;
610
+ selectedFolderUploadMode = "zip";
611
+ folderUploadModal.classList.add("hidden");
612
+ folderUploadModal.classList.remove("flex");
613
+ }
614
+
615
+ document.querySelectorAll(".folder-upload-choice").forEach((button) => {
616
+ button.addEventListener("click", () => {
617
+ if (button.disabled) {
618
+ return;
619
+ }
620
+ selectedFolderUploadMode = button.dataset.uploadMode || "zip";
621
+ document.querySelectorAll(".folder-upload-choice").forEach((choice) => {
622
+ const active = choice.dataset.uploadMode === selectedFolderUploadMode;
623
+ choice.classList.toggle("border-sky-400/40", active);
624
+ choice.classList.toggle("bg-sky-400/10", active);
625
+ choice.classList.toggle("border-white/10", !active && choice.dataset.uploadMode !== "zip");
626
+ choice.classList.toggle("bg-white/5", !active && choice.dataset.uploadMode !== "zip");
627
+ });
628
+ });
629
+ });
630
+
631
+ async function triggerTorrentAction(action, hash, mode = null) {
632
  const method = action === "delete" ? "DELETE" : "POST";
633
+ const query = mode ? `?mode=${encodeURIComponent(mode)}` : "";
634
  const target = action === "delete"
635
  ? `/api/torrents/${hash}?with_files=${deleteWithFiles.checked}`
636
  : action === "upload-gofile"
637
+ ? `/api/torrents/${hash}/upload-gofile${query}`
638
+ : action === "upload-pixeldrain"
639
+ ? `/api/torrents/${hash}/upload-pixeldrain${query}`
640
  : action === "cancel-gofile"
641
  ? `/api/torrents/${hash}/cancel-gofile`
642
  : `/api/torrents/${hash}/${action}`;
 
710
  return;
711
  }
712
 
713
+ if ((button.dataset.action === "upload-gofile" || button.dataset.action === "upload-pixeldrain") && button.dataset.isFolder === "true") {
714
+ openFolderUploadModal(
715
+ button.dataset.action,
716
+ button.dataset.hash,
717
+ button.dataset.provider || "provider ini",
718
+ button.dataset.rawEnabled === "true",
719
+ );
720
+ return;
721
+ }
722
+
723
  if (button.dataset.action === "copy-link") {
724
  try {
725
  await navigator.clipboard.writeText(button.dataset.link || "");
 
749
  });
750
  modalClose.addEventListener("click", closeDeleteModal);
751
  modalCancel.addEventListener("click", closeDeleteModal);
752
+ folderUploadClose.addEventListener("click", closeFolderUploadModal);
753
+ folderUploadCancel.addEventListener("click", closeFolderUploadModal);
754
  deleteModal.addEventListener("click", (event) => {
755
  if (event.target === deleteModal) {
756
  closeDeleteModal();
757
  }
758
  });
759
+ folderUploadModal.addEventListener("click", (event) => {
760
+ if (event.target === folderUploadModal) {
761
+ closeFolderUploadModal();
762
+ }
763
+ });
764
  modalConfirm.addEventListener("click", async () => {
765
  if (!pendingDelete) {
766
  return;
 
773
  modalConfirm.disabled = false;
774
  }
775
  });
776
+ folderUploadConfirm.addEventListener("click", async () => {
777
+ if (!pendingFolderUpload) {
778
+ return;
779
+ }
780
+
781
+ folderUploadConfirm.disabled = true;
782
+ try {
783
+ await triggerTorrentAction(pendingFolderUpload.action, pendingFolderUpload.hash, selectedFolderUploadMode);
784
+ closeFolderUploadModal();
785
+ } finally {
786
+ folderUploadConfirm.disabled = false;
787
+ }
788
+ });
789
 
790
  refreshTorrents();
791
  applyProgressBars();