files now processes multiple paths, and view shows images for any images in appropriate path
This commit is contained in:
20
files.py
20
files.py
@@ -23,10 +23,7 @@ from settings import Settings
|
|||||||
|
|
||||||
class FileData():
|
class FileData():
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.view_path=''
|
|
||||||
self.view_list=[]
|
self.view_list=[]
|
||||||
self.symlink=''
|
|
||||||
self.file_list=[]
|
|
||||||
|
|
||||||
################################################################################
|
################################################################################
|
||||||
# Utility Functions for Files
|
# Utility Functions for Files
|
||||||
@@ -106,17 +103,18 @@ class FileData():
|
|||||||
paths= import_path.split("#")
|
paths= import_path.split("#")
|
||||||
|
|
||||||
for path in paths:
|
for path in paths:
|
||||||
|
print( "GenerateFileData: Checking {}".format( path ) )
|
||||||
path = self.FixPath(path)
|
path = self.FixPath(path)
|
||||||
if os.path.exists( path ):
|
if os.path.exists( path ):
|
||||||
self.view_path = path
|
|
||||||
# to serve static content of the images, we create a symlink
|
# to serve static content of the images, we create a symlink
|
||||||
# from inside the static subdir of each import_path that exists
|
# from inside the static subdir of each import_path that exists
|
||||||
self.symlink = self.FixPath('static/{}'.format( os.path.basename(path[0:-1])))
|
symlink = self.FixPath('static/{}'.format( os.path.basename(path[0:-1])))
|
||||||
if not os.path.exists(self.symlink):
|
if not os.path.exists(symlink):
|
||||||
os.symlink(path, self.symlink)
|
os.symlink(path, symlink)
|
||||||
|
|
||||||
self.file_list.append(glob.glob(self.view_path + '**', recursive=True))
|
file_list=[]
|
||||||
for file in self.file_list[0]:
|
file_list.append(glob.glob(path + '**', recursive=True))
|
||||||
|
for file in file_list[0]:
|
||||||
if file == path:
|
if file == path:
|
||||||
continue
|
continue
|
||||||
stat = os.stat(file)
|
stat = os.stat(file)
|
||||||
@@ -141,7 +139,8 @@ class FileData():
|
|||||||
|
|
||||||
fsize = round(os.stat(file).st_size/(1024*1024))
|
fsize = round(os.stat(file).st_size/(1024*1024))
|
||||||
fname=file.replace(path, "")
|
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)
|
db.session.add(file_obj)
|
||||||
else:
|
else:
|
||||||
print( "{} - {} is OLDER than {}".format( file, stat.st_ctime, last_import_date ) )
|
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 )
|
id = db.Column(db.Integer, db.Sequence('files_id_seq'), primary_key=True )
|
||||||
name = db.Column(db.String, unique=True, nullable=False )
|
name = db.Column(db.String, unique=True, nullable=False )
|
||||||
type = db.Column(db.String, unique=False, 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)
|
size_mb = db.Column(db.Integer, unique=False, nullable=False)
|
||||||
# hash might not be unique, this could be the source of dupe problems
|
# hash might not be unique, this could be the source of dupe problems
|
||||||
hash = db.Column(db.Integer, unique=True, nullable=True)
|
hash = db.Column(db.Integer, unique=True, nullable=True)
|
||||||
|
|||||||
@@ -29,7 +29,7 @@
|
|||||||
<center>
|
<center>
|
||||||
<figure class="figure px-2" font-size: 24px;>
|
<figure class="figure px-2" font-size: 24px;>
|
||||||
{% if obj.type=="Image" %}
|
{% 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" %}
|
{% elif obj.type == "Video" %}
|
||||||
<div style="position:relative; width:100%">
|
<div style="position:relative; width:100%">
|
||||||
<img class="thumb" style="display:block" height="128" src="data:image/jpeg;base64,{{obj.thumbnail}}"></img>
|
<img class="thumb" style="display:block" height="128" src="data:image/jpeg;base64,{{obj.thumbnail}}"></img>
|
||||||
|
|||||||
Reference in New Issue
Block a user