def upload_file(user): logger.debug(f"[upload_file]: parsing payload") files = _get_parts() usage.track("Upload") if files is None or len(files) == 0: return {'code': 'error', 'message': 'No Schema Provided'}, 400 logger.debug(f"[upload_file]: received {len(files)} files") # Currently restricted to one file file = files[0] filename = file.get('filename') # Save the file logger.info(f"[upload_file]: Uploading {filename}") manager.save_data(user, filename, file.get("content")) # Return the column names, and first 5 rows data = manager.parse_data(user, filename) # Trigger webhook util.trigger_hook(user, util.Lifecycle.FILE_UPLOADED) return corsify({'code': 'success', 'data': data, 'filename': filename})
def do_import(user): body = request.json filename = body.get("filename") usage.track("Import") # Do the import manager.do_import(user, filename) # Trigger webhook util.trigger_hook(user, util.Lifecycle.DATA_EXPORTED) return corsify({'code': 'sucess'})
def validate_mapping(user): body = request.json filename = body.get("filename") mapping = body.get("mapping") schema = body.get("schema") usage.track("Validate") if mapping is None: return corsify({'code': 'error', 'message': 'No mapping Provided'}), 400 logger.debug(f"[validate_mapping]: Received mapping={json.dumps(mapping)}") # Validate the mapping data = manager.validate_mapping(user, filename, mapping, schema) # Trigger webhook util.trigger_hook(user, util.Lifecycle.MAPPING_VALIDATION) return corsify({'code': 'success', 'data': data})
def status(): usage.track("Status") return corsify({'code': 'success'})