From f0af8d392a39816c90eb19c1af100a984319890d Mon Sep 17 00:00:00 2001 From: Olive Vaughn Date: Sun, 11 Oct 2026 00:42:53 -0400 Subject: [PATCH] arthur installs as an app, and keeps what projects load A manifest and icons make it installable. A service worker at /sw.js, so its scope is every page, keeps by kind of URL: content-addressed blobs and blocks for good, as projects load them; the versioned bundle and styles until the next build; and the last copy of the page, the API reads and other statics, for when there is no network. A project opened once opens again offline. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_011FLuCjp9kNH6ovwJVXSbq9 --- clips/templates/clips/index.html | 17 +++++ clips/tests/test_api.py | 11 +++ clips/views.py | 18 ++++- server/urls.py | 3 + static/arthur/icons/icon-180.png | Bin 0 -> 540 bytes static/arthur/icons/icon-192.png | Bin 0 -> 587 bytes static/arthur/icons/icon-512.png | Bin 0 -> 2348 bytes static/arthur/manifest.webmanifest | 15 ++++ static/arthur/sw.js | 109 +++++++++++++++++++++++++++++ 9 files changed, 172 insertions(+), 1 deletion(-) create mode 100644 static/arthur/icons/icon-180.png create mode 100644 static/arthur/icons/icon-192.png create mode 100644 static/arthur/icons/icon-512.png create mode 100644 static/arthur/manifest.webmanifest create mode 100644 static/arthur/sw.js diff --git a/clips/templates/clips/index.html b/clips/templates/clips/index.html index 9d87f04..a2d79b5 100644 --- a/clips/templates/clips/index.html +++ b/clips/templates/clips/index.html @@ -21,11 +21,28 @@ and PUTs with ordinary CSRF protection — no endpoint in this app is exempt. arthur + + + + + + {% csrf_token %}
+ diff --git a/clips/tests/test_api.py b/clips/tests/test_api.py index 5d2aa52..84fed0b 100644 --- a/clips/tests/test_api.py +++ b/clips/tests/test_api.py @@ -760,6 +760,17 @@ class PageTests(TestCase): # save path reads to write the X-CSRFToken header. self.assertIn("csrfmiddlewaretoken", body) + def test_the_service_worker_is_served_from_the_root(self): + # At the root so its scope is every page — a project is /p/ — and + # never cached, or a browser would keep an old worker for good. + response = self.client.get("/sw.js") + self.assertEqual(200, response.status_code) + self.assertEqual("application/javascript", response["Content-Type"]) + self.assertEqual("no-cache", response["Cache-Control"]) + body = self.client.get("/").content.decode() + self.assertIn("manifest.webmanifest", body) + self.assertIn("serviceWorker.register('/sw.js')", body) + def test_the_detector_reports_a_version_derived_from_the_model(self): # The version is the package version plus the model asset's own hash, # because a version string in the client is one somebody has to remember to diff --git a/clips/views.py b/clips/views.py index 1f6306e..ba12b18 100644 --- a/clips/views.py +++ b/clips/views.py @@ -37,7 +37,7 @@ from django.contrib.auth import login as auth_login, logout as auth_logout from django.core.exceptions import ValidationError from django.db import transaction from django.db.models import Q -from django.http import FileResponse, HttpResponse, JsonResponse +from django.http import FileResponse, Http404, HttpResponse, JsonResponse from django.shortcuts import render from django.views.decorators.http import require_http_methods @@ -146,6 +146,22 @@ def page(request, project_id=None, slug=None): }) +def service_worker(request): + """`static/arthur/sw.js`, at the root of the site. + + A service worker controls only the paths under where it is served from, and + a project is `/p/`, so `/static/arthur/sw.js` would control nothing that + matters. Never cached itself: a browser compares this file to decide whether + there is a new worker, so a stale copy would keep the old one for good.""" + for root in settings.STATICFILES_DIRS: + path = Path(root) / "arthur" / "sw.js" + if path.exists(): + response = HttpResponse(path.read_bytes(), content_type="application/javascript") + response["Cache-Control"] = "no-cache" + return response + raise Http404("no service worker") + + # --------------------------------------------------------------------------- # the detector # diff --git a/server/urls.py b/server/urls.py index 6c42133..1ff70e4 100644 --- a/server/urls.py +++ b/server/urls.py @@ -14,6 +14,9 @@ urlpatterns = [ # same page; the client reads the id out of the path and opens it. path("p/", views.page), path("p//", views.page), + # The service worker, at the root so it can control every page; see + # `views.service_worker`. + path("sw.js", views.service_worker), path("api/", include("clips.urls")), path("blob/", views.blob, name="blob"), path("admin/", admin.site.urls), diff --git a/static/arthur/icons/icon-180.png b/static/arthur/icons/icon-180.png new file mode 100644 index 0000000000000000000000000000000000000000..25c6367b17fb60ced071fcbe1a9feba2a40f0f46 GIT binary patch literal 540 zcmeAS@N?(olHy`uVBq!ia0vp^TR@nD2}o{QKQWbof$_1Yi(^Q|t+#hK3N{C9AcV-H8S>rx4#N2enFEaO z-?x4LY;KX)yErq6MYSO0k;TbHT^us07J4T_$0aPR zPI-J_beHRUXSApmWYkrQrj(Xn4a|HN4;qqvWEL7dszJ5^29!JUa_Y9*(wQ> zG=g|rmFdztW>8=P!xmr2F?ixp!!QXL;J_#$pe86&zve;2OPjY_fvJOm!PC{xWt~$( F695@Ej3@vA literal 0 HcmV?d00001 diff --git a/static/arthur/icons/icon-512.png b/static/arthur/icons/icon-512.png new file mode 100644 index 0000000000000000000000000000000000000000..48019805b21aa69abc638ce20b6e6bcb9288f90e GIT binary patch literal 2348 zcmcIlT}V@57=F(-?QA8jWfv`~bCU*ET8l2i?4*-YWN3L2UDPPFAMM5p28Dd|Ls&Q6 zgp&fj=%x#|grFc$38F5fU09I)F$y9uV-$fHM$h|w+i{z-WGg+K^L_98{Jh`qdYS`! zOI%(T5tTIT^Y16Jp=l$XKj*!5gGBoG2LGPc(Cev}EzZl$rS&Zp)5q<*r;a)8O?P{O zzSC9u2jk1RgUz&n7{XZw;vQ$)?<6)ur<79?Sc%Vr?3`!;7E;VEo zz@)*IzZFncIrx%l!BRqso%@|;z6dy^Pl(CN?9#GDvS7UOsSy-E{Dr1f;(!(z;q_I3 zIUR3&W@)OYz|xm-ijtl*?`buMVMMpNJ)Rg9plOncC9*>PXMjyB&uXIhku1Idv zYbA-B%KS<3w4V==TO74t=$93mLt0J1(k+v^&7C6Vk#f)4Mwd8Kavi+oP3l^mSj)p> zW-Xr>fIea%1`T>br}#)2y;`h-H}d_)_*T^57LCiRdwB|2UT0r}r%T`_Nd^&DLrD%y zb)>UIbNv}9tAjMlA`, `/api/blocks/` — is named by its +// own hash, so a copy cannot be stale: cache first, keep for good. These are +// a project's frames, footage and drawings, cached as they load. +// - VERSIONED — the bundle and the stylesheet, `?v=` — is a new URL +// for every build: cache first, and drop the versions it replaces. +// - EVERYTHING ELSE of ours — the page, `/api/` reads, unversioned statics — +// can change under the same URL: the network first, the last copy offline. +// +// A Range request is left to the browser: a `