some improvement
This commit is contained in:
@@ -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"/>
|
||||
@@ -52,7 +53,17 @@ export default {
|
||||
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};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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):
|
||||
|
||||
@@ -21,6 +21,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 +29,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):
|
||||
return reverse("torrent:flux_file", kwargs={"file_id": obj.id})
|
||||
|
||||
@@ -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,7 @@ 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"
|
||||
]
|
||||
|
||||
def __init__(self):
|
||||
|
||||
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user