Browse Source

remove unused code

Pi 4 months ago
parent
commit
cb45460cf2

+ 0 - 2
rest/pyapi.py

@@ -17,9 +17,7 @@ from itertools import chain
 from base64 import urlsafe_b64decode as b64decode
 from linkpreview import link_preview
 
-from .validate import CLIP_SIZE_LIMIT, get_file_mimetype, get_file_size, get_filename, validate_file
 from .hash_util import B32REGEX, normalize_base32, blake, bytes_to_base32
-from .save import save_upload
 from .qr import get_qr_code
 from json import dumps, load
 

+ 0 - 60
rest/save.py

@@ -1,60 +0,0 @@
-#
-# Copyright (c) Daniel Sheffield 2024
-# All rights reserved
-#
-# THIS SOFTWARE IS PROVIDED AS IS WITHOUT WARRANTY
-
-from io import BufferedRandom, BytesIO
-import os
-import shutil
-from uuid import uuid4
-
-from .hash_util import blake_file, bytes_to_base32
-from .qr import get_qr_code
-
-def save_qr(qr: bytes, _b32:str , directory: str) -> str:
-    fd = os.open(f'{directory}/{_b32}.qr', os.O_WRONLY | os.O_TRUNC | os.O_CREAT, 0o600)
-    with open(fd, "wb") as f:
-        f.write(qr)
-
-
-def save_filename(name: str, _b32: str, directory: str):
-    fd = os.open(f'{directory}/{_b32}.name', os.O_WRONLY | os.O_TRUNC | os.O_CREAT, 0o600)
-    with open(fd, "w") as f:
-        f.write(name)
-
-
-def save_upload(name: str, location: str, content: BufferedRandom, root='rest/static/files') -> str:
-    tmpdir = '/tmp/upload'
-    try:
-        os.mkdir(tmpdir, mode=0o700, dir_fd=None)
-    except FileExistsError:
-        pass
-    
-    unique = uuid4()
-    fd = os.open(f'{tmpdir}/{unique.hex}', os.O_WRONLY | os.O_TRUNC | os.O_CREAT, 0o600)
-    with open(fd, "wb") as f:
-        done = False
-        if isinstance(content, BytesIO):
-            f.write(content.getvalue())
-            done = True
-        while not done and content.peek(1):
-            seg = content.read(1024)
-            f.write(seg)
-    
-    _bytes = blake_file(unique.hex, person='upload'.encode('utf-8'), root=tmpdir)
-    _b32 = bytes_to_base32(_bytes)
-
-    directory = f'{root}/{_b32}'
-    try:
-        os.mkdir(directory, mode=0o700, dir_fd=None)
-    except FileExistsError:
-        pass
-
-    shutil.move(f'{tmpdir}/{unique.hex}', f'{directory}/{_b32}.file')
-    save_filename(name, _b32, directory)
-    link = f'{location}/upload/{_b32}'
-    svg = get_qr_code(link, fallback=link)
-    save_qr(svg, _b32, directory)
-
-    return _b32

+ 0 - 2
rest/templates/button-common.tpl

@@ -1,2 +0,0 @@
-% include('button-new')
-<button class="button-resize pure-button" type="submit" form="open"> Open </button>

+ 0 - 6
rest/templates/button-new.tpl

@@ -1,6 +0,0 @@
-% from rest.tool_color import color
-% setdefault('tool', None)
-% color = color.get(tool, None)
-% label = "New" if not tool else f"New {tool.title()}"
-% style = f'style="background-color: {color}"' if color else ''
-<button class="button-resize pure-button" type="submit" form="new" {{!style}}>{{ label }}</button>

+ 0 - 15
rest/templates/button-style.tpl

@@ -1,15 +0,0 @@
-<style>
-.button-resize { font-size: 80%; }
-@media screen and (min-width:35.5em){
-    .button-resize { font-size: 80%; }
-}
-@media screen and (min-width:40em){
-    .button-resize { font-size: 85%; }
-}
-@media screen and (min-width:64em){
-    .button-resize { font-size: 100%; }
-}
-@media screen and (min-width:80em){
-    .button-resize { font-size: 110%; }
-}
-</style>

+ 0 - 6
rest/templates/buttongroup-upload.tpl

@@ -1,6 +0,0 @@
-% from rest.tool_color import color
-<div class="pure-button-group" role="action" style="padding: 1em 0 0;">
-  <button class="button-resize pure-button" type="submit" form="upload" {{!disabled}} style="background-color: {{ color['upload'] }}"> Upload </button>
-  % include('button-common')
-  <button class="button-resize pure-button" type="submit" form="download" {{!download_disabled}}> Download </button>
-</div>

+ 0 - 2
rest/templates/form-common.tpl

@@ -1,2 +0,0 @@
-% include('form-new')
-<form id="open" method="get" action="{{ action }}/open"></form>

+ 0 - 1
rest/templates/form-new.tpl

@@ -1 +0,0 @@
-<form id="new" method="get" action="{{ action }}"></form>

+ 0 - 63
rest/templates/form-open.tpl

