Merge pull request #1499 from pierotofy/upcheck

Add file size check on upload
pull/1502/head
Piero Toffanin 2024-05-08 11:56:56 -04:00 zatwierdzone przez GitHub
commit dd6b46a2c9
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: B5690EEEBB952194
3 zmienionych plików z 7 dodań i 3 usunięć

Wyświetl plik

@ -208,14 +208,14 @@ class TaskViewSet(viewsets.ViewSet):
if len(files) == 0:
raise exceptions.ValidationError(detail=_("No files uploaded"))
task.handle_images_upload(files)
uploaded = task.handle_images_upload(files)
task.images_count = len(task.scan_images())
# Update other parameters such as processing node, task name, etc.
serializer = TaskSerializer(task, data=request.data, partial=True)
serializer.is_valid(raise_exception=True)
serializer.save()
return Response({'success': True}, status=status.HTTP_200_OK)
return Response({'success': True, 'uploaded': uploaded}, status=status.HTTP_200_OK)
@action(detail=True, methods=['post'])
def duplicate(self, request, pk=None, project_pk=None):

Wyświetl plik

@ -1163,6 +1163,7 @@ class Task(models.Model):
return path_traversal_check(p, self.task_path())
def handle_images_upload(self, files):
uploaded = {}
for file in files:
name = file.name
if name is None:
@ -1181,6 +1182,9 @@ class Task(models.Model):
else:
with open(file.temporary_file_path(), 'rb') as f:
shutil.copyfileobj(f, fd)
uploaded[name] = os.path.getsize(dst_path)
return uploaded
def update_size(self, commit=False):
try:

Wyświetl plik

@ -231,7 +231,7 @@ class ProjectListItem extends React.Component {
}else{
// Check response
let response = JSON.parse(file.xhr.response);
if (response.success){
if (response.success && response.uploaded && response.uploaded[file.name] === file.size){
// Update progress by removing the tracked progress and
// use the file size as the true number of bytes
let totalBytesSent = this.state.upload.totalBytesSent + file.size;