Fix?
This commit is contained in:
@@ -48,7 +48,7 @@ requests
|
|||||||
rfc3986
|
rfc3986
|
||||||
six
|
six
|
||||||
sniffio
|
sniffio
|
||||||
SQLAlchemy==1.4.47 # 1.4.47 is the newest I am working with
|
SQLAlchemy==1.4.44 # 1.4.47 is the newest I am working with
|
||||||
starlette
|
starlette
|
||||||
stripe
|
stripe
|
||||||
typing_extensions
|
typing_extensions
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ from fastapi import APIRouter, Body, Depends, File, Form, Header, HTTPException,
|
|||||||
from fastapi.responses import FileResponse
|
from fastapi.responses import FileResponse
|
||||||
from pydantic import BaseModel, EmailStr, Field
|
from pydantic import BaseModel, EmailStr, Field
|
||||||
from typing import Dict, List, Optional, Set, Union
|
from typing import Dict, List, Optional, Set, Union
|
||||||
from pdf2image import convert_from_path
|
# from pdf2image import convert_from_path
|
||||||
|
|
||||||
from app.lib_general import log, logging, common_route_params, Common_Route_Params, common_route_params_min, Common_Route_Params_Min
|
from app.lib_general import log, logging, common_route_params, Common_Route_Params, common_route_params_min, Common_Route_Params_Min
|
||||||
from app.config import settings
|
from app.config import settings
|
||||||
@@ -739,75 +739,75 @@ async def download_tmp(
|
|||||||
# ### END ### API Hosted File ### download_tmp() ###
|
# ### END ### API Hosted File ### download_tmp() ###
|
||||||
|
|
||||||
|
|
||||||
# ### BEGIN ### API Hosted File Route ### convert_file() ###
|
# # ### BEGIN ### API Hosted File Route ### convert_file() ###
|
||||||
# This just needs to return the correct model for a new hosted_file
|
# # This just needs to return the correct model for a new hosted_file
|
||||||
# Updated 2023-04-04
|
# # Updated 2023-04-04
|
||||||
@router.get('/{hosted_file_id}/convert_file')
|
# @router.get('/{hosted_file_id}/convert_file')
|
||||||
async def convert_file(
|
# async def convert_file(
|
||||||
hosted_file_id: str = Query(..., min_length=11, max_length=22),
|
# hosted_file_id: str = Query(..., min_length=11, max_length=22),
|
||||||
|
|
||||||
from_type: str = 'pdf',
|
# from_type: str = 'pdf',
|
||||||
to_type: str = 'webp',
|
# to_type: str = 'webp',
|
||||||
pdf_opt1: bool = False,
|
# pdf_opt1: bool = False,
|
||||||
pdf_opt2: str = 'test',
|
# pdf_opt2: str = 'test',
|
||||||
|
|
||||||
commons: Common_Route_Params = Depends(common_route_params),
|
# commons: Common_Route_Params = Depends(common_route_params),
|
||||||
):
|
# ):
|
||||||
log.setLevel(logging.DEBUG) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
# log.setLevel(logging.DEBUG) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
||||||
log.debug(locals())
|
# log.debug(locals())
|
||||||
|
|
||||||
# Need to look up file_hash for hosted_file_id
|
# # Need to look up file_hash for hosted_file_id
|
||||||
|
|
||||||
# file_hash = '0080f0b03144927c173694745483894a09208d9444fdaccab054493f699361be'
|
# # file_hash = '0080f0b03144927c173694745483894a09208d9444fdaccab054493f699361be'
|
||||||
file_hash = '279312d1738fd3a8a2f136b48295e28664d38b18de66c55de56b8886b9454784'
|
# file_hash = '279312d1738fd3a8a2f136b48295e28664d38b18de66c55de56b8886b9454784'
|
||||||
file_hash_filename = f'{file_hash}.file'
|
# file_hash_filename = f'{file_hash}.file'
|
||||||
|
|
||||||
hosted_files_path = settings.FILES_PATH['hosted_files_root']
|
# hosted_files_path = settings.FILES_PATH['hosted_files_root']
|
||||||
log.info(f'Hosted Files Path: {hosted_files_path}')
|
# log.info(f'Hosted Files Path: {hosted_files_path}')
|
||||||
log.debug(shutil.disk_usage(hosted_files_path))
|
# log.debug(shutil.disk_usage(hosted_files_path))
|
||||||
|
|
||||||
file_subdirectory = file_hash[0:2]
|
# file_subdirectory = file_hash[0:2]
|
||||||
full_file_path = os.path.join(hosted_files_path, file_subdirectory, file_hash_filename)
|
# full_file_path = os.path.join(hosted_files_path, file_subdirectory, file_hash_filename)
|
||||||
log.info(f'File Hash with Subdirectory: {full_file_path}')
|
# log.info(f'File Hash with Subdirectory: {full_file_path}')
|
||||||
|
|
||||||
hosted_tmp_path = settings.FILES_PATH['hosted_tmp_root']
|
# hosted_tmp_path = settings.FILES_PATH['hosted_tmp_root']
|
||||||
log.info(f'Hosted Tmp Path: {hosted_tmp_path}')
|
# log.info(f'Hosted Tmp Path: {hosted_tmp_path}')
|
||||||
log.debug(shutil.disk_usage(hosted_tmp_path))
|
# log.debug(shutil.disk_usage(hosted_tmp_path))
|
||||||
|
|
||||||
hosted_tmp_convert_file_path = os.path.join(hosted_tmp_path, 'convert_file')
|
# hosted_tmp_convert_file_path = os.path.join(hosted_tmp_path, 'convert_file')
|
||||||
if pathlib.Path(hosted_tmp_convert_file_path):
|
# if pathlib.Path(hosted_tmp_convert_file_path):
|
||||||
log.info('Hosted tmp convert file path found')
|
# log.info('Hosted tmp convert file path found')
|
||||||
else:
|
# else:
|
||||||
log.info('Creating hosted tmp convert file path')
|
# log.info('Creating hosted tmp convert file path')
|
||||||
pathlib.Path(hosted_tmp_convert_file_path).mkdir(parents=True, exist_ok=True)
|
# pathlib.Path(hosted_tmp_convert_file_path).mkdir(parents=True, exist_ok=True)
|
||||||
|
|
||||||
images = convert_from_path(full_file_path, size=(2160, None))
|
# images = convert_from_path(full_file_path, size=(2160, None))
|
||||||
for image in images:
|
# for image in images:
|
||||||
save_path = os.path.join(hosted_tmp_convert_file_path, 'converted_2160px_lossless_90q.webp')
|
# save_path = os.path.join(hosted_tmp_convert_file_path, 'converted_2160px_lossless_90q.webp')
|
||||||
|
|
||||||
# image.save('testing_2625px_9.png', compress_level=9)
|
# # image.save('testing_2625px_9.png', compress_level=9)
|
||||||
|
|
||||||
# Lossy WebP takes about 25% of the time as WebP lossless compression with 100 level effort
|
# # Lossy WebP takes about 25% of the time as WebP lossless compression with 100 level effort
|
||||||
# .46 seconds vs 2.1 seconds with example PDF
|
# # .46 seconds vs 2.1 seconds with example PDF
|
||||||
|
|
||||||
# image.save('testing_2625px_80q.webp', quality=80) # default
|
# # image.save('testing_2625px_80q.webp', quality=80) # default
|
||||||
# timer_2a_start = timer()
|
# # timer_2a_start = timer()
|
||||||
image.save(save_path, lossless=False, quality=90) # default quality is 80
|
# image.save(save_path, lossless=False, quality=90) # default quality is 80
|
||||||
# timer_2a_end = timer()
|
# # timer_2a_end = timer()
|
||||||
# print( round((timer_2a_end - timer_2a_start), 8) )
|
# # print( round((timer_2a_end - timer_2a_start), 8) )
|
||||||
|
|
||||||
# timer_2b_start = timer()
|
# # timer_2b_start = timer()
|
||||||
# image.save('testing_2160px_lossless_100q.webp', lossless=True, quality=100) # quality is level of effort
|
# # image.save('testing_2160px_lossless_100q.webp', lossless=True, quality=100) # quality is level of effort
|
||||||
# timer_2b_end = timer()
|
# # timer_2b_end = timer()
|
||||||
# print( round((timer_2b_end - timer_2b_start), 8) )
|
# # print( round((timer_2b_end - timer_2b_start), 8) )
|
||||||
|
|
||||||
# file_info = await save_file(
|
# # file_info = await save_file(
|
||||||
# file = file_obj,
|
# # file = file_obj,
|
||||||
# account_id = account_id,
|
# # account_id = account_id,
|
||||||
# account_id_random = account_id_random,
|
# # account_id_random = account_id_random,
|
||||||
# link_to_type = link_to_type,
|
# # link_to_type = link_to_type,
|
||||||
# link_to_id = link_to_id,
|
# # link_to_id = link_to_id,
|
||||||
# link_to_id_random = link_to_id_random,
|
# # link_to_id_random = link_to_id_random,
|
||||||
# check_allowed_extension = False,
|
# # check_allowed_extension = False,
|
||||||
# )
|
# # )
|
||||||
# if file_info['saved']: pass
|
# # if file_info['saved']: pass
|
||||||
Reference in New Issue
Block a user