Daniel Sheffield 1 год назад
Родитель
Сommit
a137f443d9
3 измененных файлов с 25 добавлено и 5 удалено
  1. 17 1
      app/rest/pyapi.py
  2. 6 3
      app/rest/templates/clip-form.tpl
  3. 2 1
      app/rest/templates/paste.tpl

+ 17 - 1
app/rest/pyapi.py

@@ -140,6 +140,23 @@ def clip():
         if len(content) > CLIP_SIZE_LIMIT:
             return abort(418, f"Paste can not exceed {CLIP_SIZE_LIMIT}")
 
+        if request.params.copy == 'true':
+            response.content_type = 'text/html; charset=utf-8'
+            form = template(
+                'clip-form',
+                action='/clip',
+                method='post',
+                content=content,
+                disabled=False
+            )
+            return template(
+                'paste',
+                form=form,
+                link=f'{LOCATION}/clip',
+                disabled=False,
+                download=None
+            )
+
         _bytes = blake(content, person='clip'.encode('utf-8'))
         _b32 = bytes_to_base32(_bytes)
         directory = f'app/rest/static/{_b32}'
@@ -153,7 +170,6 @@ def clip():
 
         form = template('clip-form', action='/clip', method='post', content=content)
         response.content_type = 'text/html; charset=utf-8'
-        #return HTTPResponse(template('paste', form=form, link=f'{LOCATION}/clip/{_b32}'), 201)
         return redirect(f'/clip?hash={_b32}')
 
 def validate(filename: str) -> bytes:

+ 6 - 3
app/rest/templates/clip-form.tpl

@@ -1,6 +1,6 @@
 % from app.data.filter import get_query_param
 % content = setdefault("content", "") or ""
-% disabled = (setdefault("disabled", False) or "") and 'disabled="true"'
+% disabled = (setdefault("disabled", False) and 'readonly="true"') or ""
 <form id="paste" method="{{ method }}" action="{{ action }}">
   <style>
 textarea::-webkit-scrollbar {
@@ -31,5 +31,8 @@ textarea::-webkit-scrollbar-thumb {
     autofocus="true"
   >{{ content }}</textarea>
 </form>
-<form id="new" method="get" action="{{ action }}">
-</form>
+<form id="copy" method="post" action="{{ action }}">
+  <input id="copy-paste" name="paste" type="text" value="{{ content }}" hidden="true" />
+  <input id="copy" name="copy" type="text" value="true" hidden="true" />
+</form>
+<form id="new" method="get" action="{{ action }}"></form>

+ 2 - 1
app/rest/templates/paste.tpl

@@ -27,6 +27,7 @@ body {
       <div class="pure-u-1">
         <div class="pure-button-group" role="action" style="padding: 1em 0 0;">
           <button class="button-resize pure-button" type="submit" form="new"> New </button>
+          <button class="button-resize pure-button" type="submit" form="copy"> Edit as New </button>
           <button class="button-resize pure-button" type="submit" form="paste" {{!disabled}}> Paste </button>
           <button class="button-resize pure-button" type="submit" form="download" {{!download_disabled}}> Download </button>
         </div>
@@ -43,4 +44,4 @@ body {
       </div>
     </div>
   </body>
-</html>
+</html>