Kaynağa Gözat

scan barcodes with Binary Eye and POST to sqlpage

Pi 4 ay önce
ebeveyn
işleme
7a514cd1e4

+ 2 - 0
util-sqlpage/code.sql

@@ -0,0 +1,2 @@
+SET inner = 'code/Index.sql';
+SELECT 'dynamic' AS component, sqlpage.run_sql('code/entry.sql') AS properties;

+ 14 - 0
util-sqlpage/code/Index.sql

@@ -0,0 +1,14 @@
+SELECT 'dynamic' AS component, sqlpage.run_sql('sqlpage/Style.sql') AS properties;
+
+SET json = sqlpage.variables('post');
+
+SET inner = CASE (SELECT 1 FROM json_each($json) LIMIT 1)
+  WHEN 1 THEN 'code/save.sql'
+  ELSE 'code/recent.sql'
+END;
+--  ELSE CASE COALESCE($hash,'') = ''
+--    WHEN TRUE THEN 'sqlpage/Link.sql'
+--    ELSE 'sqlpage/link.sql'
+--  END
+--END;
+SELECT 'dynamic' AS component, sqlpage.run_sql($inner) AS properties;

+ 9 - 0
util-sqlpage/code/entry.sql

@@ -0,0 +1,9 @@
+SET title = 'Code';
+SET tool = 'code';
+SET color = '#f59f00';
+SET tabler_color = 'azure';
+--SET image = '/static/upload/upload-favicon_square.svg';
+--SET favicon = $image;
+--SET manifest = '/static/upload/manifest.json';
+SELECT 'dynamic' AS component, sqlpage.run_sql('sqlpage/theme.sql') AS properties;
+SELECT 'dynamic' AS component, sqlpage.run_sql($inner) AS properties;

+ 2 - 0
util-sqlpage/code/recent.sql

@@ -0,0 +1,2 @@
+SELECT 'table' AS component;
+SELECT hash, content, created FROM code;

+ 32 - 0
util-sqlpage/code/save.sql

@@ -0,0 +1,32 @@
+SET request = json_object(
+    'method', 'POST',
+    'url', 'https://shandan.one/hash',
+    'headers', json_object(),
+    'body', json_object(
+        'data', $json,
+        'person', $tool
+    )
+);
+SET hash = sqlpage.fetch($request);
+SET fallback = 'https://shandan.one/upload/' || sqlpage.url_encode($hash);
+SET request = json_object(
+    'method', 'POST',
+    'url', 'https://shandan.one/qr',
+    'headers', json_object(),
+    'body', json_object(
+        'data', $json,
+        'fallback', $fallback
+    )
+);
+SET qr = sqlpage.fetch($request);
+INSERT INTO code(hash, content, svg, created)
+VALUES ($hash, $json, $qr, CURRENT_TIMESTAMP)
+ON CONFLICT DO
+UPDATE SET
+  content = excluded.content,
+  created = excluded.created,
+  svg = excluded.svg
+WHERE excluded.created > code.created;
+SELECT 'text' AS component;
+SELECT $json AS contents;
+--SELECT 'dynamic' AS component, sqlpage.run_sql('sqlpage/link.sql') AS properties;

+ 7 - 0
util-sqlpage/sqlpage/migrations/006_code.sql

@@ -0,0 +1,7 @@
+DROP TABLE IF EXISTS code;
+CREATE TABLE IF NOT EXISTS code(
+  hash text PRIMARY KEY,
+  content text,
+  svg text,
+  created timestamp
+);