pull/1496/head
Piero Toffanin 2024-05-08 12:13:21 -04:00
commit d46b582dcd
3 zmienionych plików z 8 dodań i 5 usunięć

Wyświetl plik

@ -207,14 +207,14 @@ class TaskViewSet(viewsets.ViewSet):
if len(files) == 0: if len(files) == 0:
raise exceptions.ValidationError(detail=_("No files uploaded")) 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()) task.images_count = len(task.scan_images())
# Update other parameters such as processing node, task name, etc. # Update other parameters such as processing node, task name, etc.
serializer = TaskSerializer(task, data=request.data, partial=True) serializer = TaskSerializer(task, data=request.data, partial=True)
serializer.is_valid(raise_exception=True) serializer.is_valid(raise_exception=True)
serializer.save() 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']) @action(detail=True, methods=['post'])
def duplicate(self, request, pk=None, project_pk=None): 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()) return path_traversal_check(p, self.task_path())
def handle_images_upload(self, files): def handle_images_upload(self, files):
uploaded = {}
for file in files: for file in files:
name = file.name name = file.name
if name is None: if name is None:
@ -1182,6 +1183,9 @@ class Task(models.Model):
with open(file.temporary_file_path(), 'rb') as f: with open(file.temporary_file_path(), 'rb') as f:
shutil.copyfileobj(f, fd) shutil.copyfileobj(f, fd)
uploaded[name] = os.path.getsize(dst_path)
return uploaded
def update_size(self, commit=False): def update_size(self, commit=False):
try: try:
total_bytes = 0 total_bytes = 0

Wyświetl plik

@ -193,7 +193,7 @@ class ProjectListItem extends React.Component {
.on("complete", (file) => { .on("complete", (file) => {
// Retry // Retry
const retry = () => { const retry = () => {
const MAX_RETRIES = 10; const MAX_RETRIES = 20;
if (file.retries < MAX_RETRIES){ if (file.retries < MAX_RETRIES){
// Update progress // Update progress
@ -231,7 +231,7 @@ class ProjectListItem extends React.Component {
}else{ }else{
// Check response // Check response
let response = JSON.parse(file.xhr.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 // Update progress by removing the tracked progress and
// use the file size as the true number of bytes // use the file size as the true number of bytes
let totalBytesSent = this.state.upload.totalBytesSent + file.size; let totalBytesSent = this.state.upload.totalBytesSent + file.size;
@ -284,7 +284,6 @@ class ProjectListItem extends React.Component {
}else if (this.dz.getQueuedFiles() === 0){ }else if (this.dz.getQueuedFiles() === 0){
// Done but didn't upload all? // Done but didn't upload all?
this.setUploadState({ this.setUploadState({
totalCount: this.state.upload.totalCount - remainingFilesCount,
uploading: false, uploading: false,
error: interpolate(_('%(count)s files cannot be uploaded. As a reminder, only images (.jpg, .tif, .png) and GCP files (.txt) can be uploaded. Try again.'), { count: remainingFilesCount }) error: interpolate(_('%(count)s files cannot be uploaded. As a reminder, only images (.jpg, .tif, .png) and GCP files (.txt) can be uploaded. Try again.'), { count: remainingFilesCount })
}); });