some improvement

This commit is contained in:
2025-05-03 01:22:03 +02:00
parent 42332ac329
commit 26d4613dd1
9 changed files with 80 additions and 28 deletions

View File

@@ -7,6 +7,7 @@
> >
<template v-slot:prepend> <template v-slot:prepend>
<v-btn @click.stop="downloadClicked" :disabled="!is_download_finished" icon="mdi-download" color="green" variant="text"/> <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%"> <v-dialog v-if="file.is_stream_video" v-model="video_modal" width="75%" height="100%">
<template v-slot:activator="{ props }"> <template v-slot:activator="{ props }">
<v-btn v-bind="props" icon="mdi-play" variant="text"/> <v-btn v-bind="props" icon="mdi-play" variant="text"/>
@@ -52,7 +53,17 @@ export default {
a.setAttribute("download", "download"); a.setAttribute("download", "download");
a.click(); 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);
});
} }
} }
} }

View File

@@ -8,19 +8,32 @@
<!-- indeterminate--> <!-- indeterminate-->
<!-- :color="torrent.transmission_data.progress < 100 ? 'green':'red'"--> <!-- :color="torrent.transmission_data.progress < 100 ? 'green':'red'"-->
<!-- />--> <!-- />-->
<v-icon
v-if="torrent.transmission_data.rateDownload && torrent.transmission_data.rateUpload" <!-- Si téléchargement en cours-->
:color="torrent.transmission_data.rateDownload ? 'green':'red'" <v-chip variant="text" color="white" v-if="progressData.mode === 'download'">
:icon="torrent.transmission_data.rateDownload ? 'mdi-arrow-down-bold':'mdi-arrow-up-bold'" <v-icon
/> v-if="torrent.transmission_data.rateDownload"
<strong style="padding-left: 5px"> color="green"
icon="mdi-arrow-down-bold"
/>
{{progressData.value}}% {{progressData.value}}%
<strong <strong style="padding-left: 5px" v-if="torrent.transmission_data.rateDownload">
v-if="torrent.transmission_data.rateDownload || torrent.transmission_data.rateUpload" ({{fs_speed_format(torrent.transmission_data.rateDownload)}}/s)
>
({{torrent.transmission_data.rateDownload ? fs_speed_format(torrent.transmission_data.rateDownload):fs_speed_format(torrent.transmission_data.rateUpload)}}/s)
</strong> </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-progress-linear>
<v-row no-gutters> <v-row no-gutters>
<!-- ligne du haut --> <!-- ligne du haut -->
@@ -115,9 +128,10 @@ export default {
}, },
computed: { computed: {
progressData(){ progressData(){
let color = "red", value = 0, eta; let color = "red", value = 0, mode, eta;
if(this.torrent.transmission_data.progress < 100){ if(this.torrent.transmission_data.progress < 100){
color = "blue"; color = "blue";
mode = "download";
value = this.torrent.transmission_data.progress; value = this.torrent.transmission_data.progress;
if(this.torrent.transmission_data.eta !== -1){ if(this.torrent.transmission_data.eta !== -1){
eta = toHHMMSS(this.torrent.transmission_data.eta); eta = toHHMMSS(this.torrent.transmission_data.eta);
@@ -126,10 +140,11 @@ export default {
} }
}else{ }else{
color = "green"; color = "green";
mode = "upload";
value = Number((this.torrent.transmission_data.uploadRatio / 5) * 100).toFixed(2) value = Number((this.torrent.transmission_data.uploadRatio / 5) * 100).toFixed(2)
if(value > 100) value = 100; if(value > 100) value = 100;
} }
return {color, value, eta}; return {color, value, mode, eta};
} }
} }
} }

View File

@@ -69,7 +69,7 @@ class File(models.Model):
def abs_pathname(self): def abs_pathname(self):
return settings.DOWNLOAD_BASE_DIR / self.pathname return settings.DOWNLOAD_BASE_DIR / self.pathname
@property @cached_property
def mime_types(self): def mime_types(self):
mime = mimetypes.guess_type(self.pathname) mime = mimetypes.guess_type(self.pathname)
if mime: if mime:
@@ -79,11 +79,15 @@ class File(models.Model):
@property @property
def is_stream_video(self): 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 @property
def is_video(self): 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 @property
def accel_redirect(self): def accel_redirect(self):

View File

