refac
This commit is contained in:
1 parent
a2a9a3a42a
commit
15f9a8f3f1
3 files changed
+14
-14
No files matched your search
@@ -660,7 +660,7 @@ def transcription_handler(request, file_path, metadata, user=None):
|
|||||||
data = {'text': transcript.strip()}
|
data = {'text': transcript.strip()}
|
||||||
|
|
||||||
# save the transcript to a json file
|
# save the transcript to a json file
|
||||||
transcript_file = f'{file_dir}/{id}.json'
|
transcript_file = os.path.join(file_dir, f'{id}.json')
|
||||||
with open(transcript_file, 'w') as f:
|
with open(transcript_file, 'w') as f:
|
||||||
json.dump(data, f)
|
json.dump(data, f)
|
||||||
|
|
||||||
@@ -698,7 +698,7 @@ def transcription_handler(request, file_path, metadata, user=None):
|
|||||||
data = r.json()
|
data = r.json()
|
||||||
|
|
||||||
# save the transcript to a json file
|
# save the transcript to a json file
|
||||||
transcript_file = f'{file_dir}/{id}.json'
|
transcript_file = os.path.join(file_dir, f'{id}.json')
|
||||||
with open(transcript_file, 'w') as f:
|
with open(transcript_file, 'w') as f:
|
||||||
json.dump(data, f)
|
json.dump(data, f)
|
||||||
|
|
||||||
@@ -767,7 +767,7 @@ def transcription_handler(request, file_path, metadata, user=None):
|
|||||||
data = {'text': transcript.strip()}
|
data = {'text': transcript.strip()}
|
||||||
|
|
||||||
# Save transcript
|
# Save transcript
|
||||||
transcript_file = f'{file_dir}/{id}.json'
|
transcript_file = os.path.join(file_dir, f'{id}.json')
|
||||||
with open(transcript_file, 'w') as f:
|
with open(transcript_file, 'w') as f:
|
||||||
json.dump(data, f)
|
json.dump(data, f)
|
||||||
|
|
||||||
@@ -874,7 +874,7 @@ def transcription_handler(request, file_path, metadata, user=None):
|
|||||||
data = {'text': transcript}
|
data = {'text': transcript}
|
||||||
|
|
||||||
# Save transcript to json file (consistent with other providers)
|
# Save transcript to json file (consistent with other providers)
|
||||||
transcript_file = f'{file_dir}/{id}.json'
|
transcript_file = os.path.join(file_dir, f'{id}.json')
|
||||||
with open(transcript_file, 'w') as f:
|
with open(transcript_file, 'w') as f:
|
||||||
json.dump(data, f)
|
json.dump(data, f)
|
||||||
|
|
||||||
@@ -1059,7 +1059,7 @@ def transcription_handler(request, file_path, metadata, user=None):
|
|||||||
data = {'text': transcript}
|
data = {'text': transcript}
|
||||||
|
|
||||||
# Save transcript to json file (consistent with other providers)
|
# Save transcript to json file (consistent with other providers)
|
||||||
transcript_file = f'{file_dir}/{id}.json'
|
transcript_file = os.path.join(file_dir, f'{id}.json')
|
||||||
with open(transcript_file, 'w') as f:
|
with open(transcript_file, 'w') as f:
|
||||||
json.dump(data, f)
|
json.dump(data, f)
|
||||||
|
|
||||||
@@ -1237,9 +1237,9 @@ def transcription(
|
|||||||
filename = f'{id}.{ext}'
|
filename = f'{id}.{ext}'
|
||||||
contents = file.file.read()
|
contents = file.file.read()
|
||||||
|
|
||||||
file_dir = f'{CACHE_DIR}/audio/transcriptions'
|
file_dir = os.path.join(CACHE_DIR, 'audio', 'transcriptions')
|
||||||
os.makedirs(file_dir, exist_ok=True)
|
os.makedirs(file_dir, exist_ok=True)
|
||||||
file_path = f'{file_dir}/{filename}'
|
file_path = os.path.join(file_dir, filename)
|
||||||
|
|
||||||
# Defense-in-depth: ensure resolved path stays within intended directory
|
# Defense-in-depth: ensure resolved path stays within intended directory
|
||||||
if not os.path.realpath(file_path).startswith(os.path.realpath(file_dir)):
|
if not os.path.realpath(file_path).startswith(os.path.realpath(file_dir)):
|
||||||
|
|||||||
@@ -1585,7 +1585,7 @@ async def download_model(
|
|||||||
file_name = parse_huggingface_url(form_data.url)
|
file_name = parse_huggingface_url(form_data.url)
|
||||||
|
|
||||||
if file_name:
|
if file_name:
|
||||||
file_path = f'{UPLOAD_DIR}/{file_name}'
|
file_path = os.path.join(UPLOAD_DIR, file_name)
|
||||||
|
|
||||||
return StreamingResponse(
|
return StreamingResponse(
|
||||||
download_file_stream(url, form_data.url, file_path, file_name),
|
download_file_stream(url, form_data.url, file_path, file_name),
|
||||||
|
|||||||
@@ -61,7 +61,7 @@ class LocalStorageProvider(StorageProvider):
|
|||||||
contents = file.read()
|
contents = file.read()
|
||||||
if not contents:
|
if not contents:
|
||||||
raise ValueError(ERROR_MESSAGES.EMPTY_CONTENT)
|
raise ValueError(ERROR_MESSAGES.EMPTY_CONTENT)
|
||||||
file_path = f'{UPLOAD_DIR}/{filename}'
|
file_path = os.path.join(UPLOAD_DIR, filename)
|
||||||
with open(file_path, 'wb') as f:
|
with open(file_path, 'wb') as f:
|
||||||
f.write(contents)
|
f.write(contents)
|
||||||
return contents, file_path
|
return contents, file_path
|
||||||
@@ -74,8 +74,8 @@ class LocalStorageProvider(StorageProvider):
|
|||||||
@staticmethod
|
@staticmethod
|
||||||
def delete_file(file_path: str) -> None:
|
def delete_file(file_path: str) -> None:
|
||||||
"""Handles deletion of the file from local storage."""
|
"""Handles deletion of the file from local storage."""
|
||||||
filename = file_path.split('/')[-1]
|
filename = os.path.basename(file_path)
|
||||||
file_path = f'{UPLOAD_DIR}/{filename}'
|
file_path = os.path.join(UPLOAD_DIR, filename)
|
||||||
if os.path.isfile(file_path):
|
if os.path.isfile(file_path):
|
||||||
os.remove(file_path)
|
os.remove(file_path)
|
||||||
else:
|
else:
|
||||||
@@ -202,7 +202,7 @@ class S3StorageProvider(StorageProvider):
|
|||||||
return '/'.join(full_file_path.split('//')[1].split('/')[1:])
|
return '/'.join(full_file_path.split('//')[1].split('/')[1:])
|
||||||
|
|
||||||
def _get_local_file_path(self, s3_key: str) -> str:
|
def _get_local_file_path(self, s3_key: str) -> str:
|
||||||
return f'{UPLOAD_DIR}/{s3_key.split("/")[-1]}'
|
return os.path.join(UPLOAD_DIR, s3_key.split('/')[-1])
|
||||||
|
|
||||||
|
|
||||||
class GCSStorageProvider(StorageProvider):
|
class GCSStorageProvider(StorageProvider):
|
||||||
@@ -234,7 +234,7 @@ class GCSStorageProvider(StorageProvider):
|
|||||||
"""Handles downloading of the file from GCS storage."""
|
"""Handles downloading of the file from GCS storage."""
|
||||||
try:
|
try:
|
||||||
filename = file_path.removeprefix('gs://').split('/')[1]
|
filename = file_path.removeprefix('gs://').split('/')[1]
|
||||||
local_file_path = f'{UPLOAD_DIR}/{filename}'
|
local_file_path = os.path.join(UPLOAD_DIR, filename)
|
||||||
blob = self.bucket.get_blob(filename)
|
blob = self.bucket.get_blob(filename)
|
||||||
blob.download_to_filename(local_file_path)
|
blob.download_to_filename(local_file_path)
|
||||||
|
|
||||||
@@ -298,7 +298,7 @@ class AzureStorageProvider(StorageProvider):
|
|||||||
"""Handles downloading of the file from Azure Blob Storage."""
|
"""Handles downloading of the file from Azure Blob Storage."""
|
||||||
try:
|
try:
|
||||||
filename = file_path.split('/')[-1]
|
filename = file_path.split('/')[-1]
|
||||||
local_file_path = f'{UPLOAD_DIR}/{filename}'
|
local_file_path = os.path.join(UPLOAD_DIR, filename)
|
||||||
blob_client = self.container_client.get_blob_client(filename)
|
blob_client = self.container_client.get_blob_client(filename)
|
||||||
with open(local_file_path, 'wb') as download_file:
|
with open(local_file_path, 'wb') as download_file:
|
||||||
download_file.write(blob_client.download_blob().readall())
|
download_file.write(blob_client.download_blob().readall())
|
||||||
|
|||||||
Reference in new issue
Block a user