Skip to content

Commit

Permalink
[FIX] #32
Browse files Browse the repository at this point in the history
  • Loading branch information
derneuere committed Dec 13, 2020
1 parent e0ee723 commit 61793f3
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
12 changes: 6 additions & 6 deletions api/directory_watcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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()

Expand Down
2 changes: 1 addition & 1 deletion nextcloud/directory_watcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 61793f3

Please sign in to comment.