Compare commits
11 Commits
9b9c25806b
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
| 800a8dca90 | |||
| c7b09b30bd | |||
| 5c3c864a9e | |||
| 3aac0116e6 | |||
| b4330c0362 | |||
| 25fd30a0c3 | |||
| 26d4613dd1 | |||
| 42332ac329 | |||
| c7e52a2382 | |||
| cf702fa316 | |||
| 955ea36433 |
@@ -1,7 +1,7 @@
|
||||
USER_ID=1000
|
||||
GROUP_ID=1000
|
||||
|
||||
DOMAIN=127.0.0.1
|
||||
TRAEFIK_HOST_RULE=Host(`example.com`) || Host(`www.example.com`)
|
||||
|
||||
LISTEN_PORT=8000
|
||||
|
||||
|
||||
@@ -58,6 +58,7 @@ INSTALLED_APPS = [
|
||||
'user',
|
||||
'api',
|
||||
'torrent',
|
||||
'watch_party'
|
||||
]
|
||||
if DEBUG:
|
||||
INSTALLED_APPS = ["daphne"] + INSTALLED_APPS
|
||||
@@ -252,4 +253,5 @@ TRANSMISSION = {
|
||||
"port": getenv("TRANSMISSION_PORT", 9091),
|
||||
"username": getenv("TRANSMISSION_USERNAME"),
|
||||
"password": getenv("TRANSMISSION_PASSWORD")
|
||||
}
|
||||
}
|
||||
TORRENT_TTL = int(getenv("TORRENT_TTL", 90*24*60*60)) # 90 jours
|
||||
@@ -1,4 +1,4 @@
|
||||
#!/bin/bash
|
||||
#!/usr/bin/env bash
|
||||
|
||||
CORES=$(nproc)
|
||||
WORKERS=$((2 * CORES + 1))
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
>
|
||||
<template v-slot:prepend>
|
||||
<v-btn @click.stop="downloadClicked" :disabled="!is_download_finished" icon="mdi-download" color="green" variant="text"/>
|
||||
<v-btn v-if="file.is_video" @click.stop="fluxClicked" :disabled="!is_download_finished" icon="mdi-vlc" color="orange" variant="text"></v-btn>
|
||||
<v-dialog v-if="file.is_stream_video" v-model="video_modal" width="75%" height="100%">
|
||||
<template v-slot:activator="{ props }">
|
||||
<v-btn v-bind="props" icon="mdi-play" variant="text"/>
|
||||
@@ -45,14 +46,24 @@ export default {
|
||||
downloadClicked(){
|
||||
if(!this.is_download_finished) return;
|
||||
if(this.$qt.is_active){
|
||||
this.$qt.callMethod("add_files", this.file);
|
||||
this.$qt.callMethod("add_files", [this.file]);
|
||||
}else{
|
||||
let a = document.createElement("a");
|
||||
a.href = this.file.download_url;
|
||||
a.setAttribute("download", "download");
|
||||
a.click();
|
||||
}
|
||||
|
||||
},
|
||||
fluxClicked(){
|
||||
const full_url = new URL(this.file.flux_url, window.location.href).href
|
||||
navigator.clipboard.writeText(full_url)
|
||||
.then(() => {
|
||||
// Optionnel: Vous pouvez ajouter une notification pour indiquer à l'utilisateur que l'URL a été copiée
|
||||
console.log('URL copiée dans le presse-papier');
|
||||
})
|
||||
.catch(err => {
|
||||
console.error('Erreur lors de la copie dans le presse-papier:', err);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,19 +8,32 @@
|
||||
<!-- indeterminate-->
|
||||
<!-- :color="torrent.transmission_data.progress < 100 ? 'green':'red'"-->
|
||||
<!-- />-->
|
||||
<v-icon
|
||||
v-if="torrent.transmission_data.rateDownload && torrent.transmission_data.rateUpload"
|
||||
:color="torrent.transmission_data.rateDownload ? 'green':'red'"
|
||||
:icon="torrent.transmission_data.rateDownload ? 'mdi-arrow-down-bold':'mdi-arrow-up-bold'"
|
||||
/>
|
||||
<strong style="padding-left: 5px">
|
||||
|
||||
<!-- Si téléchargement en cours-->
|
||||
<v-chip variant="text" color="white" v-if="progressData.mode === 'download'">
|
||||
<v-icon
|
||||
v-if="torrent.transmission_data.rateDownload"
|
||||
color="green"
|
||||
icon="mdi-arrow-down-bold"
|
||||
/>
|
||||
{{progressData.value}}%
|
||||
<strong
|
||||
v-if="torrent.transmission_data.rateDownload || torrent.transmission_data.rateUpload"
|
||||
>
|
||||
({{torrent.transmission_data.rateDownload ? fs_speed_format(torrent.transmission_data.rateDownload):fs_speed_format(torrent.transmission_data.rateUpload)}}/s)
|
||||
<strong style="padding-left: 5px" v-if="torrent.transmission_data.rateDownload">
|
||||
({{fs_speed_format(torrent.transmission_data.rateDownload)}}/s)
|
||||
</strong>
|
||||
</strong>
|
||||
</v-chip>
|
||||
|
||||
<!-- Si téléchargement terminé-->
|
||||
<v-chip variant="text" color="red" v-else>
|
||||
<v-icon
|
||||
v-if="torrent.transmission_data.rateUpload"
|
||||
color="red"
|
||||
icon="mdi-arrow-up-bold"
|
||||
/>
|
||||
{{fs_format(torrent.transmission_data.uploadedEver)}}
|
||||
<strong style="padding-left: 5px" v-if="torrent.transmission_data.rateUpload">
|
||||
({{fs_speed_format(torrent.transmission_data.rateUpload)}}/s)
|
||||
</strong>
|
||||
</v-chip>
|
||||
</v-progress-linear>
|
||||
<v-row no-gutters>
|
||||
<!-- ligne du haut -->
|
||||
@@ -115,9 +128,10 @@ export default {
|
||||
},
|
||||
computed: {
|
||||
progressData(){
|
||||
let color = "red", value = 0, eta;
|
||||
let color = "red", value = 0, mode, eta;
|
||||
if(this.torrent.transmission_data.progress < 100){
|
||||
color = "blue";
|
||||
mode = "download";
|
||||
value = this.torrent.transmission_data.progress;
|
||||
if(this.torrent.transmission_data.eta !== -1){
|
||||
eta = toHHMMSS(this.torrent.transmission_data.eta);
|
||||
@@ -126,10 +140,11 @@ export default {
|
||||
}
|
||||
}else{
|
||||
color = "green";
|
||||
mode = "upload";
|
||||
value = Number((this.torrent.transmission_data.uploadRatio / 5) * 100).toFixed(2)
|
||||
if(value > 100) value = 100;
|
||||
}
|
||||
return {color, value, eta};
|
||||
return {color, value, mode, eta};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
from django.conf import settings
|
||||
from django.utils import timezone
|
||||
from django.core.management.base import BaseCommand
|
||||
from django.db import close_old_connections
|
||||
|
||||
@@ -5,6 +7,7 @@ import time
|
||||
import signal
|
||||
import sys
|
||||
import traceback
|
||||
from datetime import timedelta
|
||||
|
||||
from torrent.models import Torrent
|
||||
from torrent.utils import transmission_handler
|
||||
@@ -27,11 +30,22 @@ def update_transmission_data():
|
||||
})
|
||||
|
||||
|
||||
def clean_old_torrents():
|
||||
expired_date = timezone.now() - timedelta(days=settings.TORRENT_TTL)
|
||||
torrent = Torrent.objects.filter(date_created__lt=expired_date).first()
|
||||
if torrent:
|
||||
torrent.delete()
|
||||
|
||||
|
||||
class Command(BaseCommand):
|
||||
task_schedule = {
|
||||
"update_transmission_data": {
|
||||
"func": update_transmission_data,
|
||||
"schedule": 5.0
|
||||
},
|
||||
"clean_old_torrents": {
|
||||
"func": clean_old_torrents,
|
||||
"schedule": 60.0
|
||||
}
|
||||
}
|
||||
histories = {}
|
||||
|
||||
@@ -69,7 +69,7 @@ class File(models.Model):
|
||||
def abs_pathname(self):
|
||||
return settings.DOWNLOAD_BASE_DIR / self.pathname
|
||||
|
||||
@property
|
||||
@cached_property
|
||||
def mime_types(self):
|
||||
mime = mimetypes.guess_type(self.pathname)
|
||||
if mime:
|
||||
@@ -79,11 +79,15 @@ class File(models.Model):
|
||||
|
||||
@property
|
||||
def is_stream_video(self):
|
||||
return self.pathname.stem in ["mp4", "flv", "webm"]
|
||||
video_extensions = ["mp4", "flv", "webm"]
|
||||
return self.pathname.suffix.lower() in video_extensions
|
||||
|
||||
@property
|
||||
def is_video(self):
|
||||
return self.pathname.stem in ["mp4", "flv", "webm", "avi", "mkv"]
|
||||
if self.mime_types.startswith("video/"):
|
||||
return True
|
||||
video_extensions = ['.mp4', '.flv', '.webm', '.avi', '.mkv', '.mov', '.wmv']
|
||||
return self.pathname.suffix.lower() in video_extensions
|
||||
|
||||
@property
|
||||
def accel_redirect(self):
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
from django.urls import reverse
|
||||
from django.utils.text import slugify
|
||||
|
||||
from rest_framework import serializers
|
||||
|
||||
@@ -21,6 +22,7 @@ class FileSerializer(serializers.ModelSerializer):
|
||||
is_stream_video = serializers.BooleanField(read_only=True)
|
||||
is_video = serializers.BooleanField(read_only=True)
|
||||
download_url = serializers.SerializerMethodField(read_only=True)
|
||||
flux_url = serializers.SerializerMethodField(read_only=True)
|
||||
|
||||
class Meta:
|
||||
model = File
|
||||
@@ -28,3 +30,6 @@ class FileSerializer(serializers.ModelSerializer):
|
||||
|
||||
def get_download_url(self, obj):
|
||||
return reverse("torrent:download_file", kwargs={"file_id": obj.id})
|
||||
|
||||
def get_flux_url(self, obj: File):
|
||||
return f'{reverse("torrent:flux_file", kwargs={"file_id": obj.id})}#{slugify(obj.filename)}'
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
from django.urls import path
|
||||
|
||||
from .views import HomeView, download_file, download_torrent, pping
|
||||
from .views import HomeView, download_file, download_torrent, pping, flux_file
|
||||
|
||||
app_name = "torrent"
|
||||
urlpatterns = [
|
||||
@@ -8,4 +8,5 @@ urlpatterns = [
|
||||
path("pping/", pping, name="pping"),
|
||||
path("download_file/<uuid:file_id>", download_file, name="download_file"),
|
||||
path("download_torrent/<str:torrent_id>", download_torrent, name="download_torrent"),
|
||||
path("flux_file/<uuid:file_id>", flux_file, name="flux_file"),
|
||||
]
|
||||
|
||||
@@ -15,7 +15,8 @@ from user.models import User
|
||||
class Transmission:
|
||||
trpc_args = [
|
||||
"id", "percentDone", "uploadRatio", "rateUpload", "rateDownload", "hashString", "status", "sizeWhenDone",
|
||||
"leftUntilDone", "name", "eta", "totalSize"
|
||||
"leftUntilDone", "name", "eta", "totalSize", "uploadedEver", "peersGettingFromUs", "peersSendingToUs",
|
||||
"tracker", "trackerStats", "activityDate"
|
||||
]
|
||||
|
||||
def __init__(self):
|
||||
@@ -36,12 +37,13 @@ class Transmission:
|
||||
|
||||
return {
|
||||
"progress": data.progress,
|
||||
"status_str": data.status,
|
||||
**data.fields
|
||||
}
|
||||
|
||||
def get_all_data(self, hash_strings=None):
|
||||
return {
|
||||
data.hashString: {"progress": data.progress, **data.fields}
|
||||
data.hashString: {"progress": data.progress, "status_str": data.status, **data.fields}
|
||||
for data in self.client.get_torrents(hash_strings, self.trpc_args)
|
||||
}
|
||||
|
||||
|
||||
@@ -62,6 +62,23 @@ async def download_file(request, file_id):
|
||||
|
||||
|
||||
async def flux_file(request, file_id):
|
||||
# todo : version non sécurisé, voir pour ajouter un contrôle IP (par ex)
|
||||
qs = File.objects.filter(pk=file_id)
|
||||
|
||||
try:
|
||||
file = await qs.aget()
|
||||
except File.DoesNotExist:
|
||||
raise Http404()
|
||||
else:
|
||||
response = HttpResponse()
|
||||
response["X-Accel-Redirect"] = file.accel_redirect
|
||||
response["X-Accel-Buffering"] = "no"
|
||||
response["Content-Type"] = file.mime_types
|
||||
response["Content-Disposition"] = file.disposition
|
||||
return response
|
||||
|
||||
|
||||
async def secured_flux_file(request, file_id):
|
||||
user = await request.auser()
|
||||
qs = File.objects.filter(
|
||||
Q(torrent__user=user)
|
||||
@@ -106,7 +123,7 @@ async def download_torrent(request, torrent_id):
|
||||
}))
|
||||
|
||||
response = StreamingZipFileResponse(
|
||||
filename="test.zip",
|
||||
filename=f"{torrent.name}.zip",
|
||||
file_list=[
|
||||
(file.abs_pathname, file.rel_name)
|
||||
async for file in torrent.files.all()
|
||||
|
||||
0
app/watch_party/__init__.py
Normal file
0
app/watch_party/__init__.py
Normal file
3
app/watch_party/admin.py
Normal file
3
app/watch_party/admin.py
Normal file
@@ -0,0 +1,3 @@
|
||||
from django.contrib import admin
|
||||
|
||||
# Register your models here.
|
||||
6
app/watch_party/apps.py
Normal file
6
app/watch_party/apps.py
Normal file
@@ -0,0 +1,6 @@
|
||||
from django.apps import AppConfig
|
||||
|
||||
|
||||
class WatchPartyConfig(AppConfig):
|
||||
default_auto_field = 'django.db.models.BigAutoField'
|
||||
name = 'watch_party'
|
||||
0
app/watch_party/migrations/__init__.py
Normal file
0
app/watch_party/migrations/__init__.py
Normal file
11
app/watch_party/models.py
Normal file
11
app/watch_party/models.py
Normal file
@@ -0,0 +1,11 @@
|
||||
import uuid
|
||||
|
||||
from django.db import models
|
||||
|
||||
|
||||
class Room(models.Model):
|
||||
id = models.UUIDField(primary_key=True, default=uuid.uuid4)
|
||||
date_created = models.DateTimeField(auto_now_add=True)
|
||||
created_by = models.ForeignKey("user.User", on_delete=models.CASCADE, related_name="rooms_created")
|
||||
users = models.ManyToManyField("user.User", related_name="rooms")
|
||||
all_admin = models.BooleanField(default=False)
|
||||
3
app/watch_party/tests.py
Normal file
3
app/watch_party/tests.py
Normal file
@@ -0,0 +1,3 @@
|
||||
from django.test import TestCase
|
||||
|
||||
# Create your tests here.
|
||||
3
app/watch_party/views.py
Normal file
3
app/watch_party/views.py
Normal file
@@ -0,0 +1,3 @@
|
||||
from django.shortcuts import render
|
||||
|
||||
# Create your views here.
|
||||
@@ -14,7 +14,7 @@ services:
|
||||
- "traefik.enable=true"
|
||||
- "traefik.docker.network=web"
|
||||
# Routeur HTTP (port 80) pour la redirection vers HTTPS
|
||||
- "traefik.http.routers.web-http.rule=Host(`${DOMAIN}`)"
|
||||
- "traefik.http.routers.web-http.rule=${TRAEFIK_HOST_RULE}"
|
||||
- "traefik.http.routers.web-http.entrypoints=web"
|
||||
- "traefik.http.routers.web-http.middlewares=redirect-to-https"
|
||||
|
||||
@@ -22,7 +22,7 @@ services:
|
||||
- "traefik.http.middlewares.redirect-to-https.redirectscheme.scheme=https"
|
||||
|
||||
# Routeur HTTPS
|
||||
- "traefik.http.routers.web.rule=Host(`${DOMAIN}`)"
|
||||
- "traefik.http.routers.web.rule=${TRAEFIK_HOST_RULE}"
|
||||
- "traefik.http.routers.web.entrypoints=websecure"
|
||||
- "traefik.http.routers.web.tls.certresolver=le"
|
||||
|
||||
@@ -44,8 +44,8 @@ services:
|
||||
- PUID=${USER_ID}
|
||||
- PGID=${GROUP_ID}
|
||||
ports:
|
||||
- "51414:51414"
|
||||
- "51414:51414/udp"
|
||||
- "51413:51413"
|
||||
- "51413:51413/udp"
|
||||
volumes:
|
||||
- ./transmission/config:/config
|
||||
- ./transmission/downloads:/downloads
|
||||
@@ -74,7 +74,7 @@ services:
|
||||
&& cd frontend && yarn build && cd ..
|
||||
&& python manage.py collectstatic --noinput
|
||||
&& python manage.py migrate
|
||||
&& uvicorn app.asgi:application --workers 3 --host 0.0.0.0 --port 8000 --lifespan off --loop uvloop --ws websockets"
|
||||
&& uvicorn app.asgi:application --workers 3 --host 0.0.0.0 --port 8000 --lifespan off --loop uvloop --ws websockets --log-level info"
|
||||
|
||||
# celery:
|
||||
# extends:
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
server {
|
||||
gzip off;
|
||||
client_max_body_size 100M;
|
||||
|
||||
location /dl/ {
|
||||
internal;
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
server {
|
||||
gzip off;
|
||||
client_max_body_size 100M;
|
||||
|
||||
location /dl/ {
|
||||
internal;
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
"bind-address-ipv6": "::",
|
||||
"blocklist-enabled": false,
|
||||
"blocklist-url": "http://www.example.com/blocklist",
|
||||
"cache-size-mb": 4,
|
||||
"cache-size-mb": 256,
|
||||
"default-trackers": "",
|
||||
"dht-enabled": true,
|
||||
"download-dir": "/downloads/complete",
|
||||
@@ -29,8 +29,8 @@
|
||||
"message-level": 2,
|
||||
"peer-congestion-algorithm": "",
|
||||
"peer-id-ttl-hours": 6,
|
||||
"peer-limit-global": 200,
|
||||
"peer-limit-per-torrent": 50,
|
||||
"peer-limit-global": 400,
|
||||
"peer-limit-per-torrent": 100,
|
||||
"peer-port": 51413,
|
||||
"peer-port-random-high": 65535,
|
||||
"peer-port-random-low": 49152,
|
||||
@@ -42,8 +42,8 @@
|
||||
"prefetch-enabled": true,
|
||||
"queue-stalled-enabled": true,
|
||||
"queue-stalled-minutes": 30,
|
||||
"ratio-limit": 2,
|
||||
"ratio-limit-enabled": false,
|
||||
"ratio-limit": 20,
|
||||
"ratio-limit-enabled": true,
|
||||
"rename-partial-files": true,
|
||||
"rpc-authentication-required": false,
|
||||
"rpc-bind-address": "0.0.0.0",
|
||||
@@ -73,10 +73,10 @@
|
||||
"start-added-torrents": true,
|
||||
"tcp-enabled": true,
|
||||
"torrent-added-verify-mode": "fast",
|
||||
"trash-original-torrent-files": false,
|
||||
"trash-original-torrent-files": true,
|
||||
"umask": "002",
|
||||
"upload-slots-per-torrent": 14,
|
||||
"utp-enabled": false,
|
||||
"upload-slots-per-torrent": 50,
|
||||
"utp-enabled": true,
|
||||
"watch-dir": "/watch",
|
||||
"watch-dir-enabled": true
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user