mirror of
https://github.com/Ultimaker/Cura.git
synced 2025-07-06 22:47:29 -06:00
Provide source_file_id
with print file
Had to implement this a bit differently as stated in the ticket. This field is returned when uploading the project file. Logic needed a bit of a change as the new behavior dictates a sequence (we can only upload the print file after the project file is uploaded, and we know the correct `file_id`/`source_file_id`) where before these two api calls were done in parallel. CURA-8555
This commit is contained in:
parent
f67d086182
commit
854607a725
2 changed files with 19 additions and 4 deletions
|
@ -48,6 +48,7 @@ class DFFileExportAndUploadManager:
|
||||||
self._upload_jobs: List[ExportFileJob] = []
|
self._upload_jobs: List[ExportFileJob] = []
|
||||||
self._formats: List[str] = formats
|
self._formats: List[str] = formats
|
||||||
self._api = DigitalFactoryApiClient(application = CuraApplication.getInstance(), on_error = lambda error: Logger.log("e", str(error)))
|
self._api = DigitalFactoryApiClient(application = CuraApplication.getInstance(), on_error = lambda error: Logger.log("e", str(error)))
|
||||||
|
self._source_file_id: Optional[str] = None
|
||||||
|
|
||||||
# Functions of the parent class that should be called based on the upload process output
|
# Functions of the parent class that should be called based on the upload process output
|
||||||
self._on_upload_error = on_upload_error
|
self._on_upload_error = on_upload_error
|
||||||
|
@ -113,7 +114,8 @@ class DFFileExportAndUploadManager:
|
||||||
content_type = job.getMimeType(),
|
content_type = job.getMimeType(),
|
||||||
job_name = job.getFileName(),
|
job_name = job.getFileName(),
|
||||||
file_size = len(job.getOutput()),
|
file_size = len(job.getOutput()),
|
||||||
library_project_id = self._library_project_id
|
library_project_id = self._library_project_id,
|
||||||
|
source_file_id = self._source_file_id
|
||||||
)
|
)
|
||||||
self._api.requestUploadUFP(request, on_finished = self._uploadFileData, on_error = self._onRequestUploadPrintFileFailed)
|
self._api.requestUploadUFP(request, on_finished = self._uploadFileData, on_error = self._onRequestUploadPrintFileFailed)
|
||||||
|
|
||||||
|
@ -125,6 +127,9 @@ class DFFileExportAndUploadManager:
|
||||||
"""
|
"""
|
||||||
if isinstance(file_upload_response, DFLibraryFileUploadResponse):
|
if isinstance(file_upload_response, DFLibraryFileUploadResponse):
|
||||||
file_name = file_upload_response.file_name
|
file_name = file_upload_response.file_name
|
||||||
|
|
||||||
|
# store the `file_id` so it can be as `source_file_id` when uploading the print file
|
||||||
|
self._source_file_id = file_upload_response.file_id
|
||||||
elif isinstance(file_upload_response, DFPrintJobUploadResponse):
|
elif isinstance(file_upload_response, DFPrintJobUploadResponse):
|
||||||
file_name = file_upload_response.job_name if file_upload_response.job_name is not None else ""
|
file_name = file_upload_response.job_name if file_upload_response.job_name is not None else ""
|
||||||
else:
|
else:
|
||||||
|
@ -145,6 +150,8 @@ class DFFileExportAndUploadManager:
|
||||||
on_progress = self._onUploadProgress,
|
on_progress = self._onUploadProgress,
|
||||||
on_error = self._onUploadError)
|
on_error = self._onUploadError)
|
||||||
|
|
||||||
|
self._handleNextUploadJob()
|
||||||
|
|
||||||
def _onUploadProgress(self, filename: str, progress: int) -> None:
|
def _onUploadProgress(self, filename: str, progress: int) -> None:
|
||||||
"""
|
"""
|
||||||
Updates the progress message according to the total progress of the two files and displays it to the user. It is
|
Updates the progress message according to the total progress of the two files and displays it to the user. It is
|
||||||
|
@ -325,8 +332,13 @@ class DFFileExportAndUploadManager:
|
||||||
message.hide()
|
message.hide()
|
||||||
|
|
||||||
def start(self) -> None:
|
def start(self) -> None:
|
||||||
for job in self._upload_jobs:
|
self._handleNextUploadJob()
|
||||||
job.start()
|
|
||||||
|
def _handleNextUploadJob(self):
|
||||||
|
match self._upload_jobs:
|
||||||
|
case [job, *jobs]:
|
||||||
|
job.start()
|
||||||
|
self._upload_jobs = jobs
|
||||||
|
|
||||||
def initializeFileUploadJobMetadata(self) -> Dict[str, Any]:
|
def initializeFileUploadJobMetadata(self) -> Dict[str, Any]:
|
||||||
metadata = {}
|
metadata = {}
|
||||||
|
|
|
@ -1,12 +1,14 @@
|
||||||
# Copyright (c) 2021 Ultimaker B.V.
|
# Copyright (c) 2021 Ultimaker B.V.
|
||||||
# Cura is released under the terms of the LGPLv3 or higher.
|
# Cura is released under the terms of the LGPLv3 or higher.
|
||||||
|
from typing import Optional
|
||||||
|
|
||||||
from .BaseModel import BaseModel
|
from .BaseModel import BaseModel
|
||||||
|
|
||||||
|
|
||||||
# Model that represents the request to upload a print job to the cloud
|
# Model that represents the request to upload a print job to the cloud
|
||||||
class DFPrintJobUploadRequest(BaseModel):
|
class DFPrintJobUploadRequest(BaseModel):
|
||||||
|
|
||||||
def __init__(self, job_name: str, file_size: int, content_type: str, library_project_id: str, **kwargs) -> None:
|
def __init__(self, job_name: str, file_size: int, content_type: str, library_project_id: str, source_file_id: str, **kwargs) -> None:
|
||||||
"""Creates a new print job upload request.
|
"""Creates a new print job upload request.
|
||||||
|
|
||||||
:param job_name: The name of the print job.
|
:param job_name: The name of the print job.
|
||||||
|
@ -18,4 +20,5 @@ class DFPrintJobUploadRequest(BaseModel):
|
||||||
self.file_size = file_size
|
self.file_size = file_size
|
||||||
self.content_type = content_type
|
self.content_type = content_type
|
||||||
self.library_project_id = library_project_id
|
self.library_project_id = library_project_id
|
||||||
|
self.source_file_id = source_file_id
|
||||||
super().__init__(**kwargs)
|
super().__init__(**kwargs)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue