MCPcopy Create free account
hub / github.com/diffgram/diffgram / validate_file_data_for_input_packet

Function validate_file_data_for_input_packet

walrus/methods/input/packet.py:382–478  ·  view source on GitHub ↗

Determines if payload has valid file data. Validation here goes like this: We expect either - file_id, - [media_url and media_type] - [file_name and directory_id] If none of these are completed error is returned. :param input: :param project_s

(session, input, project_string_id, log)

Source from the content-addressed store, hash-verified

380
381
382def validate_file_data_for_input_packet(session, input, project_string_id, log):
383 """
384 Determines if payload has valid file data.
385 Validation here goes like this:
386 We expect either
387 - file_id,
388 - [media_url and media_type]
389 - [file_name and directory_id]
390 If none of these are completed error is returned.
391 :param input:
392 :param project_string_id:
393 :param log:
394 :return:
395 """
396 project = Project.get_by_string_id(session = session, project_string_id = project_string_id)
397 if input.get('type') == 'from_blob_path':
398 log = validate_input_from_blob_path(
399 project = project,
400 input = input,
401 session = session,
402 log = log
403 )
404 if regular_log.log_has_error(log):
405 return False, log, None
406 else:
407 return True, log, None
408 if input.get('type') == 'from_text_data':
409 log = validate_input_from_text_data(
410 input = input,
411 log = log
412 )
413 if regular_log.log_has_error(log):
414 return False, log, None
415 else:
416 return True, log, None
417 valid_id = False
418 valid_media_url = False
419 valid_file_name = False
420 if input.get('media'):
421 media_url = input['media'].get('url', None)
422 media_type = input['media'].get('type', None)
423 else:
424 media_url = None
425 media_type = None
426
427 file_id = None
428 if input.get('file_id') is None and input.get('type') != 'from_text_data':
429 # Validate Media URL Case
430 if media_url is None:
431 log['error'] = {}
432 log["error"]["media_url"] = "url in media dict not supplied"
433 else:
434 if media_type is None:
435 valid_media_url = False
436 log['error'] = {}
437 log["error"]["media_type"] = "type in media dict not supplied ['image', 'video']"
438 else:
439 valid_media_url = True

Callers 1

input_packetFunction · 0.85

Calls 5

get_by_string_idMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected