forked from Kieran/void.cat
add upload history and nginx accel download
This commit is contained in:
parent
cfba9975c5
commit
f3e9434793
@ -1,5 +0,0 @@
|
|||||||
{
|
|
||||||
"require": {
|
|
||||||
"php-ffmpeg/php-ffmpeg": "~0.5"
|
|
||||||
}
|
|
||||||
}
|
|
@ -8,5 +8,6 @@
|
|||||||
/* GENERAL SETTINGS */
|
/* GENERAL SETTINGS */
|
||||||
define('_DEFAULT_TYPE', 'application/octet-stream');
|
define('_DEFAULT_TYPE', 'application/octet-stream');
|
||||||
define('_SITEURL', 'http://example.com/');
|
define('_SITEURL', 'http://example.com/');
|
||||||
define('_FILEPATH', dirname ( __FILE__ ) . '/out/');
|
define('_UPLOADDIR', '/out/');
|
||||||
|
define('_FILEPATH', dirname ( __FILE__ ) . _UPLOADDIR);
|
||||||
?>
|
?>
|
||||||
|
25
download2.php
Normal file
25
download2.php
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
function XFastDownload($location, $filename, $mimeType = 'application/octet-stream')
|
||||||
|
{
|
||||||
|
$url = "https://www.google-analytics.com/collect";
|
||||||
|
$payload = "v=1&tid=UA-73200448-1&cid=" . session_id() . "&t=pageview&dh=" . $_SERVER['HTTP_HOST'] . "&dp=" . urlencode($_SERVER['REQUEST_URI']) . "&uip=" . $_SERVER['REMOTE_ADDR'] . "&ua=" . urlencode($_SERVER["HTTP_USER_AGENT"]) . "&dr=" . urlencode($_SERVER["HTTP_REFERER"]);
|
||||||
|
|
||||||
|
$ch = curl_init();
|
||||||
|
|
||||||
|
curl_setopt($ch, CURLOPT_URL, $url);
|
||||||
|
curl_setopt($ch, CURLOPT_POST, 1);
|
||||||
|
curl_setopt($ch, CURLOPT_POSTFIELDS, $payload);
|
||||||
|
|
||||||
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||||
|
curl_exec($ch);
|
||||||
|
curl_close ($ch);
|
||||||
|
|
||||||
|
$expire = 604800;
|
||||||
|
|
||||||
|
header("X-Accel-Redirect: $location");
|
||||||
|
header("Cache-Control: public, max-age=$expire");
|
||||||
|
header("Content-type: $mimeType");
|
||||||
|
header('Content-Disposition: inline; filename="' . $filename . '"');
|
||||||
|
}
|
||||||
|
?>
|
34
index.php
34
index.php
@ -1,4 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
|
session_start();
|
||||||
|
|
||||||
//check for view param otherwise return file
|
//check for view param otherwise return file
|
||||||
$hash = isset($_GET["hash"]) ? substr($_GET["hash"], strrpos($_GET["hash"], '/') + 1) : null;
|
$hash = isset($_GET["hash"]) ? substr($_GET["hash"], strrpos($_GET["hash"], '/') + 1) : null;
|
||||||
if(!isset($_GET["v"]) && $hash != null)
|
if(!isset($_GET["v"]) && $hash != null)
|
||||||
@ -8,20 +10,9 @@
|
|||||||
$db = new DB();
|
$db = new DB();
|
||||||
$f = $db->GetFile($hash);
|
$f = $db->GetFile($hash);
|
||||||
if($f->id != 0){
|
if($f->id != 0){
|
||||||
include_once('download.php');
|
include_once('download2.php');
|
||||||
smartReadFile($f->path, $f->filename, $f->mime);
|
|
||||||
}
|
|
||||||
|
|
||||||
exit;
|
$db->AddView($f->hash160);
|
||||||
}else if(isset($_GET["thumb"]) && $hash != null)
|
|
||||||
{
|
|
||||||
include_once('db.php');
|
|
||||||
|
|
||||||
$db = new DB();
|
|
||||||
$f = $db->GetFile($hash);
|
|
||||||
if($f->id != 0){
|
|
||||||
include_once('download.php');
|
|
||||||
smartReadFile($f->path . '/thumb/', $f->filename, $f->mime);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
exit;
|
exit;
|
||||||
@ -113,6 +104,10 @@
|
|||||||
echo "<div id=\"uploads\" style=\"display: none\"></div><div id=\"upload\">Drop Files < " . $maxsizeM . "</div>";
|
echo "<div id=\"uploads\" style=\"display: none\"></div><div id=\"upload\">Drop Files < " . $maxsizeM . "</div>";
|
||||||
}
|
}
|
||||||
?>
|
?>
|
||||||
|
<div id="history">
|
||||||
|
<h3>Your Uploads</h3>
|
||||||
|
<small>History is saved in <a style="display: initial; padding: initial; margin: initial;" href="https://www.w3schools.com/html/html5_webstorage.asp">localStorage</a> <b style="cursor: pointer; user-select: none;" onclick="localStorage.setItem('history', ''); window.location.reload();">(clear)</b></small>
|
||||||
|
</div>
|
||||||
<div id="footer">
|
<div id="footer">
|
||||||
<a href="https://github.com/v0l/void.cat">Github</a>
|
<a href="https://github.com/v0l/void.cat">Github</a>
|
||||||
| <a href="https://twitter.com/chkn10deez">Twitter</a>
|
| <a href="https://twitter.com/chkn10deez">Twitter</a>
|
||||||
@ -129,5 +124,18 @@
|
|||||||
ga('create', 'UA-73200448-1', 'auto');
|
ga('create', 'UA-73200448-1', 'auto');
|
||||||
ga('send', 'pageview');
|
ga('send', 'pageview');
|
||||||
</script>
|
</script>
|
||||||
|
<script>
|
||||||
|
var h = loadHistory();
|
||||||
|
var hl = document.querySelector('#history');
|
||||||
|
for(var x = h.length - 1; x >= 0; x--) {
|
||||||
|
var hx = h[x];
|
||||||
|
var nh = document.createElement('a');
|
||||||
|
nh.href = hx.link + '&v';
|
||||||
|
nh.target = '_blank'
|
||||||
|
nh.text = (hx.filename === null ? 'clipboard' : hx.filename);
|
||||||
|
|
||||||
|
hl.appendChild(nh);
|
||||||
|
}
|
||||||
|
</script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
@ -140,6 +140,18 @@ video {
|
|||||||
font-weight: bold;
|
font-weight: bold;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#history {
|
||||||
|
margin: 10px;
|
||||||
|
padding: 10px;
|
||||||
|
border: 2px solid #eee;
|
||||||
|
background-color: rgba(238, 238, 238, 0.18);
|
||||||
|
}
|
||||||
|
|
||||||
|
#history a {
|
||||||
|
display: block;
|
||||||
|
margin: 5px;
|
||||||
|
}
|
||||||
|
|
||||||
/* MEDIA OVERWRITE QUERIES */
|
/* MEDIA OVERWRITE QUERIES */
|
||||||
@media (max-width: 720px) {
|
@media (max-width: 720px) {
|
||||||
#main {
|
#main {
|
||||||
|
@ -55,6 +55,25 @@ function addPasteFunctions()
|
|||||||
document.addEventListener('paste', handleFilePaste, false);
|
document.addEventListener('paste', handleFilePaste, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function loadHistory(){
|
||||||
|
var hist = localStorage.getItem("history");
|
||||||
|
if(hist.length > 0) {
|
||||||
|
hist = JSON.parse(hist);
|
||||||
|
} else {
|
||||||
|
hist = [];
|
||||||
|
}
|
||||||
|
|
||||||
|
return hist;
|
||||||
|
}
|
||||||
|
|
||||||
|
function saveToHistory(r){
|
||||||
|
var hist = loadHistory();
|
||||||
|
|
||||||
|
hist[hist.length] = r;
|
||||||
|
|
||||||
|
localStorage.setItem("history", JSON.stringify(hist));
|
||||||
|
}
|
||||||
|
|
||||||
function uploadComplete(rsp, id, s)
|
function uploadComplete(rsp, id, s)
|
||||||
{
|
{
|
||||||
var upl = $('#' + id);
|
var upl = $('#' + id);
|
||||||
@ -99,6 +118,9 @@ function uploadComplete(rsp, id, s)
|
|||||||
+ '<br/><small><b>Hash256:</b> ' + rsp.hash
|
+ '<br/><small><b>Hash256:</b> ' + rsp.hash
|
||||||
+ '</small><br/><small><b>Hash160:</b> ' + rsp.publichash + '</small>'
|
+ '</small><br/><small><b>Hash160:</b> ' + rsp.publichash + '</small>'
|
||||||
+ '<br/><small><a target=\"_blank\" href=\"//' + lk + '&v\">(link)</a></small>';
|
+ '<br/><small><a target=\"_blank\" href=\"//' + lk + '&v\">(link)</a></small>';
|
||||||
|
|
||||||
|
//save to history
|
||||||
|
saveToHistory(rsp);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -39,6 +39,8 @@
|
|||||||
$response["hash"] = $fh;
|
$response["hash"] = $fh;
|
||||||
rewind($tmpf);
|
rewind($tmpf);
|
||||||
|
|
||||||
|
$response["filename"] = $fname;
|
||||||
|
|
||||||
//check for dupes
|
//check for dupes
|
||||||
$f_e = $db->Exists256($fh);
|
$f_e = $db->Exists256($fh);
|
||||||
if($f_e->id != 0)
|
if($f_e->id != 0)
|
||||||
|
Loading…
Reference in New Issue
Block a user