mirror of
https://github.com/Alexander-D-Karpov/akarpov
synced 2024-11-29 00:53:42 +03:00
added trash files, preview dependencies for docker
This commit is contained in:
parent
d29860397a
commit
ff272f868e
21
akarpov/files/migrations/0014_alter_fileintrash_file.py
Normal file
21
akarpov/files/migrations/0014_alter_fileintrash_file.py
Normal file
|
@ -0,0 +1,21 @@
|
|||
# Generated by Django 4.2 on 2023-04-11 10:55
|
||||
|
||||
import akarpov.files.services.files
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
("files", "0013_alter_file_options"),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name="fileintrash",
|
||||
name="file",
|
||||
field=models.FileField(
|
||||
upload_to=akarpov.files.services.files.trash_file_upload
|
||||
),
|
||||
),
|
||||
]
|
18
akarpov/files/migrations/0015_fileintrash_name.py
Normal file
18
akarpov/files/migrations/0015_fileintrash_name.py
Normal file
|
@ -0,0 +1,18 @@
|
|||
# Generated by Django 4.2 on 2023-04-11 11:20
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
("files", "0014_alter_fileintrash_file"),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name="fileintrash",
|
||||
name="name",
|
||||
field=models.CharField(blank=True, max_length=200),
|
||||
),
|
||||
]
|
|
@ -13,7 +13,7 @@
|
|||
from django.urls import reverse
|
||||
from model_utils.models import TimeStampedModel
|
||||
|
||||
from akarpov.files.services.files import user_unique_file_upload
|
||||
from akarpov.files.services.files import trash_file_upload, user_unique_file_upload
|
||||
from akarpov.tools.shortener.models import ShortLink
|
||||
|
||||
|
||||
|
@ -62,8 +62,9 @@ class Meta:
|
|||
|
||||
|
||||
class FileInTrash(TimeStampedModel):
|
||||
name = CharField(max_length=200, blank=True)
|
||||
user = ForeignKey("users.User", related_name="trash_files", on_delete=CASCADE)
|
||||
file = FileField(blank=False, upload_to="file/trash/")
|
||||
file = FileField(blank=False, upload_to=trash_file_upload)
|
||||
|
||||
|
||||
class Folder(TimeStampedModel, ShortLink):
|
||||
|
|
|
@ -14,3 +14,9 @@ def user_unique_file_upload(instance, filename):
|
|||
slug = generate_charset(5)
|
||||
|
||||
return os.path.join(f"files/{username}/{slug}", filename)
|
||||
|
||||
|
||||
def trash_file_upload(instance, filename):
|
||||
"""stores user trash files"""
|
||||
username = instance.user.username
|
||||
return os.path.join(f"file/trash/{username}", filename)
|
||||
|
|
|
@ -1,12 +1,16 @@
|
|||
from django.db.models.signals import post_save
|
||||
import os
|
||||
|
||||
from django.core.files.base import File
|
||||
from django.db.models.signals import post_delete, post_save
|
||||
from django.dispatch import receiver
|
||||
|
||||
from akarpov.files.models import File
|
||||
from akarpov.files.models import File as FileModel
|
||||
from akarpov.files.models import FileInTrash
|
||||
from akarpov.files.tasks import process_file
|
||||
|
||||
|
||||
@receiver(post_save, sender=File)
|
||||
def post_on_create(sender, instance: File, created, **kwargs):
|
||||
@receiver(post_save, sender=FileModel)
|
||||
def post_on_create(sender, instance: FileModel, created, **kwargs):
|
||||
if created:
|
||||
process_file.apply_async(
|
||||
kwargs={
|
||||
|
@ -14,3 +18,18 @@ def post_on_create(sender, instance: File, created, **kwargs):
|
|||
},
|
||||
countdown=2,
|
||||
)
|
||||
|
||||
|
||||
@receiver(post_delete, sender=FileModel)
|
||||
def move_file_to_trash(sender, instance, **kwargs):
|
||||
if instance.file:
|
||||
name = instance.file.name.split("/")[-1]
|
||||
trash = FileInTrash(user=instance.user, name=name)
|
||||
trash.file = File(instance.file, name=name)
|
||||
trash.save()
|
||||
path = instance.file.path
|
||||
file_dir = "/".join(path.split("/")[:-1]) + "/"
|
||||
if os.path.isfile(path):
|
||||
os.remove(path)
|
||||
if os.path.isdir(file_dir) and len(os.listdir(file_dir)) == 0:
|
||||
os.rmdir(file_dir)
|
||||
|
|
|
@ -152,11 +152,8 @@
|
|||
dataType: "json",
|
||||
maxChunkSize: 1000000, // Chunks of 1000 kB
|
||||
formData: form_data,
|
||||
prependFiles: true,
|
||||
dropZone: body,
|
||||
pasteZone: body,
|
||||
sequentialUploads: true,
|
||||
autoUpload: false,
|
||||
add: function(e, data) { // Called before starting upload
|
||||
if (cur !== true){
|
||||
cur = true
|
||||
|
|
|
@ -27,7 +27,6 @@ RUN apt-get update && \
|
|||
apt-get install -y build-essential libpq-dev gettext libmagic-dev libjpeg-dev zlib1g-dev && \
|
||||
# Dependencies for file preview generation
|
||||
apt-get install -y webp libimage-exiftool-perl libmagickwand-dev ffmpeg && \
|
||||
# apt-get install -y poppler-utils libfile-mimeinfo-perl ghostscript libsecret-1-0 zlib1g-dev libjpeg-dev imagemagick libmagic1 libreoffice inkscape xvfb && \
|
||||
apt-get purge -y --auto-remove -o APT:AutoRemove:RecommendsImportant=false && \
|
||||
rm -rf /var/lib/apt/lists/*
|
||||
|
||||
|
@ -51,6 +50,9 @@ COPY ./compose/local/django/start /start
|
|||
RUN sed -i 's/\r$//g' /start
|
||||
RUN chmod +x /start
|
||||
|
||||
COPY ./compose/local/django/install_preview_dependencies /install_preview_dependencies
|
||||
RUN sed -i 's/\r$//g' /install_preview_dependencies
|
||||
RUN chmod +x /install_preview_dependencies
|
||||
|
||||
COPY ./compose/local/django/celery/worker/start /start-celeryworker
|
||||
RUN sed -i 's/\r$//g' /start-celeryworker
|
||||
|
|
10
compose/local/django/install_preview_dependencies
Normal file
10
compose/local/django/install_preview_dependencies
Normal file
|
@ -0,0 +1,10 @@
|
|||
#!/bin/bash
|
||||
|
||||
apt-get update
|
||||
apt-get install -y poppler-utils libfile-mimeinfo-perl ghostscript libsecret-1-0 zlib1g-dev libjpeg-dev imagemagick libmagic1 libreoffice inkscape xvfb
|
||||
wget https://github.com/jgraph/drawio-desktop/releases/download/v13.0.3/draw.io-amd64-13.0.3.deb
|
||||
dpkg -i draw.io-amd64-13.0.3.deb
|
||||
rm draw.io-amd64-13.0.3.deb
|
||||
apt-get purge -y --auto-remove -o APT:AutoRemove:RecommendsImportant=false && \
|
||||
rm -rf /var/lib/apt/lists/*
|
||||
preview --check-dependencies``
|
Loading…
Reference in New Issue
Block a user