Added some filename sanitation
This commit is contained in:
parent
c5f66ec0d9
commit
9e939dfd03
@ -4,13 +4,13 @@ import os
|
|||||||
import functools
|
import functools
|
||||||
import logging
|
import logging
|
||||||
from contextlib import closing, contextmanager
|
from contextlib import closing, contextmanager
|
||||||
import pprint
|
|
||||||
|
|
||||||
import requests
|
import requests
|
||||||
import requests.structures
|
import requests.structures
|
||||||
import pillarsdk
|
import pillarsdk
|
||||||
import pillarsdk.exceptions
|
import pillarsdk.exceptions
|
||||||
import pillarsdk.utils
|
import pillarsdk.utils
|
||||||
|
from pillarsdk.utils import sanitize_filename
|
||||||
|
|
||||||
from . import http_cache
|
from . import http_cache
|
||||||
|
|
||||||
@ -288,7 +288,7 @@ async def fetch_thumbnail_info(file: pillarsdk.File, directory: str, desired_siz
|
|||||||
.format(file['_id'], desired_size))
|
.format(file['_id'], desired_size))
|
||||||
|
|
||||||
root, ext = os.path.splitext(file['file_path'])
|
root, ext = os.path.splitext(file['file_path'])
|
||||||
thumb_fname = "{0}-{1}.jpg".format(root, desired_size)
|
thumb_fname = sanitize_filename('{0}-{1}.jpg'.format(root, desired_size))
|
||||||
thumb_path = os.path.abspath(os.path.join(directory, thumb_fname))
|
thumb_path = os.path.abspath(os.path.join(directory, thumb_fname))
|
||||||
|
|
||||||
return thumb_link, thumb_path
|
return thumb_link, thumb_path
|
||||||
@ -422,13 +422,14 @@ async def download_file_by_uuid(file_uuid,
|
|||||||
metadata_file = os.path.join(metadata_directory, 'files', '%s.json' % file_uuid)
|
metadata_file = os.path.join(metadata_directory, 'files', '%s.json' % file_uuid)
|
||||||
save_as_json(file_desc, metadata_file)
|
save_as_json(file_desc, metadata_file)
|
||||||
|
|
||||||
file_path = os.path.join(target_directory, file_desc['filename'])
|
file_path = os.path.join(target_directory, sanitize_filename(file_desc['filename']))
|
||||||
file_url = file_desc['link']
|
file_url = file_desc['link']
|
||||||
# log.debug('Texture %r:\n%s', file_uuid, pprint.pformat(file_desc.to_dict()))
|
# log.debug('Texture %r:\n%s', file_uuid, pprint.pformat(file_desc.to_dict()))
|
||||||
loop.call_soon_threadsafe(file_loading, file_path, file_desc)
|
loop.call_soon_threadsafe(file_loading, file_path, file_desc)
|
||||||
|
|
||||||
# Cached headers are stored in the project space
|
# Cached headers are stored in the project space
|
||||||
header_store = os.path.join(metadata_directory, 'files', '%s.headers' % file_uuid)
|
header_store = os.path.join(metadata_directory, 'files',
|
||||||
|
sanitize_filename('%s.headers' % file_uuid))
|
||||||
|
|
||||||
await download_to_file(file_url, file_path, header_store=header_store, future=future)
|
await download_to_file(file_url, file_path, header_store=header_store, future=future)
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user