mirror of
https://github.com/blw1138/Zordon.git
synced 2025-12-17 16:58:12 +00:00
See progress of uploads in client
This commit is contained in:
@@ -3,6 +3,7 @@ import os
|
||||
import json
|
||||
import requests
|
||||
from lib.render_workers.base_worker import RenderStatus
|
||||
from requests_toolbelt.multipart import MultipartEncoder, MultipartEncoderMonitor
|
||||
|
||||
status_colors = {RenderStatus.ERROR: "red", RenderStatus.CANCELLED: 'orange1', RenderStatus.COMPLETED: 'green',
|
||||
RenderStatus.NOT_STARTED: "yellow", RenderStatus.SCHEDULED: 'purple',
|
||||
@@ -69,10 +70,21 @@ class RenderServerProxy:
|
||||
all_data = self.request_data('full_status', timeout=timeout)
|
||||
return all_data
|
||||
|
||||
def post_job_to_server(self, input_path, job_list):
|
||||
# Pack job data and submit to server
|
||||
job_files = {'file': (os.path.basename(input_path), open(input_path, 'rb'), 'application/octet-stream'),
|
||||
'json': (None, json.dumps(job_list), 'application/json')}
|
||||
def post_job_to_server(self, input_path, job_list, callback=None):
|
||||
# Prepare the form data
|
||||
encoder = MultipartEncoder({
|
||||
'file': (os.path.basename(input_path), open(input_path, 'rb'), 'application/octet-stream'),
|
||||
'json': (None, json.dumps(job_list), 'application/json'),
|
||||
})
|
||||
|
||||
req = requests.post(f'http://{self.hostname}:{self.port}/api/add_job', files=job_files)
|
||||
return req
|
||||
# Create a monitor that will track the upload progress
|
||||
if callback:
|
||||
monitor = MultipartEncoderMonitor(encoder, callback(encoder))
|
||||
else:
|
||||
monitor = MultipartEncoderMonitor(encoder)
|
||||
|
||||
# Send the request
|
||||
headers = {'Content-Type': monitor.content_type}
|
||||
response = requests.post(f'http://{self.hostname}:{self.port}/api/add_job', data=monitor, headers=headers)
|
||||
|
||||
return response
|
||||
|
||||
Reference in New Issue
Block a user