strix

A simple web UI for motion
git clone https://www.brianlane.com/git/strix
Log | Files | Refs | LICENSE

commit c5e19f7a1157a6bdda1f9db692f7c7d4eafa5a08
parent d4e5da80cf90b0f50bfc58e0ee9a91681ce12329
Author: Brian C. Lane <bcl@brianlane.com>
Date:   Sun, 26 Jun 2022 10:07:31 -0700

Add image directory listing

Diffstat:
Msrc/strix/api.py | 14++++++++++++--
Asrc/strix/ui/dirlist.tmpl | 15+++++++++++++++
Msrc/strix/ui/events.html | 7++++++-
3 files changed, 33 insertions(+), 3 deletions(-)

diff --git a/src/strix/api.py b/src/strix/api.py @@ -16,13 +16,15 @@ # along with this program. If not, see <http://www.gnu.org/licenses/>. from gevent import monkey; monkey.patch_all() from datetime import datetime +from glob import glob import os # Fix mimetypes so that it recognized m4v as video/mp4 import mimetypes mimetypes.add_type("video/mp4", ".m4v") -from bottle import install, route, run, static_file, request, Response, JSONPlugin +from bottle import abort, install, route, run, static_file, request, Response, JSONPlugin +from bottle import template from json import dumps from threading import Thread @@ -49,7 +51,15 @@ def run_api(logging_queue, base_dir, cameras, host, port, debug, queue_rx): @route('/motion/<filepath:path>') def serve_motion(filepath): - return static_file(filepath, root=base_dir) + if os.path.isfile(base_dir + "/" + filepath): + return static_file(filepath, root=base_dir) + + path = os.path.normpath(base_dir + os.path.normpath("/" + filepath)) + if not os.path.isdir(path): + abort(404) + + listing = sorted([os.path.basename(f) for f in glob(path + "/*.jpg")]) + return template(os.path.dirname(__file__)+"/ui/dirlist.tmpl", listing=listing) @route('/api/cameras/list') def serve_cameras_list() -> Response: diff --git a/src/strix/ui/dirlist.tmpl b/src/strix/ui/dirlist.tmpl @@ -0,0 +1,15 @@ +<!DOCTYPE html> +<html lang="en"> +<head> + <meta charset=UTF-8> + <meta name="viewport" content="width=device-width"> + <title>Strix - Motion Camera UI - Event Images</title> +</head> +<body> +<ul> +% for img in listing: + <li><a href="{{img}}">{{img}}</a> +% end +</ul> +</body> +</html> diff --git a/src/strix/ui/events.html b/src/strix/ui/events.html @@ -13,7 +13,8 @@ </div> <div id="days"> <ul id="daylinks"> - <li><a id="debugvideo" onclick="">debug</a></li> + <li><a id="imagelist" href="" target="_images">Images</a></li> + <li><a id="debugvideo" onclick="">Debug</a></li> <li><a id="scrollback" onclick="">Jump Back</a></li> </ul> </div> @@ -106,6 +107,10 @@ function load_viewer(event, scrollY) { viewer.src = event; viewer.autoplay = true; + // Setup the Images link + var il = document.querySelector("#imagelist"); + il.href = event.replace("video.m4v", ""); + // Setup the scrollback link var sb = document.querySelector("#scrollback"); sb.onclick = function() {scroll(0, scrollY);};