Ver código fonte

Add SQLite availability check and platform stubs

Add platform build tags and a no-op SQLite stub for platforms where modernc.org/libc/sqlite lacks a C-runtime port (e.g. linux/mipsle, windows/arm). Update tests to use matching build constraints. Expose a new API action ('available') so callers can probe SQLite support without opening a DB. Update the SQLite Admin UI: add a banner and CSS to inform users when SQLite is unavailable, and JS to probe the API on load and disable the open button when unsupported. Files changed: agi/agi.sqlite.go, agi/agi.sqlite_stub.go (new), agi/agi_sqlite_test.go, web/SQLite Admin/backend/api.agi, web/SQLite Admin/index.html.
Toby Chui 1 semana atrás
pai
commit
1a98598dd4

+ 2 - 0
src/mod/agi/agi.sqlite.go

@@ -1,3 +1,5 @@
+//go:build !(linux && mipsle) && !(windows && arm)
+
 package agi
 
 import (

+ 8 - 0
src/mod/agi/agi.sqlite_stub.go

@@ -0,0 +1,8 @@
+//go:build (linux && mipsle) || (windows && arm)
+
+package agi
+
+// SQLiteLibRegister is a no-op on platforms where modernc.org/libc/sqlite
+// does not provide a C-runtime port (e.g. linux/mipsle, windows/arm).
+// requirelib("sqlite") will return false in AGI scripts on these platforms.
+func (g *Gateway) SQLiteLibRegister() {}

+ 2 - 0
src/mod/agi/agi_sqlite_test.go

@@ -1,3 +1,5 @@
+//go:build !(linux && mipsle) && !(windows && arm)
+
 package agi
 
 import (

+ 6 - 0
src/web/SQLite Admin/backend/api.agi

@@ -29,6 +29,12 @@ if (typeof action === "undefined" || action === "") {
     exit(0);
 }
 
+// available — no db required; lets callers probe library support before opening a file
+if (action === "available") {
+    respond({available: true});
+    exit(0);
+}
+
 if (typeof db === "undefined" || db === "") {
     respond({error: "Missing parameter: db"});
     exit(0);

+ 34 - 0
src/web/SQLite Admin/index.html

@@ -477,6 +477,21 @@
         }
         #toast.show { opacity: 1; }
         #toast.error { background: var(--danger); }
+
+        /* ── SQLite-unavailable banner ───────────────────── */
+        #not-supported-banner {
+            display: none;
+            margin: 0 0 12px 0;
+            padding: 12px 16px;
+            background: #fff3cd; color: #7d5800;
+            border: 1px solid #ffc107;
+            border-radius: 8px;
+            font-size: 13px;
+            line-height: 1.5;
+            text-align: center;
+        }
+        #not-supported-banner.show { display: block; }
+        #not-supported-banner strong { display: block; margin-bottom: 4px; font-size: 14px; }
     </style>
 </head>
 <body>
@@ -512,6 +527,10 @@
 
         <!-- Welcome screen (shown before any DB is open) -->
         <div id="welcome">
+            <div id="not-supported-banner">
+                <strong>SQLite not available on this platform</strong>
+                The SQLite library could not be loaded on this server. This feature requires a platform supported by the SQLite backend (linux/amd64, linux/arm64, darwin, windows/amd64, windows/arm64, and others). OpenWRT (linux/mipsle) and other embedded targets are not supported.
+            </div>
             <svg width="72" height="72" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round">
                 <ellipse cx="12" cy="5" rx="9" ry="3"/>
                 <path d="M21 12c0 1.657-4.03 3-9 3s-9-1.343-9-3"/>
@@ -662,6 +681,21 @@ function api(params, cb) {
     });
 }
 
+// Probe SQLite availability on load; show banner and disable open button if unsupported
+(function checkSQLiteAvailability() {
+    api({action: 'available'}, function(err, data) {
+        var unavailable = (err) ||
+                          (data && data.error &&
+                           data.error.indexOf('not available') !== -1);
+        if (unavailable) {
+            document.getElementById('not-supported-banner').classList.add('show');
+            document.getElementById('btn-open-db').disabled = true;
+            document.getElementById('btn-open-db').title =
+                'SQLite is not supported on this platform';
+        }
+    });
+}());
+
 function escapeHtml(s) {
     if (s === null || s === undefined) return '';
     return String(s)