Pi před 4 měsíci
rodič
revize
e4a8087ad8

+ 5 - 0
util-sqlpage/goto/download.sql

@@ -0,0 +1,5 @@
+SET content = (SELECT content FROM clip WHERE hash = $hash);
+SELECT 'shell-empty' AS component;
+SELECT 'text' AS component
+, $content AS html
+;

+ 34 - 0
util-sqlpage/goto/form.sql

@@ -0,0 +1,34 @@
+SELECT 'dynamic' AS component, sqlpage.run_sql('sqlpage/QR.sql') AS properties;
+SET view = COALESCE($content, '') <> '' AND COALESCE($action, '') <> ('Shrtn It!');
+SELECT 'button' AS component;
+SELECT 'Open' AS title
+, 1 AS width
+, $tabler_color AS color
+, '/goto/open.sql?' AS link
+;
+SELECT 'New' AS title
+, 1 AS width
+, 'gray-500' AS color
+, 'https://shandan.one/goto.sql?' AS link
+;
+
+SELECT 'form' AS component
+, '/goto.sql' AS action
+, '' AS validate
+, 'post' AS method
+WHERE NOT $view
+;
+SELECT 'Shrtn It!' AS value
+, '' AS label
+, 1 AS width
+, 'submit' type
+, 'action' AS name
+WHERE NOT $view
+;
+SELECT 'content' AS name
+, '' AS label
+, 'input' AS type
+, $content AS value
+WHERE NOT $view
+;
+--TODO: preview

+ 55 - 0
util-sqlpage/goto/open.sql

@@ -0,0 +1,55 @@
+SELECT 'shell' AS component
+, 'dark' AS theme
+, 'Goto' AS title
+, 'https://shandan.one/static/goto/goto-favicon_square.svg' AS image
+, 'https://cdn.jsdelivr.net/npm/purecss@2.1.0/build/pure-min.css' AS css
+;
+SELECT 'text' AS component
+, '<style>
+.form-fieldset {
+    border: none;
+}
+.form-fieldset .row {
+    align-items: center;
+    justify-content: center;
+}
+input[name=hash] {
+    text-align: center;
+}
+</style>' AS html
+;
+SET color = '#8f4f4f';
+SET tabler_color = 'google';
+SELECT 'button' AS component
+, 'center' AS justify
+, 'lg' AS size
+;
+SELECT 'New GoTo' AS title
+, 2 AS width
+, $tabler_color AS color
+, '/goto.sql?' AS link
+;
+SELECT 'form' AS component
+, 'open-goto' AS id
+, '/clip.sql' AS action
+, '' AS validate
+, 'get' AS method
+;
+SELECT 'C0DE' AS placeholder
+, 'input' AS type
+, '' AS label
+, 'hash' AS name
+, 2 AS width
+, TRUE AS autofocus
+;
+SELECT 'button' AS component
+, 'center' AS justify
+, 'lg' AS size
+, 2 AS width
+;
+SELECT 'Submit' AS title
+, 1 AS width
+, 'gray-500' AS color
+, '/goto.sql?' AS link
+, 'open-goto' AS form
+;

+ 29 - 0
util-sqlpage/goto/save.sql

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

+ 9 - 1
util-sqlpage/sqlpage/validate.sql

@@ -1,4 +1,12 @@
-SET content = (SELECT content FROM clip WHERE hash = $hash);
+SET content = (
+SELECT content
+FROM clip
+WHERE hash = $hash AND $tool = 'clip'
+UNION
+SELECT content
+FROM goto
+WHERE hash = $hash AND $tool = 'goto'
+);
 
 SET inner = CASE COALESCE($content,'') = ''
   WHEN TRUE THEN 'sqlpage/alert.sql'