Work on hosted files. Now with basic hosted directory check and clean up.
This commit is contained in:
@@ -78,6 +78,44 @@ def load_hosted_file_obj(
|
||||
# ### END ### API Hosted File Methods ### load_hosted_file_obj() ###
|
||||
|
||||
|
||||
|
||||
|
||||
# ### BEGIN ### API Hosted File Methods ### lookup_file_hash() ###
|
||||
# Updated 2022-08-09
|
||||
@logger_reset
|
||||
def lookup_file_hash(
|
||||
file_hash: str,
|
||||
) -> Hosted_File_Base|dict|bool:
|
||||
log.setLevel(logging.INFO) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
||||
log.debug(locals())
|
||||
|
||||
|
||||
sql = f"""
|
||||
SELECT id AS 'hosted_file_id', id_random AS 'hosted_file_id_random'
|
||||
FROM hosted_file
|
||||
WHERE hosted_file.hash_sha256 = :hash_sha256
|
||||
"""
|
||||
log.debug(sql)
|
||||
|
||||
hosted_file_data = {}
|
||||
hosted_file_data['hash_sha256'] = file_hash
|
||||
log.debug(hosted_file_data)
|
||||
|
||||
if hosted_file_select_result := sql_select(sql=sql, data=hosted_file_data):
|
||||
hosted_file_id = hosted_file_select_result.get('hosted_file_id')
|
||||
hosted_file_id_random = hosted_file_select_result.get('hosted_file_id_random')
|
||||
log.info(f'Selected Hosted File record. Hosted File ID: {hosted_file_id}')
|
||||
return hosted_file_id
|
||||
elif hosted_file_select_result is None:
|
||||
log.warning(f'Hosted File record was not found. SHA 256 Hash: {file_hash}')
|
||||
return None
|
||||
# pass
|
||||
else:
|
||||
log.error(f'Something went wrong while trying to select the hosted file record. SHA 256 Hash: {file_hash}')
|
||||
return False
|
||||
# ### END ### API Hosted File Methods ### lookup_file_hash() ###
|
||||
|
||||
|
||||
# ### BEGIN ### API Hosted File Route ### get_file_object_hash() ###
|
||||
@logger_reset
|
||||
async def get_file_object_hash(file_object:File):
|
||||
|
||||
Reference in New Issue
Block a user