From 61793f3a0c41676a0c7d10444f739c3c837a29c8 Mon Sep 17 00:00:00 2001 From: Niaz Faridani-Rad Date: Sun, 13 Dec 2020 11:11:37 +0100 Subject: [PATCH] [FIX] #32 --- api/directory_watcher.py | 12 ++++++------ nextcloud/directory_watcher.py | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/api/directory_watcher.py b/api/directory_watcher.py index 49dca9ea03..5c0e298b55 100644 --- a/api/directory_watcher.py +++ b/api/directory_watcher.py @@ -12,12 +12,12 @@ import magic from PIL import Image -def isValidMedia(p): +def isValidMedia(filebuffer): try: - filetype = magic.from_file(p, mime=True) + filetype = magic.from_buffer(filebuffer, mime=True) return filetype.find('image/jpeg') or filetype.find('image/png') except: - util.logger.exception("Following image throwed an exception: " + p) + util.logger.exception("Following image throwed an exception: " + file.name) return False def calculate_hash(user,image_path): @@ -28,7 +28,7 @@ def calculate_hash(user,image_path): return hash_md5.hexdigest() + str(user.id) def handle_new_image(user, image_path, job_id): - if isValidMedia(image_path): + if isValidMedia(open(image_path,"rb").read(2048)): try: elapsed_times = { 'md5':None, @@ -93,7 +93,7 @@ def handle_new_image(user, image_path, job_id): util.logger.exception("job {}: could not load image {}".format(job_id,image_path)) def rescan_image(user, image_path, job_id): - if isValidMedia(image_path): + if isValidMedia(open(image_path,"rb").read(2048)): try: elapsed_times = { 'md5':None, @@ -147,7 +147,7 @@ def scan_photos(user, job_id): image_paths = [ p for p in image_paths - if isValidMedia(p) and 'thumb' not in p.lower() + if isValidMedia(open(p,"rb").read(2048)) and 'thumb' not in p.lower() ] image_paths.sort() diff --git a/nextcloud/directory_watcher.py b/nextcloud/directory_watcher.py index 50e9c19e89..6fa3259d7b 100644 --- a/nextcloud/directory_watcher.py +++ b/nextcloud/directory_watcher.py @@ -13,7 +13,7 @@ def collect_photos(nc, path, photos): for x in nc.list(path): - if isValidMedia(x.path): + if isValidMedia(nc.get_file_contents(x)): photos.append(x.path) elif x.is_dir(): collect_photos(nc, x.path, photos)