fixed text controller for v3

This commit is contained in:
Chris
2025-05-17 21:27:15 +02:00
parent 419f5a19d1
commit c02a25439e
4 changed files with 40 additions and 21 deletions

View File

@@ -4,6 +4,12 @@ class TextController implements ContentController
{ {
public const ctype = 'static'; public const ctype = 'static';
public $mimes = [
'text/plain',
'text/csv',
'text/tab-separated-values',
];
//returns all extensions registered by this type of content //returns all extensions registered by this type of content
public function getRegisteredExtensions(){return array('txt','text','csv');} public function getRegisteredExtensions(){return array('txt','text','csv');}

View File

@@ -75,7 +75,10 @@ class API
//check naughty list (previously deleted files) //check naughty list (previously deleted files)
if ($this->isFileInNaughtyList($sha1)) if ($this->isFileInNaughtyList($sha1))
{
addToLog(getUserIP()." tried to upload a file with the SHA1: ".$sha1." (".$type.", original name:".$_FILES['file']['name'].") but it was previously deleted and therefore on the naughty list");
return ['status' => 'err', 'reason' => 'File is in the naughty list']; return ['status' => 'err', 'reason' => 'File is in the naughty list'];
}
$answer = false; $answer = false;
foreach(loadAllContentControllers() as $cc) foreach(loadAllContentControllers() as $cc)
@@ -89,7 +92,10 @@ class API
} }
if (!$answer) if (!$answer)
{
addToLog(getUserIP()." tried to upload a file with the SHA1: ".$sha1." (".$type.", original name:".$_FILES['file']['name'].") but the file type is not supported");
return ['status' => 'err', 'reason' => 'Unsupported mime type: ' . $type]; return ['status' => 'err', 'reason' => 'Unsupported mime type: ' . $type];
}
else if($answer['hash'] && $answer['status']=='ok'){ else if($answer['hash'] && $answer['status']=='ok'){
$delcode = getRandomString(32); $delcode = getRandomString(32);
$meta = [ $meta = [
@@ -124,11 +130,18 @@ class API
]; ];
} }
else else
{
addToLog(getUserIP()." tried to upload a file with the SHA1: ".$sha1." (".$type.", original name:".$_FILES['file']['name'].") but the upload failed. Probably in the handleUpload method of the content controller ".get_class($cc));
return ['status' => 'err', 'reason' => 'Strange error during upload']; return ['status' => 'err', 'reason' => 'Strange error during upload'];
}
} else } else
{
addToLog(getUserIP()." tried to upload a file with the SHA1: ".$_FILES['file']['name']." (".$_FILES['file']['type'].") but the upload failed with error code: ".$_FILES['file']["error"]." (".$this->uploadErrorMessage($_FILES['file']["error"]).")");
return ['status' => 'err', 'reason' => 'Upload error: '.$this->uploadErrorMessage($_FILES['file']["error"])]; return ['status' => 'err', 'reason' => 'Upload error: '.$this->uploadErrorMessage($_FILES['file']["error"])];
} }
}
public function checkPermissions() public function checkPermissions()

View File

