Bug fixes, clean up, stuff

This commit is contained in:
Scott Idem
2023-09-21 12:12:31 -04:00
parent fa39529f3f
commit 0ac9510546
4 changed files with 131 additions and 5 deletions

View File

@@ -144,7 +144,39 @@ def allowed_file_extension(extension: str, extension_list: list):
# ### END ### API Hosted File Methods ### allowed_file_extension() ###
# ### BEGIN ### API Hosted File Methods ### lookup_file_hash() ###
# Updated 2023-09-19
@logger_reset
def check_for_hosted_file_hash_file(
file_hash: str,
sub_dir: str,
) -> dict|bool:
log.setLevel(logging.DEBUG) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
log.debug(locals())
file_size = None
hosted_files_path = settings.FILES_PATH['hosted_files_root']
log.info(f'Hosted Files Path: {hosted_files_path}')
log.debug(shutil.disk_usage(hosted_files_path))
hosted_files_dir_w_subdir = os.path.join(hosted_files_path, sub_dir)
path_hosted_files_dir_w_subdir = pathlib.Path(hosted_files_dir_w_subdir)
if path_hosted_files_dir_w_subdir.exists(): pass
else:
log.warning('Hashed hosted file subdirectory was not found in the hosted files root.')
return False
hosted_files_dir_w_subdir_filename = os.path.join(hosted_files_path, sub_dir, f'{file_hash}.file')
path_hosted_files_dir_w_subdir_filename = pathlib.Path(hosted_files_dir_w_subdir_filename)
if path_hosted_files_dir_w_subdir_filename.exists():
file_size = os.path.getsize(path_hosted_files_dir_w_subdir_filename)
else:
log.warning('Hashed hosted file not found in the expected hosted files subdirectory.')
return False
return {'found': True, 'file_size': file_size}
# ### BEGIN ### API Hosted File Methods ### save_file() ###