tMove example site and config into its own directory - partage - File upload system
 (HTM) git clone git://git.z3bra.org/partage.git
 (DIR) Log
 (DIR) Files
 (DIR) Refs
 (DIR) README
 (DIR) LICENSE
       ---
 (DIR) commit 8f1f9b5cd01c58ed94a0ebfb3bd685983d047bc7
 (DIR) parent 5cf182f6f8ce9e5fa2ace974c8f9378c1ce8fdf4
 (HTM) Author: Willy Goiffon <dev@z3bra.org>
       Date:   Wed, 20 Oct 2021 22:37:21 +0200
       
       Move example site and config into its own directory
       
       Diffstat:
         A example/partage.conf                |      36 +++++++++++++++++++++++++++++++
         A example/static/dz.js                |      88 +++++++++++++++++++++++++++++++
         R static/favicon.ico -> example/stat… |       0 
         R static/partage.css -> example/stat… |       0 
         R static/partage.png -> example/stat… |       0 
         R static/robots.txt -> example/stati… |       0 
         A example/templates/index.html        |      39 +++++++++++++++++++++++++++++++
         A example/templates/upload.html       |      22 ++++++++++++++++++++++
         D static/dz.js                        |      85 -------------------------------
         D templates/index.html                |      39 -------------------------------
         D templates/upload.html               |      22 ----------------------
       
       11 files changed, 185 insertions(+), 146 deletions(-)
       ---
 (DIR) diff --git a/example/partage.conf b/example/partage.conf
       t@@ -0,0 +1,36 @@
       +# TCP or unix Socket to listen on.
       +# When unix sockets are used, the content will be served over FastCGI.
       +#listen = /var/run/partage-fcgi.sock
       +listen = 127.0.0.1:9000
       +
       +# Base to use when constructing URI to files uploaded.
       +# The full URI must be specified, in the form SCHEME://HOST[:PORT]
       +baseuri = http://127.0.0.1:9000
       +
       +# Drop privilege to the user and group specified.
       +# When only the user is specified, the default group of the user will
       +# be used.
       +#user = www
       +#group = daemon
       +
       +# Change the root directory to the following directory.
       +# When a chroot is set, all path must be given according to the chroot.
       +# Note: the configuration file is read before chrooting.
       +#chroot = /var/www
       +
       +# Path to the different path used by the server. Must take into account
       +# the chroot if set.
       +rootdir = example/static
       +tmplpath = example/templates
       +filepath = example/files
       +metapath = example/meta
       +
       +# URI context that files will be served on
       +filectx = /f/
       +
       +# Maximum per-file upload size (in bytes)
       +maxsize = 536870912 # 512Mib
       +
       +# Default expiration time (in seconds). An expiration time of 0 seconds
       +# means no expiration.
       +expiry = 86400 # 24 hours
 (DIR) diff --git a/example/static/dz.js b/example/static/dz.js
       t@@ -0,0 +1,88 @@
       +// Handle drag and drop into a dropzone_element div:
       +// send the files as a POST request to the server
       +"use strict";
       +
       +// Only start once the DOM tree is ready
       +if(document.readyState === "complete") {
       +    setupzone();
       +} else {
       +    document.addEventListener("DOMContentLoaded", setupzone);
       +}
       +
       +function setupzone() {
       +    let dropzone = document.getElementById("dropzone");
       +    let fileinput = document.getElementById("filebox");
       +    let fallbackform = document.getElementById("fallbackform");
       +
       +    fallbackform.style.display = "none";
       +
       +    dropzone.className = "dropzone";
       +    dropzone.innerHTML = "Click or drop file(s)";
       +
       +    dropzone.onclick = function() {
       +        fileinput.click()
       +        return false;
       +    }
       +
       +    dropzone.ondragover = function() {
       +        this.className = "dropzone dragover";
       +        return false;
       +    }
       +    
       +    dropzone.ondragleave = function() {
       +        this.className = "dropzone";
       +        return false;
       +    }
       +
       +    dropzone.ondrop = function(e) {
       +        // Stop browser from simply opening that was just dropped
       +        e.preventDefault();  
       +        // Restore original dropzone appearance
       +        this.className = "dropzone";
       +        sendfiles(e.dataTransfer.files)
       +    }
       +
       +    fileinput.onchange = function(e) {
       +        sendfiles(this.files)
       +    }
       +}
       +
       +function sendfiles(files) {
       +    let uploads = document.getElementById("uploads");
       +    let progressbar = document.createElement("progress");
       +    let uploadlist = document.createElement("ul");
       +    let formData = new FormData(), xhr = new XMLHttpRequest();
       +
       +    uploads.appendChild(progressbar);
       +    uploads.appendChild(uploadlist);
       +
       +    formData.append("expiry", 10);
       +    for(let i=0; i < files.length; i++) {
       +        formData.append("file", files[i]);
       +    }
       +
       +    // triggers periodically
       +    xhr.upload.onprogress = function(e) {
       +        // e.loaded - how many bytes downloaded
       +        // e.lengthComputable = true if the server sent Content-Length header
       +        // e.total - total number of bytes (if lengthComputable)
       +        if (e.lengthComputable) {
       +                progressbar.max = e.total
       +        }
       +        progressbar.value = e.loaded
       +    }
       +
       +    xhr.onreadystatechange = function() {
       +        if(xhr.readyState === XMLHttpRequest.DONE) {
       +                progressbar.remove();
       +                this.response.split(/\r?\n/).forEach(function(link) {
       +                        let li = document.createElement("li");
       +                        li.innerHTML = `<a href="${link}">${link}</a>`;
       +                        uploadlist.appendChild(li);
       +                });
       +        }
       +    }
       +
       +    xhr.open('POST', window.location.href, true); // async = true
       +    xhr.send(formData); 
       +}
 (DIR) diff --git a/static/favicon.ico b/example/static/favicon.ico
       Binary files differ.
 (DIR) diff --git a/static/partage.css b/example/static/partage.css
 (DIR) diff --git a/static/partage.png b/example/static/partage.png
       Binary files differ.
 (DIR) diff --git a/static/robots.txt b/example/static/robots.txt
 (DIR) diff --git a/example/templates/index.html b/example/templates/index.html
       t@@ -0,0 +1,39 @@
       +<!DOCTYPE HTML>
       +<html>
       +<head>
       +        <meta charset="utf-8">
       +        <meta name="author" content="z3bra">
       +        <meta name="robots" content="noindex,nofollow" />
       +        <meta name="viewport" content="width=device-width">
       +        <link rel="stylesheet" type="text/css" href="/partage.css" />
       +        <link rel="icon" type="image/ico" href="/favicon.ico" />
       +        <title>Partage</title>
       +</head>
       +<body>
       +        <header>
       +                <img id="logo" src="/partage.png" />
       +                <h1>partage</h1>
       +        </header>
       +        <form enctype="multipart/form-data" method="post">
       +                <div id="dropzone"></div>
       +                <div id="fallbackform" class="dropzone">
       +                        <input id="filebox" name="file" type="file" multiple/>
       +                        <input id="output" name="output" type="hidden" value='html' />
       +                        <input type="submit" value="Upload"/>
       +                </div>
       +                <section id="formsettings">
       +                        <label for="expiry"> Destroy after </label>
       +                        <select id="expiry" name="expiry">
       +                                <option value="900"> 15 minutes </option>
       +                                <option value="3600"> 1 hour </option>
       +                                <option value="28800"> 8 hours </option>
       +                                <option value="86400" selected> 1 day </option>
       +                                <option value="604800"> 1 week </option>
       +                        </select>
       +                </section>
       +        </form>
       +        <p>File size limited to {{.Maxsize}}.</p>
       +        <div id="uploads"></div>
       +        <script src="/dz.js"></script>
       +</body>
       +</html>
 (DIR) diff --git a/example/templates/upload.html b/example/templates/upload.html
       t@@ -0,0 +1,22 @@
       +<!DOCTYPE HTML>
       +<html>
       +<head>
       +        <meta charset="utf-8">
       +        <meta name="author" content="z3bra">
       +        <meta name="viewport" content="width=device-width">
       +        <link rel="stylesheet" type="text/css" href="/partage.css" />
       +        <link rel="icon" type="image/ico" href="/favicon.ico" />
       +        <title>Partage</title>
       +</head>
       +<body>
       +        <header>
       +                <img id="logo" src="/partage.png" />
       +                <h1>partage</h1>
       +        </header>
       +        <ul>
       +        {{range .Links}}
       +          <li><a href="{{.}}">{{.}}</a></li>
       +        {{end}}
       +        </ul>
       +</body>
       +</html>
 (DIR) diff --git a/static/dz.js b/static/dz.js
       t@@ -1,85 +0,0 @@
       -// Handle drag and drop into a dropzone_element div:
       -// send the files as a POST request to the server
       -"use strict";
       -
       -// Only start once the DOM tree is ready
       -if(document.readyState === "complete") {
       -    setupzone();
       -} else {
       -    document.addEventListener("DOMContentLoaded", setupzone);
       -}
       -
       -function setupzone() {
       -    let dropzone = document.getElementById("dropzone");
       -    let fileinput = document.getElementById("filebox");
       -    let fallbackform = document.getElementById("fallbackform");
       -
       -    fallbackform.style.display = "none";
       -
       -    dropzone.className = "dropzone";
       -    dropzone.innerHTML = "Click or drop file(s)";
       -
       -    dropzone.onclick = function() {
       -        fileinput.click()
       -        return false;
       -    }
       -
       -    dropzone.ondragover = function() {
       -        this.className = "dropzone dragover";
       -        return false;
       -    }
       -    
       -    dropzone.ondragleave = function() {
       -        this.className = "dropzone";
       -        return false;
       -    }
       -
       -    dropzone.ondrop = function(e) {
       -        // Stop browser from simply opening that was just dropped
       -        e.preventDefault();  
       -        // Restore original dropzone appearance
       -        this.className = "dropzone";
       -        sendfiles(e.dataTransfer.files)
       -    }
       -
       -    fileinput.onchange = function(e) {
       -        sendfiles(this.files)
       -    }
       -}
       -
       -function sendfiles(files) {
       -    let uploads = document.getElementById("uploads");
       -    let progressbar = document.createElement("progress");
       -    let uploadlist = document.createElement("ul");
       -    let formData = new FormData(), xhr = new XMLHttpRequest();
       -
       -    uploads.appendChild(progressbar);
       -    uploads.appendChild(uploadlist);
       -
       -    formData.append("expiry", 10);
       -    for(let i=0; i < files.length; i++) {
       -        formData.append("file", files[i]);
       -    }
       -
       -    // triggers periodically
       -    xhr.upload.onprogress = function(e) {
       -        // e.loaded - how many bytes downloaded
       -        // e.lengthComputable = true if the server sent Content-Length header
       -        // e.total - total number of bytes (if lengthComputable)
       -
       -    }
       -
       -    xhr.onreadystatechange = function() {
       -        if(xhr.readyState === XMLHttpRequest.DONE) {
       -                progressbar.remove();
       -                this.response.split(/\r?\n/).forEach(function(link) {
       -                        let li = document.createElement("li");
       -                        li.innerHTML = `<a href="${link}">${link}</a>`;
       -                        uploadlist.appendChild(li);
       -                });
       -        }
       -    }
       -
       -    xhr.open('POST', window.location.href, true); // async = true
       -    xhr.send(formData); 
       -}
 (DIR) diff --git a/templates/index.html b/templates/index.html
       t@@ -1,39 +0,0 @@
       -<!DOCTYPE HTML>
       -<html>
       -<head>
       -        <meta charset="utf-8">
       -        <meta name="author" content="z3bra">
       -        <meta name="robots" content="noindex,nofollow" />
       -        <meta name="viewport" content="width=device-width">
       -        <link rel="stylesheet" type="text/css" href="/partage.css" />
       -        <link rel="icon" type="image/png" href="/favicon.ico" />
       -        <title>Partage</title>
       -</head>
       -<body>
       -        <header>
       -                <img id="logo" src="/partage.png" />
       -                <h1>partage</h1>
       -        </header>
       -        <form enctype="multipart/form-data" method="post">
       -                <div id="dropzone"></div>
       -                <div id="fallbackform" class="dropzone">
       -                        <input id="filebox" name="file" type="file" multiple/>
       -                        <input id="output" name="output" type="hidden" value='html' />
       -                        <input type="submit" value="Upload"/>
       -                </div>
       -                <section id="formsettings">
       -                        <label for="expiry"> Destroy after </label>
       -                        <select id="expiry" name="expiry">
       -                                <option value="900"> 15 minutes </option>
       -                                <option value="3600"> 1 hour </option>
       -                                <option value="28800"> 8 hours </option>
       -                                <option value="86400" selected> 1 day </option>
       -                                <option value="604800"> 1 week </option>
       -                        </select>
       -                </section>
       -        </form>
       -        <p>File size limited to {{.Maxsize}}.</p>
       -        <div id="uploads"></div>
       -        <script src="/dz.js"></script>
       -</body>
       -</html>
 (DIR) diff --git a/templates/upload.html b/templates/upload.html
       t@@ -1,22 +0,0 @@
       -<!DOCTYPE HTML>
       -<html>
       -<head>
       -        <meta charset="utf-8">
       -        <meta name="author" content="z3bra">
       -        <meta name="viewport" content="width=device-width">
       -        <link rel="stylesheet" type="text/css" href="/partage.css" />
       -        <link rel="icon" type="image/png" href="/favicon.ico" />
       -        <title>Partage</title>
       -</head>
       -<body>
       -        <header>
       -                <h1>partage</h1>
       -                <img id="logo" src="/partage.png" />
       -        </header>
       -        <ul>
       -        {{range .Links}}
       -          <li><a href="{{.}}">{{.}}</a></li>
       -        {{end}}
       -        </ul>
       -</body>
       -</html>