@@ -1,45 +1,45 @@
<!doctype html> <!doctype html>
<html> <html>
<head> <head>
<title><?php echo (defined('TITLE')?TITLE:'PictShare image hosting'); ?></title> <title><?= (defined('TITLE')?TITLE:'PictShare image hosting'); ?></title>
<meta http-equiv="content-type" content="text/html;charset=utf-8" /> <meta http-equiv="content-type" content="text/html;charset=utf-8" />
<meta name="copyright" content="Copyright <?php echo date("Y"); ?> PictShare" /> <meta name="copyright" content="Copyright <?= date("Y"); ?> PictShare" />
<meta id="viewport" name="viewport" content="width=<?php echo $width ?>, user-scalable=yes" /> <meta id="viewport" name="viewport" content="width=<?= $width ?>, user-scalable=yes" />
<script src="https://code.jquery.com/jquery-2.1.4.min.js"></script> <script src="https://code.jquery.com/jquery-2.1.4.min.js"></script>
<style type="text/css"> <style type="text/css">
*{margin:0px;padding:0px;} *{margin:0px;padding:0px;}
</style> </style>
<link rel="alternate" type="application/json+oembed" href="<?php echo URL; ?>backend.php?a=oembed&t=json&url=<?php echo rawurlencode(URL.$hash); ?>" title="PictShare" /> <link rel="alternate" type="application/json+oembed" href="<?= URL; ?>backend.php?a=oembed&t=json&url=<?= rawurlencode(URL.$hash); ?>" title="PictShare" />
<link rel="canonical" href="<?php echo URL.$hash; ?>" /> <link rel="canonical" href="<?= URL.$hash; ?>" />
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" /> <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
<meta property="og:site_name" content="<?php echo (defined('TITLE')?TITLE:'PictShare mp4 hosting'); ?>" /> <meta property="og:site_name" content="<?= (defined('TITLE')?TITLE:'PictShare mp4 hosting'); ?>" />
<meta property="og:url" content="<?php echo URL.$hash; ?>" /> <meta property="og:url" content="<?= URL.$hash; ?>" />
<meta property="og:title" content="<?php echo (defined('TITLE')?TITLE:'PictShare mp4 hosting'); ?> MP4" /> <meta property="og:title" content="<?= (defined('TITLE')?TITLE:'PictShare mp4 hosting'); ?> MP4" />
<meta property="og:type" content="video.other" /> <meta property="og:type" content="video.other" />
<meta property="og:image" content="<?php echo URL.'preview/'.$hash; ?>" /> <meta property="og:image" content="<?= URL.'preview/'.$hash; ?>" />
<meta property="og:image:width" content="<?php echo $width ?>" /> <meta property="og:image:width" content="<?= $width ?>" />
<meta property="og:image:height" content="<?php echo $height ?>" /> <meta property="og:image:height" content="<?= $height ?>" />
<meta property="og:description" content="MP4 Video" /> <meta property="og:description" content="MP4 Video" />
<meta property="og:video" content="<?php echo URL.$hash; ?>" /> <meta property="og:video" content="<?= URL.$hash; ?>" />
<meta property="og:video:secure_url" content="<?php echo URL.$hash; ?>" /> <meta property="og:video:secure_url" content="<?= URL.$hash; ?>" />
<meta property="og:video:type" content="application/x-shockwave-flash" /> <meta property="og:video:type" content="application/x-shockwave-flash" />
<meta property="og:video:width" content="<?php echo $width ?>" /> <meta property="og:video:width" content="<?= $width ?>" />
<meta property="og:video:height" content="<?php echo $height ?>" /> <meta property="og:video:height" content="<?= $height ?>" />
<meta property="og:video:type" content="video/mp4" /> <meta property="og:video:type" content="video/mp4" />
<meta property="og:video:width" content="<?php echo $width ?>" /> <meta property="og:video:width" content="<?= $width ?>" />
<meta property="og:video:height" content="<?php echo $height ?>" /> <meta property="og:video:height" content="<?= $height ?>" />
</head> </head>
<body id="body"> <body id="body">
<div id="container"> <div id="container">
<video id="video" poster="<?php echo URL.$url.'/preview/'.$hash; ?>" preload="auto" autoplay="autoplay" controls muted="muted" loop="loop" webkit-playsinline> <video id="video" poster="<?= URL.$url.'/preview/'.$hash; ?>" preload="auto" autoplay="autoplay" controls muted="muted" loop="loop" webkit-playsinline>
<source src="<?php echo URL.$url.'/raw' ?>" type="video/mp4"> <source src="<?= URL.$url.'/raw' ?>" type="video/mp4">
<?php <?php
if(file_exists(getDataDir().DS.$hash.DS.'webm_1.'.$hash)) if(file_exists(getDataDir().DS.$hash.DS.'webm_1.'.$hash))
echo '<source src="'.URL.'raw/webm/'.$hash.'" type="video/webm">'."\n"; echo '<source src="'.URL.'raw/webm/'.$hash.'" type="video/webm">'."\n";
@@ -48,7 +48,7 @@
?> ?>
</video> </video>
</div> </div>
<small><?php echo $filesize; ?> <a href="<?php echo URL.$url.'/raw' ?>">Raw</a> <a href="<?php echo URL.$url.'/download' ?>">Download</a></a></small> <small><?= $filesize; ?> <a href="<?= URL.$url.'/raw' ?>">Raw</a> <a href="<?= URL.$url.'/download' ?>">Download</a></a></small>
<script> <script>
var hadToResizeW = false; var hadToResizeW = false;

View File

@@ -21,7 +21,7 @@ if(file_exists(ROOT.'/src/lib/vendor/autoload.php'))
//parse the URL to an array and filter it //parse the URL to an array and filter it
$url = array_filter(explode('/',ltrim(parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH),'/'))); $url = array_filter(explode('/',ltrim(parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH),'/')));
if($url[0] == 'api' || $url[0] == 'raw') if($url[0] == 'api')
{ {
array_shift($url); //remove "api" form the URL array_shift($url); //remove "api" form the URL
$a = new API($url); $a = new API($url);