finnally doooo and close #11
Former-commit-id: b899f43722862ed4aafbca659670f26011ae727d [formerly 746709cdc2fa58bc69a71fa795a5589a1145d853] [formerly 5aab2327e90c4dd0a47b71d8ef90043e8918db06 [formerly eb22fd20ce78b48c6a2a3c3ffc59b1ca76feda5e]] Former-commit-id: ca8b01af19ef3bbd870636170f60fd7ae8e4cd7f [formerly be235a498e36298e07f1b5d07939668d57e08fe2] Former-commit-id: 6bccf20702c8b3867a3a2ebae711834a740a06ad
This commit is contained in:
parent
f3408df0b5
commit
777d18e887
|
@ -45,7 +45,6 @@ button {
|
||||||
padding: .5em 1em;
|
padding: .5em 1em;
|
||||||
margin-left: .5em;
|
margin-left: .5em;
|
||||||
border-radius: .1em;
|
border-radius: .1em;
|
||||||
background-color;
|
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
background: #2196f3;
|
background: #2196f3;
|
||||||
color: #fff;
|
color: #fff;
|
||||||
|
@ -376,10 +375,6 @@ header>div div {
|
||||||
position: relative;
|
position: relative;
|
||||||
}
|
}
|
||||||
|
|
||||||
header .actions {
|
|
||||||
/* margin-left: auto; */
|
|
||||||
}
|
|
||||||
|
|
||||||
#logout {
|
#logout {
|
||||||
border-radius: 0;
|
border-radius: 0;
|
||||||
margin-left: auto;
|
margin-left: auto;
|
||||||
|
@ -1010,6 +1005,10 @@ header .actions {
|
||||||
padding: .3em;
|
padding: .3em;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.prompt code {
|
||||||
|
word-wrap: break-word;
|
||||||
|
}
|
||||||
|
|
||||||
.prompt div,
|
.prompt div,
|
||||||
.help div {
|
.help div {
|
||||||
margin-top: 1em;
|
margin-top: 1em;
|
||||||
|
|
|
@ -302,17 +302,40 @@ function openEvent (event) {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getHash (event, hash) {
|
||||||
|
event.preventDefault()
|
||||||
|
|
||||||
|
let request = new window.XMLHttpRequest()
|
||||||
|
request.open('GET', `${window.location.pathname}?checksum=${hash}`, true)
|
||||||
|
|
||||||
|
request.onload = () => {
|
||||||
|
if (request.status >= 300) {
|
||||||
|
console.log(request.statusText)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
event.target.parentElement.innerHTML = request.responseText
|
||||||
|
}
|
||||||
|
request.onerror = (e) => console.log(e)
|
||||||
|
request.send()
|
||||||
|
}
|
||||||
|
|
||||||
function infoEvent (event) {
|
function infoEvent (event) {
|
||||||
event.preventDefault()
|
event.preventDefault()
|
||||||
if (event.currentTarget.classList.contains('disabled')) {
|
if (event.currentTarget.classList.contains('disabled')) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let dir = false
|
||||||
let link
|
let link
|
||||||
|
|
||||||
if (selectedItems.length) {
|
if (selectedItems.length) {
|
||||||
link = document.getElementById(selectedItems[0]).dataset.url
|
link = document.getElementById(selectedItems[0]).dataset.url
|
||||||
|
dir = document.getElementById(selectedItems[0]).dataset.dir
|
||||||
} else {
|
} else {
|
||||||
|
if (document.getElementById('listing') !== null) {
|
||||||
|
dir = true
|
||||||
|
}
|
||||||
|
|
||||||
link = window.location.pathname
|
link = window.location.pathname
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -326,6 +349,10 @@ function infoEvent (event) {
|
||||||
clone.getElementById('content_length').innerHTML = xml.getElementsByTagName('getcontentlength')[0].innerHTML
|
clone.getElementById('content_length').innerHTML = xml.getElementsByTagName('getcontentlength')[0].innerHTML
|
||||||
clone.getElementById('last_modified').innerHTML = xml.getElementsByTagName('getlastmodified')[0].innerHTML
|
clone.getElementById('last_modified').innerHTML = xml.getElementsByTagName('getlastmodified')[0].innerHTML
|
||||||
|
|
||||||
|
if (dir === true || dir === 'true') {
|
||||||
|
clone.querySelector('.file-only').style.display = 'none'
|
||||||
|
}
|
||||||
|
|
||||||
document.querySelector('body').appendChild(clone)
|
document.querySelector('body').appendChild(clone)
|
||||||
document.querySelector('.overlay').classList.add('active')
|
document.querySelector('.overlay').classList.add('active')
|
||||||
document.querySelector('.prompt').classList.add('active')
|
document.querySelector('.prompt').classList.add('active')
|
||||||
|
|
|
@ -215,6 +215,14 @@
|
||||||
<p><strong>Display Name:</strong> <span id="display_name"></span></p>
|
<p><strong>Display Name:</strong> <span id="display_name"></span></p>
|
||||||
<p><strong>Content Length:</strong> <span id="content_length"></span> Bytes</p>
|
<p><strong>Content Length:</strong> <span id="content_length"></span> Bytes</p>
|
||||||
<p><strong>Last Modified:</strong> <span id="last_modified"></span></p>
|
<p><strong>Last Modified:</strong> <span id="last_modified"></span></p>
|
||||||
|
|
||||||
|
<section class="file-only">
|
||||||
|
<p><strong>MD5:</strong> <code id="md5"><a href="#" onclick="getHash(event, 'md5')">show</a></code></p>
|
||||||
|
<p><strong>SHA1:</strong> <code id="sha1"><a href="#" onclick="getHash(event, 'sha1')">show</a></code></p>
|
||||||
|
<p><strong>SHA256:</strong> <code id="sha256"><a href="#" onclick="getHash(event, 'sha256')">show</a></code></p>
|
||||||
|
<p><strong>SHA512:</strong> <code id="sha512"><a href="#" onclick="getHash(event, 'sha512')">show</a></code></p>
|
||||||
|
</section>
|
||||||
|
|
||||||
<div>
|
<div>
|
||||||
<button type="submit" onclick="closePrompt(event);" class="ok">OK</button>
|
<button type="submit" onclick="closePrompt(event);" class="ok">OK</button>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
bbb145fc8bd2b1a8c6896fb345e858cb02187a9d
|
47a317d31e5cc5c338be174795c888342611b7d6
|
|
@ -173,6 +173,8 @@ func (f FileManager) ServeHTTP(w http.ResponseWriter, r *http.Request) (int, err
|
||||||
case r.URL.Query().Get("raw") == "true" && !fi.IsDir:
|
case r.URL.Query().Get("raw") == "true" && !fi.IsDir:
|
||||||
http.ServeFile(w, r, fi.Path)
|
http.ServeFile(w, r, fi.Path)
|
||||||
code, err = 0, nil
|
code, err = 0, nil
|
||||||
|
case !fi.IsDir && r.URL.Query().Get("checksum") != "":
|
||||||
|
code, err = handlers.Checksum(w, r, c, fi)
|
||||||
case fi.IsDir:
|
case fi.IsDir:
|
||||||
code, err = handlers.ServeListing(w, r, c, user, fi)
|
code, err = handlers.ServeListing(w, r, c, user, fi)
|
||||||
default:
|
default:
|
||||||
|
|
|
@ -0,0 +1,54 @@
|
||||||
|
package handlers
|
||||||
|
|
||||||
|
import (
|
||||||
|
"crypto/md5"
|
||||||
|
"crypto/sha1"
|
||||||
|
"crypto/sha256"
|
||||||
|
"crypto/sha512"
|
||||||
|
"encoding/hex"
|
||||||
|
e "errors"
|
||||||
|
"hash"
|
||||||
|
"io"
|
||||||
|
"net/http"
|
||||||
|
"os"
|
||||||
|
|
||||||
|
"github.com/hacdias/caddy-filemanager/config"
|
||||||
|
"github.com/hacdias/caddy-filemanager/file"
|
||||||
|
"github.com/hacdias/caddy-filemanager/utils/errors"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Checksum calculates the hash of a file. Supports MD5, SHA1, SHA256 and SHA512.
|
||||||
|
func Checksum(w http.ResponseWriter, r *http.Request, c *config.Config, i *file.Info) (int, error) {
|
||||||
|
query := r.URL.Query().Get("checksum")
|
||||||
|
|
||||||
|
file, err := os.Open(i.Path)
|
||||||
|
if err != nil {
|
||||||
|
return errors.ErrorToHTTPCode(err, true), err
|
||||||
|
}
|
||||||
|
|
||||||
|
defer file.Close()
|
||||||
|
|
||||||
|
var h hash.Hash
|
||||||
|
|
||||||
|
switch query {
|
||||||
|
case "md5":
|
||||||
|
h = md5.New()
|
||||||
|
case "sha1":
|
||||||
|
h = sha1.New()
|
||||||
|
case "sha256":
|
||||||
|
h = sha256.New()
|
||||||
|
case "sha512":
|
||||||
|
h = sha512.New()
|
||||||
|
default:
|
||||||
|
return http.StatusBadRequest, e.New("Unknown HASH type")
|
||||||
|
}
|
||||||
|
|
||||||
|
_, err = io.Copy(h, file)
|
||||||
|
if err != nil {
|
||||||
|
return http.StatusInternalServerError, err
|
||||||
|
}
|
||||||
|
|
||||||
|
val := hex.EncodeToString(h.Sum(nil))
|
||||||
|
w.Write([]byte(val))
|
||||||
|
return http.StatusOK, nil
|
||||||
|
}
|
Loading…
Reference in New Issue