Skip to content

Commit 660b902

Browse files
committed
Adding no-cache paramater support for thumbnail HTTP server, so it will ignore cache and re-generate a thumbnail image
1 parent 3d67fb0 commit 660b902

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

src/classes/thumbnail.py

+13-4
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,13 @@
3737
from http.server import BaseHTTPRequestHandler, HTTPServer
3838
from socketserver import ThreadingMixIn
3939

40-
REGEX_THUMBNAIL_URL = re.compile(r"/thumbnails/(?P<file_id>.+?)/(?P<file_frame>\d+)(?P<only_path>/path/)?")
40+
# Regex for parsing URLs: (examples)
41+
# http://127.0.0.1:33723/thumbnails/9ATJTBQ71V/1/path/no-cache/
42+
# http://127.0.0.1:33723/thumbnails/9ATJTBQ71V/1/path/
43+
# http://127.0.0.1:33723/thumbnails/9ATJTBQ71V/1/path
44+
# http://127.0.0.1:33723/thumbnails/9ATJTBQ71V/1/
45+
# http://127.0.0.1:33723/thumbnails/9ATJTBQ71V/1
46+
REGEX_THUMBNAIL_URL = re.compile(r"/thumbnails/(?P<file_id>.+?)/(?P<file_frame>\d+)/*(?P<only_path>path)?/*(?P<no_cache>no-cache)?")
4147

4248

4349
def GenerateThumbnail(file_path, thumb_path, thumbnail_frame, width, height, mask, overlay):
@@ -124,10 +130,12 @@ def do_GET(self):
124130
""" Process each GET request and return a value (image or file path)"""
125131
# Parse URL
126132
url_output = REGEX_THUMBNAIL_URL.match(self.path)
127-
if url_output and len(url_output.groups()) == 3:
133+
if url_output and len(url_output.groups()) == 4:
128134
# Path is expected to have 3 matched components (third is optional though)
129135
# /thumbnails/FILE-ID/FRAME-NUMBER/ or
130-
# /thumbnails/FILE-ID/FRAME-NUMBER/path/
136+
# /thumbnails/FILE-ID/FRAME-NUMBER/path/ or
137+
# /thumbnails/FILE-ID/FRAME-NUMBER/no-cache/ or
138+
# /thumbnails/FILE-ID/FRAME-NUMBER/path/no-cache/
131139
self.send_response_only(200)
132140
else:
133141
self.send_error(404)
@@ -137,6 +145,7 @@ def do_GET(self):
137145
file_id = url_output.group('file_id')
138146
file_frame = int(url_output.group('file_frame'))
139147
only_path = url_output.group('only_path')
148+
no_cache = url_output.group('no_cache')
140149

141150
try:
142151
# Look up file data
@@ -165,7 +174,7 @@ def do_GET(self):
165174
# Try with ID and frame # in filename (for backwards compatibility)
166175
thumb_path = os.path.join(info.THUMBNAIL_PATH, "%s-%s.png" % (file_id, file_frame))
167176

168-
if not os.path.exists(thumb_path):
177+
if not os.path.exists(thumb_path) or no_cache:
169178
# Generate thumbnail (since we can't find it)
170179

171180
# Determine if video overlay should be applied to thumbnail

0 commit comments

Comments
 (0)