MCPcopy
hub / github.com/diffgram/diffgram / admin_set_logo_core

Function admin_set_logo_core

default/methods/configs/set_logo.py:30–57  ·  view source on GitHub ↗
(session, file_binary, log = regular_log.default())

Source from the content-addressed store, hash-verified

28
29 return jsonify(sytem_configs = system_configs)
30def admin_set_logo_core(session, file_binary, log = regular_log.default()):
31 # Upload to temp dir
32 temp_dir = tempfile.gettempdir()
33 extension = file_binary.filename.split('.')[len(file_binary.filename.split('.')) - 1]
34 allowed_formats = ['jpg', 'png', 'webp', 'jpeg']
35 if extension.lower() not in allowed_formats:
36 log['error']['image'] = f'Invalid image format only support {allowed_formats}.'
37 return None, log
38 file_path = f"{temp_dir}/{uuid.uuid4()}.{extension}"
39 file_binary.save(file_path)
40 blob_path = f'{settings.SYSTEM_DATA_BASE_DIR}{file_binary.filename}'
41 # Upload to Cloud Storage
42
43 content_type = mimetypes.guess_type(file_binary.filename)
44 print('FILE PATH', file_path, content_type)
45 data_tools.upload_to_cloud_storage(
46 temp_local_path = file_path,
47 blob_path = blob_path,
48 content_type = content_type[0]
49 )
50 # Save new image Object
51 new_image = Image(original_filename = file_binary.filename, url_signed_blob_path = blob_path)
52 session.add(new_image)
53 session.flush()
54 # Save System Config
55 config = SystemConfigs.set_logo(session = session, image_id = new_image.id)
56 config_data = config.serialize(session = session)
57 return config_data, log

Callers 1

api_admin_set_logoFunction · 0.85

Calls 7

ImageClass · 0.90
splitMethod · 0.80
set_logoMethod · 0.80
saveMethod · 0.45
addMethod · 0.45
serializeMethod · 0.45

Tested by

no test coverage detected