MCPcopy
hub / github.com/diffgram/diffgram / append_to_batch_core

Function append_to_batch_core

default/methods/batch/append_to_batch.py:81–166  ·  view source on GitHub ↗
(session, log, batch_id, member, project, request)

Source from the content-addressed store, hash-verified

79
80
81def append_to_batch_core(session, log, batch_id, member, project, request):
82 result = None
83 batch = InputBatch.get_by_id(session = session, id = batch_id)
84
85 if batch.project_id != project.id:
86 log['error']['batch_id'] = "Batch is not from the provided project."
87 return False, log
88
89 binary_file = request.files.get('file')
90 if not binary_file:
91 log['error']['binary_file'] = "No file provided"
92 return False, log
93
94 file = request.files['file']
95 # secure_filename makes sure the filename isn't unsafe to save
96 content_range = request.headers.get('Content-Range')
97 content_range_index = int(request.headers.get('Content-Range-Index'))
98 total_chunks = int(request.headers.get('Content-Range-Total-Chunks'))
99 if content_range.startswith('bytes'):
100 new_range = content_range.replace('bytes ', '')
101 chunks = new_range.split('/')[0]
102 size = int(new_range.split('/')[1])
103 chunk_start = int(new_range.split('-')[0])
104 chunk_end = int(chunks.split('-')[1])
105 temp_dir_path = f'/tmp/batches/{batch.id}_batch_payload.json'
106 if chunk_start == 0:
107 session.add(batch)
108 url = data_tools.create_resumable_upload_session(
109 blob_path = temp_dir_path,
110 content_type = 'application/json',
111 input = None,
112 batch = batch
113 )
114 batch.data_temp_dir = url
115 session.add(batch)
116 stream = file.stream.read()
117 content_size = len(stream)
118
119 response = data_tools.transmit_chunk_of_resumable_upload(
120 stream = stream,
121 blob_path = temp_dir_path,
122 content_type = 'application/json',
123 prior_created_url = batch.data_temp_dir,
124 content_start = chunk_start,
125 content_size = content_size,
126 total_size = size,
127 total_parts_count = total_chunks,
128 chunk_index = content_range_index,
129 input = None,
130 batch = batch,
131 )
132 else:
133 stream = file.stream.read()
134 content_size = len(stream)
135
136 response = data_tools.transmit_chunk_of_resumable_upload(
137 stream = stream,
138 blob_path = temp_dir_path,

Callers 1

append_to_batch_apiFunction · 0.85

Calls 10

replaceMethod · 0.80
splitMethod · 0.80
commitMethod · 0.80
get_by_idMethod · 0.45
getMethod · 0.45
addMethod · 0.45
startMethod · 0.45

Tested by

no test coverage detected