Added option so serve images recursively
This commit is contained in:
parent
cf6845c303
commit
1f60023b91
@ -1,4 +1,5 @@
|
|||||||
imgdir = "."
|
imgdir = "."
|
||||||
|
recursive = True
|
||||||
refresh = 5
|
refresh = 5
|
||||||
cachedir = "/tmp/webslider"
|
cachedir = "/tmp/webslider"
|
||||||
resolution = (1920, 1080)
|
resolution = (1920, 1080)
|
||||||
|
@ -14,6 +14,7 @@ import config
|
|||||||
app = Flask(__name__)
|
app = Flask(__name__)
|
||||||
|
|
||||||
imgdir = Path(config.imgdir).expanduser().resolve()
|
imgdir = Path(config.imgdir).expanduser().resolve()
|
||||||
|
img_glob = "**/*.jpg" if config.recursive else "*.jpg"
|
||||||
cache_resolution = config.resolution
|
cache_resolution = config.resolution
|
||||||
cache_dir = Path(config.cachedir) / ("%sx%s" % cache_resolution)
|
cache_dir = Path(config.cachedir) / ("%sx%s" % cache_resolution)
|
||||||
|
|
||||||
@ -25,7 +26,6 @@ def random():
|
|||||||
|
|
||||||
@app.route("/random_image/")
|
@app.route("/random_image/")
|
||||||
def random_image():
|
def random_image():
|
||||||
img_glob = "*jpg"
|
|
||||||
last_modified_time, last_modified_file = max(
|
last_modified_time, last_modified_file = max(
|
||||||
(f.stat().st_mtime, f) for f in imgdir.glob(img_glob)
|
(f.stat().st_mtime, f) for f in imgdir.glob(img_glob)
|
||||||
)
|
)
|
||||||
@ -36,7 +36,10 @@ def random_image():
|
|||||||
images = list(imgdir.glob(img_glob))
|
images = list(imgdir.glob(img_glob))
|
||||||
selected_image = choice(images).relative_to(imgdir)
|
selected_image = choice(images).relative_to(imgdir)
|
||||||
|
|
||||||
return redirect(url_for("image", filename=selected_image) + "?hash=%s" % get_cache_filename(selected_image))
|
return redirect(
|
||||||
|
url_for("image", filename=selected_image)
|
||||||
|
+ "?hash=%s" % get_cache_filename(selected_image)
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
@app.route("/img/<path:filename>")
|
@app.route("/img/<path:filename>")
|
||||||
@ -77,7 +80,7 @@ def get_cache_filename(filename):
|
|||||||
|
|
||||||
|
|
||||||
def pre_cache_images():
|
def pre_cache_images():
|
||||||
for image_file in sorted(imgdir.glob("*.jpg")):
|
for image_file in sorted(imgdir.glob(img_glob)):
|
||||||
create_cache_file(image_file.relative_to(imgdir))
|
create_cache_file(image_file.relative_to(imgdir))
|
||||||
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user