@@ -1,63 +0,0 @@
-% from rest.tool_color import color
-<!DOCTYPE html>
-<html>
-  <head>
-    <style>
-html {
-  --scrollbarBG: #333333;
-  --thumbBG: #080808;
-}
-body {
-  background-color: #080808;
-  color: #cccccc;
-}
-label span {
-    font-size: 2em;
-}
-input[type=text] {
-    font-size: 3em;
-    text-align: center;
-}
-button[type=submit] {
-    font-size: 1.5em;
-}
-form {
-    position: absolute;
-    top: 50vh;
-    height: 12em;
-    margin-top: -8em;
-    padding-bottom: 4em;
-    left: 50vw;
-    width: 15em;
-    margin-left: -7.5em;
-    display: inline-grid;
-}
-    </style>
-    <title>{{tool.title()}}</title>
-    <link rel="manifest" href="/static/{{tool}}/manifest.json"/>
-    <link rel="icon" href="/static/{{tool}}/48.png" />
-    <meta name="viewport" content="width=device-width, initial-scale=1"/>
-    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/purecss@2.1.0/build/pure-min.css" integrity="sha384-yHIFVG6ClnONEA5yB5DJXfW2/KC173DIQrYoZMEtBvGzmf0PKiGyNEqe9N6BNDBH" crossorigin="anonymous"/>
-    <link rel="stylesheet" href="https://shandan.one/css/grids-responsive-min.css"/>
-    <link rel="stylesheet" href="https://shandan.one/css/responsive-visibility-collapse.css"/>
-  </head>
-  <body style="text-align: center">
-      % include('form-new')
-      <form id="{{tool}}-open" action="{{action}}" method="{{method}}">
-        % include(f'button-new')
-        <input
-          type="text"
-          id="{{tool}}-code"
-          name="hash"
-          placeholder="C0DE"
-          required="true"
-          pattern="[A-TV-Za-tv-z0-9]{1,5}"
-          title="Base32 Code: Any of letters A-Z (excluding U) or digits 0-9.&#10;&#10;Note: O 0 and i I l L 1 can be used interchangeably"
-          size="5"
-          style="margin: 0.3em 0 0.3em"
-          autofocus="true"
-        ></input>
-        <button class="button-resize pure-button" type="submit" form="{{tool}}-open"> Submit </button>
-    </form>
-  </body>
-</html>

+ 0 - 6
rest/templates/form-upload.tpl

@@ -1,6 +0,0 @@
-% content = setdefault("content", "") or ""
-% disabled = setdefault("disabled", "") and 'hidden="true"'
-<form id="upload" method="{{ method }}" action="{{ action }}" enctype="multipart/form-data">
-  <input type="file" name="paste" required="true" {{disabled}} />
-</form>
-% include('form-common')

+ 0 - 70
rest/templates/upload.tpl

@@ -1,70 +0,0 @@
-% from rest.tool_color import color
-% link = setdefault("link", "") or ""
-% disabled = setdefault("disabled", "") and 'disabled="true"'
-% download_disabled = "" if disabled else 'disabled="true"'
-% mimetype = (setdefault("mimetype", None) is not True and mimetype) or None
-<!DOCTYPE html>
-<html>
-  <head>
-    <style>
-html {
-  --scrollbarBG: #333333;
-  --thumbBG: #080808;
-}
-body {
-  background-color: #080808;
-  color: #cccccc;
-}
-img {
-  background-color: floralwhite;
-  color: black;
-  max-height: min(100vh, calc(100vw * 9 / 16));
-  max-width: calc(100vw - 2em);
-}
-object {
-  width: 80%;
-  margin: 1em 0 0;
-}
-object.other {
-  height: 60vh;
-}
-object.text {
-  height: 60vh;
-  border: floralwhite;
-  border-style: solid;
-  border-width: thin;
-}
-    </style>
-    <title>Upload</title>
-    <link rel="manifest" href="/static/upload/manifest.json"/>
-    <link rel="icon" href="/static/upload/48.png" />
-    <meta name="viewport" content="width=device-width, initial-scale=1"/>
-    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/purecss@2.1.0/build/pure-min.css" integrity="sha384-yHIFVG6ClnONEA5yB5DJXfW2/KC173DIQrYoZMEtBvGzmf0PKiGyNEqe9N6BNDBH" crossorigin="anonymous"/>
-    <link rel="stylesheet" href="https://shandan.one/css/grids-responsive-min.css"/>
-    <link rel="stylesheet" href="https://shandan.one/css/responsive-visibility-collapse.css"/>
-  </head>
-  <body align="center" style="text-align: center">
-    <div class="pure-g">
-      <div class="pure-u-1">
-        % include('buttongroup-upload')
-      </div>
-      <div class="pure-u-1">
-        <div class="pure-button" style="margin: 1em 0 0; background: {{ color['upload'] }};">
-          <a href="{{link}}" style="color: floralwhite;">{{ link }}</a>
-        </div>
-      </div>
-      <div class="pure-u-1">
-        <p><details><summary> Show QR code ...</summary><img src="{{qr}}"/></details></p>
-{{!form}}
-<form id="download" method="get" action="{{link}}"></form>
-        % if mimetype and mimetype.startswith('text'):
-        <object class="text" data="{{link}}?download=false&mimetype=text/plain" type={{mimetype}}><p>Unable to display {{mimetype}}</p></object>
-        % elif mimetype and mimetype.startswith('image'):
-        <object data="{{link}}?download=false" type="{{mimetype}}"><p>Unable to display {{mimetype}}</p></object>
-        % elif mimetype:
-        <object class="other" data="{{link}}?download=false" type={{mimetype}}><p>Unable to display {{mimetype}}</p></object>
-        % end
-      </div>
-    </div>
-  </body>
-</html>