@@ -21,6 +21,7 @@ class FileSerializer(serializers.ModelSerializer):
is_stream_video = serializers.BooleanField(read_only=True) is_stream_video = serializers.BooleanField(read_only=True)
is_video = serializers.BooleanField(read_only=True) is_video = serializers.BooleanField(read_only=True)
download_url = serializers.SerializerMethodField(read_only=True) download_url = serializers.SerializerMethodField(read_only=True)
flux_url = serializers.SerializerMethodField(read_only=True)
class Meta: class Meta:
model = File model = File
@@ -28,3 +29,6 @@ class FileSerializer(serializers.ModelSerializer):
def get_download_url(self, obj): def get_download_url(self, obj):
return reverse("torrent:download_file", kwargs={"file_id": obj.id}) return reverse("torrent:download_file", kwargs={"file_id": obj.id})
def get_flux_url(self, obj):
return reverse("torrent:flux_file", kwargs={"file_id": obj.id})

View File

@@ -1,6 +1,6 @@
from django.urls import path 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" app_name = "torrent"
urlpatterns = [ urlpatterns = [
@@ -8,4 +8,5 @@ urlpatterns = [
path("pping/", pping, name="pping"), path("pping/", pping, name="pping"),
path("download_file/<uuid:file_id>", download_file, name="download_file"), path("download_file/<uuid:file_id>", download_file, name="download_file"),
path("download_torrent/<str:torrent_id>", download_torrent, name="download_torrent"), path("download_torrent/<str:torrent_id>", download_torrent, name="download_torrent"),
path("flux_file/<uuid:file_id>", flux_file, name="flux_file"),
] ]

View File

@@ -15,7 +15,7 @@ from user.models import User
class Transmission: class Transmission:
trpc_args = [ trpc_args = [
"id", "percentDone", "uploadRatio", "rateUpload", "rateDownload", "hashString", "status", "sizeWhenDone", "id", "percentDone", "uploadRatio", "rateUpload", "rateDownload", "hashString", "status", "sizeWhenDone",
"leftUntilDone", "name", "eta", "totalSize" "leftUntilDone", "name", "eta", "totalSize", "uploadedEver"
] ]
def __init__(self): def __init__(self):

View File

@@ -62,6 +62,23 @@ async def download_file(request, file_id):
async def flux_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() user = await request.auser()
qs = File.objects.filter( qs = File.objects.filter(
Q(torrent__user=user) Q(torrent__user=user)
@@ -106,7 +123,7 @@ async def download_torrent(request, torrent_id):
})) }))
response = StreamingZipFileResponse( response = StreamingZipFileResponse(
filename="test.zip", filename=f"{torrent.name}.zip",
file_list=[ file_list=[
(file.abs_pathname, file.rel_name) (file.abs_pathname, file.rel_name)
async for file in torrent.files.all() async for file in torrent.files.all()

View File

@@ -44,8 +44,8 @@ services:
- PUID=${USER_ID} - PUID=${USER_ID}
- PGID=${GROUP_ID} - PGID=${GROUP_ID}
ports: ports:
- "51414:51414" - "51413:51413"
- "51414:51414/udp" - "51413:51413/udp"
volumes: volumes:
- ./transmission/config:/config - ./transmission/config:/config
- ./transmission/downloads:/downloads - ./transmission/downloads:/downloads

View File

@@ -14,7 +14,7 @@
"bind-address-ipv6": "::", "bind-address-ipv6": "::",
"blocklist-enabled": false, "blocklist-enabled": false,
"blocklist-url": "http://www.example.com/blocklist", "blocklist-url": "http://www.example.com/blocklist",
"cache-size-mb": 4, "cache-size-mb": 256,
"default-trackers": "", "default-trackers": "",
"dht-enabled": true, "dht-enabled": true,
"download-dir": "/downloads/complete", "download-dir": "/downloads/complete",
@@ -42,8 +42,8 @@
"prefetch-enabled": true, "prefetch-enabled": true,
"queue-stalled-enabled": true, "queue-stalled-enabled": true,
"queue-stalled-minutes": 30, "queue-stalled-minutes": 30,
"ratio-limit": 2, "ratio-limit": 20,
"ratio-limit-enabled": false, "ratio-limit-enabled": true,
"rename-partial-files": true, "rename-partial-files": true,
"rpc-authentication-required": false, "rpc-authentication-required": false,
"rpc-bind-address": "0.0.0.0", "rpc-bind-address": "0.0.0.0",
@@ -73,10 +73,10 @@
"start-added-torrents": true, "start-added-torrents": true,
"tcp-enabled": true, "tcp-enabled": true,
"torrent-added-verify-mode": "fast", "torrent-added-verify-mode": "fast",
"trash-original-torrent-files": false, "trash-original-torrent-files": true,
"umask": "002", "umask": "002",
"upload-slots-per-torrent": 14, "upload-slots-per-torrent": 100,
"utp-enabled": false, "utp-enabled": true,
"watch-dir": "/watch", "watch-dir": "/watch",
"watch-dir-enabled": true "watch-dir-enabled": true
} }