-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcloud_reader.py
More file actions
574 lines (480 loc) · 22.6 KB
/
cloud_reader.py
File metadata and controls
574 lines (480 loc) · 22.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
from __future__ import annotations
import io, os, re, hashlib, fcntl, urllib.parse
from contextlib import contextmanager
from pathlib import Path
from typing import Literal
import base64, brotli, urllib3, certifi
from adapters.core import pick_adapter
from flask import Flask, request, send_file, abort, Response, render_template_string
from slugify import slugify
import pyvips
SAFE_RE = re.compile(r'^[A-Za-z0-9_.-]+$')
def to_key(s:str)->str:
if SAFE_RE.fullmatch(s):
return s
b64 = base64.urlsafe_b64encode(s.encode()).decode()
return b64.rstrip('=')
def from_key(k: str) -> str:
pad = '=' * (-len(k) % 4)
try:
decoded = base64.urlsafe_b64decode(k + pad).decode()
if decoded.startswith('http'):
return decoded
except Exception:
pass
return k
# ─────────────────────── Config ───────────────────────────────────────────
IMAGE_HOST = "https://meo.comick.pictures"
CACHE_ROOT = Path("image_cache")
CACHE_LIMIT = 2 * 1024 * 1024 * 1024 # 2 GB
DEVICE_W = dict(mobile=720, tablet=1080, desktop=None)
TARGET_KB = dict(avif=50, webp=75, jpeg=110)
WEBP_NL = 60
LINEART_COL = 32
HTTP = urllib3.PoolManager(
num_pools=20,
maxsize=20,
timeout=urllib3.util.Timeout(connect=6, read=12),
cert_reqs='CERT_REQUIRED',
ca_certs=certifi.where(),
headers={"User-Agent": "Mozilla/5.0"}
)
# ───────────────────── Flask app & dirs ───────────────────────────────────
app = Flask(__name__)
for d in ("mobile", "tablet", "desktop"):
(CACHE_ROOT / d).mkdir(parents=True, exist_ok=True)
# ───────────────────── Helpers ────────────────────────────────────────────
def validate_filename(fn:str)->str:
if not re.fullmatch(r"[A-Za-z0-9_.\-]+", fn):
abort(400,"bad filename")
return fn
MOBILE = re.compile(r"Mobile|Android|iPhone|Windows Phone", re.I).search
TABLET = re.compile(r"iPad|Tablet|Tab", re.I).search
def parse_device(ua: str) -> tuple[str, int | None]:
if MOBILE(ua): return "mobile", 720
if TABLET(ua): return "tablet", 1080
return "desktop", None
def client_hints(req)->dict:
h=req.headers
return dict(
save_data=h.get("Save-Data","").lower()=="on",
ect=(h.get("ECT") or h.get("Ect") or "").lower(),
width=int(h.get("Width",0) or 0) or None,
vwidth=int(h.get("Viewport-Width",0) or 0) or None)
def browser_fmt(accept: str, net: str) -> Literal["avif", "webp", "jpeg"]:
a = accept.lower()
if net in ("2g", "slow-2g"):
return "webp" if "image/webp" in a else "jpeg"
if "image/avif" in a: # <- no extra flag
return "avif"
if "image/webp" in a:
return "webp"
return "jpeg"
def target_width(mw:int|None,hints:dict)->int|None:
return hints.get("width") or hints.get("vwidth") or mw
# ─────────── libvips helpers ────────────
def vips_load(buf: bytes) -> pyvips.Image:
v = pyvips.Image.new_from_buffer(buf, "", access="sequential").autorot()
if v.format != "uchar":
v = v.cast("uchar")
if v.interpretation not in ("srgb", "b-w"):
v = v.colourspace("srgb")
return v
def vips_is_line_art(v: pyvips.Image) -> bool:
scale = 64 / max(v.width, v.height)
small = v.resize(scale, kernel="nearest")
hist = small.hist_find()
return hist.width * hist.height <= LINEART_COL
def vips_low_var_gray(v: pyvips.Image) -> pyvips.Image:
if v.bands == 1:
return v
if hasattr(v, "deviation"):
std = sum(v.deviation()[0, 0:v.bands]) / v.bands
if std < 14:
return v.colourspace("b-w")
return v
def vips_encode(v: pyvips.Image, fmt: str, q: int, nl=False) -> bytes:
if fmt == "webp":
return v.write_to_buffer(".webp", Q=q, effort=6,
near_lossless=WEBP_NL if nl else 0)
if fmt == "avif":
return v.write_to_buffer(".avif", Q=q, speed=6)
if fmt == "jpeg":
return v.write_to_buffer(".jpg", Q=q, optimize_coding=True)
raise ValueError("fmt?")
def encode_with_budget(v: pyvips.Image, fmt: str, init_q: int) -> bytes:
if fmt == "webp" and vips_is_line_art(v):
return vips_encode(v, "webp", init_q, nl=True)
if fmt == "avif":
return vips_encode(v, "avif", init_q)
budget = TARGET_KB[fmt]
q, step = init_q, 5
mpx = v.width * v.height / 1_000_000
for _ in range(4):
data = vips_encode(v, fmt, q)
if len(data) / 1024 <= budget * mpx or q <= 20:
return data
q = max(15, q - step)
step += 2
return data
# ───────────────────── Cache helpers ──────────────────────────────────────
def cache_key(dev,fmt,name,w):
return CACHE_ROOT/dev/f"{slugify(name)}{'-w'+str(w) if w else ''}.{fmt}"
@contextmanager
def file_lock(p:Path):
fh=p.with_suffix(p.suffix+".lock").open("w")
fcntl.flock(fh,fcntl.LOCK_EX)
try: yield
finally:
fcntl.flock(fh,fcntl.LOCK_UN); fh.close()
try: Path(fh.name).unlink(missing_ok=True)
except OSError: pass
def atomic_write(dst:Path,data:bytes):
tmp=dst.with_suffix(dst.suffix+".tmp")
with tmp.open("wb") as f:
f.write(data); f.flush(); os.fsync(f.fileno())
os.replace(tmp,dst)
def etag_for(p:Path)->str:
return hashlib.md5(p.read_bytes()).hexdigest()
def prune_cache():
size=sum(p.stat().st_size for p in CACHE_ROOT.rglob("*") if p.is_file())
if size<=CACHE_LIMIT: return
files=sorted(CACHE_ROOT.rglob("*"),key=lambda p:p.stat().st_atime)
while size>CACHE_LIMIT*0.9 and files:
f=files.pop(0)
try: size-=f.stat().st_size; f.unlink(missing_ok=True)
except OSError: pass
# ───────────────────── Image endpoint ───────────────────────────────────── Here Incase I want to Switch back from go
# def fetch_and_encode(ori: str, hdr: dict,
# mw: int | None, fmt: str, device: str) -> bytes:
# r = HTTP.request("GET", ori, headers=hdr)
# if r.status >= 400:
# raise ValueError(f"{r.status}")
# v = vips_load(r.data)
# # viewport-based scale
# if mw and v.width > mw:
# v = v.resize(mw / v.width, kernel="lanczos3")
# # libheif size guard
# MAX_W, MAX_H = 6000, 12000
# if v.width > MAX_W or v.height > MAX_H:
# ratio = min(MAX_W / v.width, MAX_H / v.height)
# v = v.resize(ratio, kernel="lanczos3")
# if v.hasalpha():
# v = v.flatten(background=[255, 255, 255])
# v = vips_low_var_gray(v)
# init_q = 50 if fmt == "avif" else (55 if device != "desktop" else 75)
# try:
# return encode_with_budget(v, fmt, init_q)
# except pyvips.Error:
# if fmt == "avif":
# return encode_with_budget(v, "webp", 60)
# raise
# @app.route("/image/<path:filename>")
# def image_proxy(filename):
# filename = validate_filename(filename)
# # strip format suffix if present
# raw = filename
# for _ in range(2):
# if re.search(r'\.(avif|webp|jpe?g|png)$', raw, re.I):
# raw = raw.rsplit('.', 1)[0]
# origin = from_key(raw)
# if origin.startswith("http"):
# ori = origin
# extra_hdr = {"Referer": "https://bato.to/"}
# else: # Comick b2key
# if not re.search(r'\.(jpe?g|png|webp)$', origin, re.I):
# origin += ".jpg"
# ori = f"{IMAGE_HOST}/{origin}"
# extra_hdr = {"Referer": "https://comick.io/"}
# hints = client_hints(request)
# device, mw = parse_device(request.headers.get("User-Agent", ""))
# mw = target_width(mw, hints)
# if hints["save_data"] and mw:
# mw = min(mw, 480)
# fmt = browser_fmt(request.headers.get("Accept", ""), hints["ect"])
# key = cache_key(device, fmt, filename, mw)
# # -------------- served from cache -----------------------------------
# if key.exists():
# et = etag_for(key)
# if request.headers.get("If-None-Match") == et:
# return Response(status=304)
# resp = send_file(key, mimetype=f"image/{fmt}",
# max_age=2_592_000, etag=et)
# resp.headers["X-Optimised-Format"] = fmt
# return resp
# # -------------- generate & cache ------------------------------------
# with file_lock(key):
# if key.exists():
# resp = send_file(key, mimetype=f"image/{fmt}",
# max_age=2_592_000, etag=etag_for(key))
# resp.headers["X-Optimised-Format"] = fmt
# return resp
# try:
# buf_bytes = ENC_POOL.submit(
# fetch_and_encode, ori, extra_hdr, mw, fmt, device
# ).result()
# except Exception as ex:
# app.logger.exception("encode failed for %s", ori)
# abort(500, f"optimisation error {ex}")
# key.parent.mkdir(parents=True, exist_ok=True)
# atomic_write(key, buf_bytes)
# prune_cache()
# resp = send_file(io.BytesIO(buf_bytes), mimetype=f"image/{fmt}",
# max_age=2_592_000, etag=etag_for(key))
# resp.headers["X-Optimised-Format"] = fmt
# return resp
# ───────────────── Brotli for HTML ────────────────────────────────────────
@app.after_request
def compress(resp):
if not resp.mimetype.startswith("text/") or len(resp.get_data()) <= 512:
return resp
ae = request.headers.get("Accept-Encoding","").lower()
if resp.headers.get("Content-Encoding"):
return resp
resp.direct_passthrough = False
if "br" in ae:
resp.set_data(brotli.compress(resp.get_data(), quality=5))
resp.headers["Content-Encoding"] = "br"
elif "gzip" in ae:
import gzip
buf = io.BytesIO()
with gzip.GzipFile(fileobj=buf, mode="wb", compresslevel=6) as gz:
gz.write(resp.get_data())
resp.set_data(buf.getvalue())
resp.headers["Content-Encoding"] = "gzip"
else:
return resp
resp.headers["Vary"] = "Accept-Encoding"
resp.headers.pop("Content-Length", None)
return resp
# ───────────────────── Reader UI ──────────────────────────────────────────
LANDING_HTML = """<!DOCTYPE html><html lang="en"><head>
<meta charset="UTF-8"><meta name="viewport" content="width=device-width,initial-scale=1">
<title>Cloud Reader</title>
<style>
body{background:#121212;color:#e0e0e0;font-family:sans-serif;margin:0;padding:20px}
.container{max-width:800px;margin:0 auto}
.input-box{max-width:420px;margin:0 auto 40px auto;text-align:center}
h1{text-align:center}
input,button{font-size:16px;border-radius:4px;padding:12px;width:100%}
input{border:1px solid #444;background:#222;color:#ddd;margin-bottom:12px}
button{background:#4285f4;color:#fff;border:none;cursor:pointer}
h2{border-bottom:1px solid #444;padding-bottom:10px;margin-top:0}
.history-grid{display:grid;grid-template-columns:repeat(auto-fill,minmax(150px,1fr));gap:20px}
.history-item a{text-decoration:none;color:#e0e0e0}
.history-item img{width:100%;aspect-ratio:2 / 3;object-fit:cover;border-radius:4px;background-color:#222}
.history-item p{margin:8px 0 0 0;font-size:14px;text-align:center;font-weight:700}
</style></head><body>
<div class="container">
<div class="input-box">
<h1>Cloud Reader</h1>
<form action="/reader" method="get">
<input type="url" name="url" placeholder="Paste chapter URL…" required>
<button type="submit">Load Chapter</button>
</form>
</div>
<div id="history-section">
<h2>Resume Reading</h2>
<div id="history-grid" class="history-grid"></div>
<p id="no-history" style="display:none;text-align:center;">Your reading history will appear here.</p>
</div>
</div>
<script>
document.addEventListener("DOMContentLoaded", function() {
const historyGrid = document.getElementById('history-grid');
const noHistoryMsg = document.getElementById('no-history');
const history = JSON.parse(localStorage.getItem('readingHistory') || '[]');
if (history.length === 0) {
noHistoryMsg.style.display = 'block';
} else {
history.forEach(item => {
const urlParam = encodeURIComponent(item.chapterUrl);
const historyItem = document.createElement('div');
historyItem.className = 'history-item';
historyItem.innerHTML = `
<a href="/reader?url=${urlParam}">
<img src="${item.coverUrl}" alt="${item.seriesTitle}" loading="lazy">
<p>${item.seriesTitle}</p>
</a>
`;
historyGrid.appendChild(historyItem);
});
}
});
</script>
</body></html>"""
body_css = """
body{margin:0;background:#000;font-family:sans-serif}
.page{position:relative;margin:0 auto;max-width:830px}
img{width:100%;display:block;opacity:0;filter:blur(8px);transition:opacity .3s ease,filter .4s ease;}
img.loaded{opacity:1;filter:blur(0);}
.placeholder{width:100%;padding-top:140%;background:url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 50 50'><circle cx='25' cy='25' r='20' stroke='%23666' stroke-width='4' fill='none' stroke-linecap='round'><animateTransform attributeName='transform' type='rotate' from='0 25 25' to='360 25 25' dur='1s' repeatCount='indefinite'/></circle></svg>") center/32px no-repeat #1e1e1e;animation:pulse 1.5s infinite;}
@keyframes pulse{0%{opacity:.6}50%{opacity:.3}100%{opacity:.6}}
.bad{background:#600!important}
#counter{position:fixed;top:8px;right:8px;font-size:14px;color:#eee;background:rgba(0,0,0,.6);padding:4px 8px;border-radius:4px;z-index:10;}
#nav-bar{position:fixed;bottom:0;left:0;right:0;background:rgba(20,20,20,.9);color:#fff;display:flex;justify-content:space-between;align-items:center;height:48px;padding:0 10px;z-index:10;-webkit-backdrop-filter:blur(5px);backdrop-filter:blur(5px);}
.nav-button{color:#fff;text-decoration:none;padding:8px 12px;border-radius:5px;background-color:rgba(50,50,50,.8);font-weight:700;display:flex;align-items:center;line-height:1;}
.nav-button:hover{background-color:#4285f4;}
.nav-center{display:flex;align-items:center;gap:8px;min-width:0;}
#chapter-title{font-size:14px;font-weight:700;white-space:nowrap;overflow:hidden;text-overflow:ellipsis;color:#fff;text-decoration:none;}
#chapter-select{background-color:rgba(50,50,50,.8);color:#fff;border:1px solid #555;border-radius:5px;padding:6px;font-size:14px;}
"""
# ───────────────── Reader JS ────────────────────
js_code = """
const imgs = [...document.querySelectorAll('.lazy')];
const total = imgs.length;
const BUFFER = 6;
const counter = document.getElementById('counter');
let shown = 0;
function upd(){ counter.textContent = `${shown}/${total}`; }
/* ---------- low-level load helper --------------------- */
function loadImg(img){
if (img.dataset.state === 'req') return;
img.dataset.state = 'req';
const ph = img.nextElementSibling;
img.src = img.dataset.src;
img.onload = () => { img.classList.add('loaded'); ph.remove(); shown++; upd(); };
img.onerror = () => { ph.classList.add('bad'); setTimeout(() => img.src = img.dataset.src, 3000); };
}
/* ---------- ensure we have a buffer ahead ------------ */
function warmAhead(idx){
for (let i = idx + 1; i <= idx + BUFFER && i < imgs.length; i++){
loadImg(imgs[i]);
}
}
/* ---------- observer to track current page ----------- */
const io = new IntersectionObserver(entries=>{
entries.forEach(e=>{
if (!e.isIntersecting) return;
const img = e.target;
const idx = imgs.indexOf(img);
/* on first intersection make sure it's loaded */
loadImg(img);
/* now warm the buffer ahead */
warmAhead(idx);
});
}, { rootMargin:'0px', threshold: 0.35 }); // 35 % of the img must be visible
imgs.forEach(img => io.observe(img));
upd();
/* ---------- eager boot-strap: load the first BUFFER --- */
warmAhead(-1);
/* ---------- keyboard navigation ---------------------- */
document.addEventListener('keydown', e=>{
if (e.key === 'ArrowRight') document.querySelector('.nav-button.next')?.click();
if (e.key === 'ArrowLeft') document.querySelector('.nav-button.prev')?.click();
if (e.key === 'ArrowDown') window.scrollBy({top:0.9*innerHeight, behavior:'smooth'});
if (e.key === 'ArrowUp') window.scrollBy({top:-0.9*innerHeight, behavior:'smooth'});
});
/* ---------- chapter dropdown ------------------------- */
function chapter_jump(sel){ if(sel.value) location.href = sel.value; }
"""
@app.route("/reader")
def reader():
url = request.args.get("url")
if not url:
return LANDING_HTML
try:
chapter_data = pick_adapter(url).pages(url)
except Exception as e:
return f"Adapter error: {e}", 400
pages_raw_list = chapter_data.get("image_urls", [])
series_title = chapter_data.get("series_title", "Comic")
chapter_title = chapter_data.get("chapter_title", "Reader")
next_chapter_url = chapter_data.get("next_chapter_url")
prev_chapter_url = chapter_data.get("prev_chapter_url")
series_url = chapter_data.get("series_url")
chapter_list = chapter_data.get("chapter_list", [])
current_url = chapter_data.get("current_chapter_url", url)
cover_url = chapter_data.get("cover_url")
hints = client_hints(request)
fmt = browser_fmt(request.headers.get("Accept",""), hints["ect"])
pages_html_parts = []
device, mw = parse_device(request.headers.get("User-Agent", ""))
mw = target_width(mw, hints)
if hints["save_data"] and mw:
mw = min(mw, 480)
for i, page_info in enumerate(pages_raw_list):
original_key = page_info["key"]
num_chunks = page_info.get("chunks", 1)
encoded_key = to_key(original_key)
if num_chunks > 1:
for chunk_num in range(1, num_chunks + 1):
data_src = f"/image/?u={encoded_key}&chunk={chunk_num}&w={mw or 0}&fmt={fmt}"
pages_html_parts.append(f"<div class='page'><img class='lazy' data-src='{data_src}' alt='Page {i+1} Chunk {chunk_num}'><div class='placeholder'></div></div>")
else:
data_src = f"/image/?u={encoded_key}&w={mw or 0}&fmt={fmt}"
fetch_priority = 'high' if i == 0 else 'low'
pages_html_parts.append(f"<div class='page'><img class='lazy' fetchpriority='{fetch_priority}' data-src='{data_src}' alt='Page {i+1}'><div class='placeholder'></div></div>")
pages_html = "\n".join(pages_html_parts)
import urllib.parse
import json
chapter_options = []
if chapter_list:
for chap in chapter_list:
reader_link = f"/reader?url={urllib.parse.quote_plus(chap['url'])}"
selected = 'selected' if chap['url'] == current_url else ''
chapter_options.append(f'<option value="{reader_link}" {selected}>{chap["text"]}</option>')
chapter_select_html = f'<select id="chapter-select" onchange="chapter_jump(this)">{"".join(chapter_options)}</select>'
nav_html_parts = ['<div id="nav-bar">']
if prev_chapter_url:
prev_url_encoded = urllib.parse.quote_plus(prev_chapter_url)
nav_html_parts.append(f'<a href="/reader?url={prev_url_encoded}" class="nav-button prev">‹ Prev</a>')
else:
nav_html_parts.append('<div></div>')
nav_html_parts.append('<div class="nav-center">')
if series_url:
nav_html_parts.append(f'<a id="chapter-title" href="{series_url}" target="_blank" title="{series_title}">{chapter_title}</a>')
else:
nav_html_parts.append(f'<span id="chapter-title">{chapter_title}</span>')
if chapter_list:
nav_html_parts.append(chapter_select_html)
nav_html_parts.append('</div>')
if next_chapter_url:
next_url_encoded = urllib.parse.quote_plus(next_chapter_url)
nav_html_parts.append(f'<a href="/reader?url={next_url_encoded}" class="nav-button next">Next ›</a>')
else:
nav_html_parts.append('<div></div>')
nav_html_parts.append('</div>')
nav_html = "\n".join(nav_html_parts)
history_script = ""
if series_title and current_url and cover_url:
history_data = {
"seriesTitle": series_title,
"chapterUrl": current_url,
"coverUrl": cover_url
}
history_script = f"""
<script>
(function() {{
const newItem = {json.dumps(history_data)};
let history = JSON.parse(localStorage.getItem('readingHistory') || '[]');
history = history.filter(item => item.seriesTitle !== newItem.seriesTitle);
history.unshift(newItem);
const historyLimit = 5;
history = history.slice(0, historyLimit);
localStorage.setItem('readingHistory', JSON.stringify(history));
}})();
</script>
"""
return f"""<!DOCTYPE html><html><head><link rel="preconnect" href="{IMAGE_HOST}">
<meta charset='utf-8'><meta name='viewport' content='width=device-width,initial-scale=1'>
<title>{series_title} - {chapter_title}</title><style>{body_css}</style></head><body>
<span id='counter'></span>
{pages_html}
{nav_html}
<script>{js_code}</script>
{history_script}
</body></html>"""
# ───────────────────── Stats / Health ────────────────────────────────────
@app.route("/stats")
def stats():
mb = sum(p.stat().st_size for p in CACHE_ROOT.rglob("*"))/1048576
return render_template_string("<h1>Cache {{m:.1f}} MB</h1>", m=mb)
@app.route("/health")
def health(): return "OK", 200
@app.route("/")
def index():
return LANDING_HTML
# ─────────────────────────── Run (dev) ───────────────────────────────────
if __name__ == "__main__":
app.run("0.0.0.0", 5000, threaded=True)