Browse Source

get pasted content too

Daniel Sheffield 4 months ago
parent
commit
05a728ede8

+ 2 - 44
home-sqlpage/clip.sql

@@ -4,9 +4,10 @@ SELECT 'shell' AS component
 , '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';
+SELECT 'dynamic' AS component, sqlpage.run_sql('sqlpage/Style.sql') AS properties;
+
 SET tool = 'clip';
 SET hash = CASE $hash = ''
   WHEN TRUE THEN NULL
@@ -17,46 +18,3 @@ SET inner = CASE $hash IS NULL
   ELSE 'sqlpage/link.sql'
 END;
 SELECT 'dynamic' AS component, sqlpage.run_sql($inner) AS properties;
-
-SELECT 'form' AS component
-, '/clip' AS action
-, '' AS validate
-, 'post' AS method
-;
-SELECT 'Paste' AS value
-, '' AS label
-, 1 AS width
-, 'submit' AS type
-, 'action' AS name
-;
-SELECT 'Edit as New' AS value
-, '' AS label
-, 2 AS width
-, 'submit' AS type
-, 'action' AS name
-;
-SELECT 'New' AS value
-, '' AS label
-, 1 AS width
-, 'submit' AS type
-, 'action' AS name
-, '/clip.sql' AS action
-;
-SELECT 'Open' AS value
-, '' AS label
-, 1 AS width
-, 'submit' AS type
-, 'action' AS name
-, '/clip/open.sql' AS action
-;
-SELECT 'Download' AS value
-, '' AS label
-, 2 AS width
-, 'submit' AS type
-, 'action' AS name
-;
-SELECT 'Paste something here...' AS placeholder
-, 'textarea' AS type
-, 'paste' AS name
-, '' AS label
-;

+ 6 - 1
home-sqlpage/sqlpage/Style.sql

@@ -1,10 +1,15 @@
 SELECT 'text' AS component
 , '<style>
-body {
+body .pure-g {
     text-align: center
 }
 details img {
     background-color: white
 }
+.code-component pre {
+    border-width: 2px;
+    border-color: '||$color||';
+    border-style: solid;
+}
 </style>' AS html
 ;

+ 8 - 1
home-sqlpage/sqlpage/link.sql

@@ -3,4 +3,11 @@ SET api_results = sqlpage.fetch($url);
 SET hash = $api_results->>'o';
 SET link = COALESCE('https://shandan.one/'||$tool||'/'||$hash, NULL);
 SELECT 'dynamic' AS component, sqlpage.run_sql('sqlpage/Link.sql') AS properties;
-SELECT 'dynamic' AS component, sqlpage.run_sql('sqlpage/QR.sql') AS properties;
+SELECT 'dynamic' AS component, sqlpage.run_sql('sqlpage/QR.sql') AS properties;
+
+SET content = NULL;
+SET inner = CASE $hash IS NULL
+  WHEN TRUE THEN $tool||'/form.sql'
+  ELSE 'sqlpage/validate.sql'
+END;
+SELECT 'dynamic' AS component, sqlpage.run_sql($inner) AS properties;

+ 5 - 0
home-sqlpage/sqlpage/status.sql

@@ -0,0 +1,5 @@
+SELECT 'alert' AS component
+, 'error-'||$status AS icon
+, $status||' - '||$info AS title
+, $url||' returned: '||$status||' - '||$info AS description
+;

+ 17 - 0
home-sqlpage/sqlpage/validate.sql

@@ -0,0 +1,17 @@
+SET url = 'https://shandan.one/clip/validate?hash=' || sqlpage.url_encode($hash);
+SET api_results = sqlpage.fetch($url);
+SET content = $api_results->>'o';
+SET err = $api_results->>'err';
+SET inner = CASE $err IS NULL
+  WHEN TRUE THEN $tool||'/form.sql'
+  ELSE 'sqlpage/status.sql'
+END;
+SET status = CASE $err IS NULL
+  WHEN TRUE THEN NULL
+  ELSE $err->>0
+END;
+SET info = CASE $err IS NULL
+  WHEN TRUE THEN NULL
+  ELSE $err->>1
+END;
+SELECT 'dynamic' AS component, sqlpage.run_sql($inner) AS properties;

+ 4 - 3
rest/pyapi.py

@@ -36,11 +36,12 @@ def normalize():
 @route('/clip/validate', method=['GET'])
 def validate_clip():
     _hash = request.params.hash
-    ret = _validate(_hash, 'clip', root='rest/static/files').decode('utf-8')
+    ret = _validate(_hash, 'clip', root='rest/static/files')
     response.content_type = 'application/json'
-    return bottle.get(ret[0])(*ret[1:]) if isinstance(ret, tuple) else dumps({
+    return dumps({
         'i': _hash,
-        'o': ret,
+        'o': ret.decode('utf-8') if isinstance(ret, bytes) else None,
+        'err': ret[1:] if isinstance(ret, tuple) else None
     })
 
 

+ 1 - 1
rest/validate.py

@@ -70,7 +70,7 @@ def _validate(filename: str, tool: str, root='rest/static/files') -> bytes:
 
 def validate(filename: str, tool: str, root='rest/static/files') -> bytes:
     ret = _validate(filename, tool, root)
-    return bottle.get(ret[0])(*ret[1:]) if isinstance(ret, tuple) else ret
+    return getattr(bottle, ret[0])(*ret[1:]) if isinstance(ret, tuple) else ret
 
 
 def get_filename(filename: str, root: str = 'rest/static/files'):