files now processes multiple paths, and view shows images for any images in appropriate path

This commit is contained in:
2021-01-12 16:58:41 +11:00
parent 48748c23be
commit d857233723
2 changed files with 11 additions and 11 deletions

View File

@@ -23,10 +23,7 @@ from settings import Settings
class FileData():
def __init__(self):
self.view_path=''
self.view_list=[]
self.symlink=''
self.file_list=[]
################################################################################
# Utility Functions for Files
@@ -106,17 +103,18 @@ class FileData():
paths= import_path.split("#")
for path in paths:
print( "GenerateFileData: Checking {}".format( path ) )
path = self.FixPath(path)
if os.path.exists( path ):
self.view_path = path
# to serve static content of the images, we create a symlink
# from inside the static subdir of each import_path that exists
self.symlink = self.FixPath('static/{}'.format( os.path.basename(path[0:-1])))
if not os.path.exists(self.symlink):
os.symlink(path, self.symlink)
symlink = self.FixPath('static/{}'.format( os.path.basename(path[0:-1])))
if not os.path.exists(symlink):
os.symlink(path, symlink)
self.file_list.append(glob.glob(self.view_path + '**', recursive=True))
for file in self.file_list[0]:
file_list=[]
file_list.append(glob.glob(path + '**', recursive=True))
for file in file_list[0]:
if file == path:
continue
stat = os.stat(file)
@@ -141,7 +139,8 @@ class FileData():
fsize = round(os.stat(file).st_size/(1024*1024))
fname=file.replace(path, "")
file_obj = Files( name=fname, type=ftype, size_mb=fsize, hash=fhash, thumbnail=fthumbnail )
path_prefix=symlink.replace(path,"")
file_obj = Files( name=fname, type=ftype, size_mb=fsize, hash=fhash, path_prefix=path_prefix, thumbnail=fthumbnail )
db.session.add(file_obj)
else:
print( "{} - {} is OLDER than {}".format( file, stat.st_ctime, last_import_date ) )
@@ -158,6 +157,7 @@ class Files(db.Model):
id = db.Column(db.Integer, db.Sequence('files_id_seq'), primary_key=True )
name = db.Column(db.String, unique=True, nullable=False )
type = db.Column(db.String, unique=False, nullable=False)
path_prefix = db.Column(db.String, unique=False, nullable=False)
size_mb = db.Column(db.Integer, unique=False, nullable=False)
# hash might not be unique, this could be the source of dupe problems
hash = db.Column(db.Integer, unique=True, nullable=True)

View File

@@ -29,7 +29,7 @@
<center>
<figure class="figure px-2" font-size: 24px;>
{% if obj.type=="Image" %}
<a href="{{file_data.symlink}}/{{obj.name}}"><img class="thumb" height="128" src="data:image/jpeg;base64,{{obj.thumbnail}}"></img></a>
<a href="{{obj.path_prefix}}/{{obj.name}}"><img class="thumb" height="128" src="data:image/jpeg;base64,{{obj.thumbnail}}"></img></a>
{% elif obj.type == "Video" %}
<div style="position:relative; width:100%">
<img class="thumb" style="display:block" height="128" src="data:image/jpeg;base64,{{obj.thumbnail}}"></img>