Serveur : surveillance des nouvelles versions d'Excalidraw (/api/update)

- Le serveur interroge le registre npm (@excalidraw/excalidraw, dist-tag
  latest) au démarrage puis toutes les 12 h ; GET /api/update.
  UPDATE_CHECK=false désactive, NPM_REGISTRY permet un miroir ; sans réseau,
  la dernière valeur connue est gardée.
- Dockerfile/compose : argument de build EXCALIDRAW_VERSION pour reconstruire
  l'image avec une autre version sans modifier le dépôt.
- README : style Excalidraw, import de dossiers, mise à jour d'Excalidraw.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019EuvvuTv7AUc8ksDHv8VKx
This commit is contained in:
claude BotandClaude Opus 5.5 committed 2026-10-07 15:45:17 +02:00
1 parent 9ecaab550a
commit 49a816bb12
8 files changed
+225 -7

No files matched your search

+56
View File
@@ -0,0 +1,56 @@
package update
import (
"context"
"net/http"
"net/http/httptest"
"testing"
"time"
)
func TestCheck(t *testing.T) {
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if r.URL.Path != "/@excalidraw/excalidraw/latest" {
http.NotFound(w, r)
return
}
_, _ = w.Write([]byte(`{"name":"@excalidraw/excalidraw","version":"0.19.0"}`))
}))
defer srv.Close()
c := &Checker{Registry: srv.URL, Interval: time.Hour, Client: srv.Client()}
if s := c.Status(); !s.Enabled || s.Latest != "" {
t.Fatalf("avant vérification : %+v", s)
}
c.check(context.Background())
if s := c.Status(); s.Latest != "0.19.0" || s.CheckedAt == nil {
t.Fatalf("après vérification : %+v", s)
}
}
func TestCheckKeepsLastValueOnError(t *testing.T) {
ok := true
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if !ok {
http.Error(w, "panne", http.StatusBadGateway)
return
}
_, _ = w.Write([]byte(`{"version":"0.18.2"}`))
}))
defer srv.Close()
c := &Checker{Registry: srv.URL, Interval: time.Hour, Client: srv.Client()}
c.check(context.Background())
ok = false
c.check(context.Background())
if s := c.Status(); s.Latest != "0.18.2" {
t.Fatalf("valeur perdue après une erreur : %+v", s)
}
}
func TestNilCheckerIsDisabled(t *testing.T) {
var c *Checker
if s := c.Status(); s.Enabled {
t.Fatalf("checker nil : %+v", s)
}
}