Bläddra i källkod

implement past and clip in sqlpage

Daniel Sheffield 4 månader sedan
förälder
incheckning
e32c87b9b5
6 ändrade filer med 97 tillägg och 0 borttagningar
  1. 63 0
      clip.sql
  2. 1 0
      rest/pyapi.py
  3. 10 0
      sqlpage/Link.sql
  4. 9 0
      sqlpage/QR.sql
  5. 10 0
      sqlpage/Style.sql
  6. 4 0
      sqlpage/link.sql

+ 63 - 0
clip.sql

@@ -0,0 +1,63 @@
+SELECT 'shell' AS component
+, 'dark' AS theme
+, 'Clip' AS title
+, 'https://shandan.one/static/clip/clip-favicon_square.svg' AS image
+, 'https://cdn.jsdelivr.net/npm/purecss@2.1.0/build/pure-min.css' AS css
+;
+SELECT 'dynamic' AS component, sqlpage.run_sql('sqlpage/Style.sql') AS properties;
+
+SET color = '#4f8f4f';
+SET tool = 'clip';
+SET hash = CASE $hash = ''
+  WHEN TRUE THEN NULL
+  ELSE $hash
+END;
+SET inner = CASE $hash IS NULL
+  WHEN TRUE THEN 'sqlpage/Link.sql'
+  ELSE 'sqlpage/link.sql'
+END;
+SELECT 'dynamic' AS component, sqlpage.run_sql($inner) AS properties;
+SELECT 'dynamic' AS component, sqlpage.run_sql('sqlpage/QR.sql') AS properties;
+
+SELECT 'form' AS component
+, '/clip' AS action
+, '' AS validate
+, 'post' AS method
+;
+SELECT 'Paste' AS value
+, '' AS label
+, 1 AS width
+, 'button' AS type
+, 'action' AS name
+;
+SELECT 'Edit as New' AS value
+, '' AS label
+, 2 AS width
+, 'button' AS type
+, 'action' AS name
+;
+SELECT 'New' AS value
+, '' AS label
+, 1 AS width
+, 'button' AS type
+, 'action' AS name
+, '/clip.sql' AS action
+;
+SELECT 'Open' AS value
+, '' AS label
+, 1 AS width
+, 'button' AS type
+, 'action' AS name
+, '/clip/open.sql' AS action
+;
+SELECT 'Download' AS value
+, '' AS label
+, 2 AS width
+, 'button' AS type
+, 'action' AS name
+;
+SELECT 'Paste something here...' AS placeholder
+, 'textarea' AS type
+, 'paste' AS name
+, '' AS label
+;

+ 1 - 0
rest/pyapi.py

@@ -37,6 +37,7 @@ def normalize():
 def validate_clip():
     _hash = request.params.hash
     ret = _validate(_hash, 'clip', root='rest/static/files').decode('utf-8')
+    response.content_type = 'application/json'
     return bottle.get(ret[0])(*ret[1:]) if isinstance(ret, tuple) else dumps({
         'i': _hash,
         'o': ret,

+ 10 - 0
sqlpage/Link.sql

@@ -0,0 +1,10 @@
+SET link = COALESCE($link, 'https://shandan.one/'||$tool);
+SELECT 'text' AS component
+, '<div class="pure-g" sty>
+  <div class="pure-u-1">
+    <div class="pure-button" style="margin: 1em 0 0; background: '||$color||';">
+      <a href="'||$link||'" style="color: floralwhite;">'||$link||'</a>
+    </div>
+  </div>
+</div>' AS html
+;

+ 9 - 0
sqlpage/QR.sql

@@ -0,0 +1,9 @@
+SET qr = COALESCE('https://shandan.one/'||$tool||'/'||$hash||'.qr', 'https://shandan.one/static/'||$tool||'/qr.svg');
+SELECT 'text' AS component
+, '<div class="pure-g" sty>
+  <div class="pure-u-1">
+    <details><summary>Show QR code ...</summary>
+    <img src="'||$qr||'"></details>
+  </div>
+</div>' AS html
+;

+ 10 - 0
sqlpage/Style.sql

@@ -0,0 +1,10 @@
+SELECT 'text' AS component
+, '<style>
+body {
+    text-align: center
+}
+details img {
+    background-color: white
+}
+</style>' AS html
+;

+ 4 - 0
sqlpage/link.sql

@@ -0,0 +1,4 @@
+SET url = 'https://shandan.one/normalize?hash=' || sqlpage.url_encode($hash);
+SET api_results = sqlpage.fetch($url);
+SET link = COALESCE('https://shandan.one/'||$tool||'/'||$api_results->>'o', NULL);
+SELECT 'dynamic' AS component, sqlpage.run_sql('sqlpage/Link.sql') AS properties;