vodkas

Simple file sharing server
Log | Files | Refs

templates.go (1726B)


      1 // TODO: A better alternative to this inline HTML stuff:
      2 //       https://odino.org/bundling-static-files-within-your-golang-app/
      3 package main
      4 
      5 import "html/template"
      6 
      7 
      8 // I think template data variables must be exported (upper case) in order to be usable
      9 var uploadPageTemplate = template.Must(template.New("uploadPage").Parse(`
     10 <!DOCTYPE html>
     11 <html>
     12 <head>
     13     <style>
     14         textarea { width: 100%; }
     15     </style>
     16 
     17 </head>
     18 <body>
     19 <h1>Upload to /{{.ShotKey}}</h1>
     20 
     21 <form action="/{{.ShotKey}}" method="POST" onreset="formReset()" enctype="multipart/form-data">
     22     <label for="input-numdls">Number of downloads</label><br>
     23     <input value="1" type="number" id="input-numdls" name="numdls"><br>
     24     <p>
     25         <label for="input-file">File dump</label><br>
     26         <input type="file" id="input-file" name="file" style="width: 100%;"
     27                oninput="inputChanged(this, '#input-text')"><br>
     28         <b>or</b><br>
     29         <label for="input-text">Text dump</label><br>
     30         <textarea id="input-text" name="text" rows="15"
     31                   oninput="inputChanged(this, '#input-file')"></textarea><br>
     32     </p>
     33     <input type="reset" value="Reset">
     34     <input type="submit" value="Submit">
     35 </form>
     36 
     37 <script>
     38     function formReset() {
     39         document.querySelector("#input-text").removeAttribute("disabled");
     40         document.querySelector("#input-file").removeAttribute("disabled");
     41     }
     42     function inputChanged(changedInput, otherInputId) {
     43         const otherInput = document.querySelector(otherInputId);
     44         if (changedInput.value) {
     45             otherInput.setAttribute("disabled", true);
     46         } else {
     47             otherInput.removeAttribute("disabled");
     48         }
     49     }
     50 </script>
     51 </body>
     52 </html>
     53 `))