Limit text files to be loaded
This commit is contained in:
Родитель
c0112f0557
Коммит
c1465e2113
|
@ -27,6 +27,7 @@ use OC\Files\View;
|
|||
use OCP\AppFramework\Controller;
|
||||
use OCP\AppFramework\Http;
|
||||
use OCP\AppFramework\Http\DataResponse;
|
||||
use OCP\IConfig;
|
||||
use OCP\IL10N;
|
||||
use OCP\ILogger;
|
||||
use OCP\IRequest;
|
||||
|
@ -75,23 +76,28 @@ class FileHandlingController extends Controller{
|
|||
try {
|
||||
if (!empty($filename)) {
|
||||
$path = $dir . '/' . $filename;
|
||||
$filecontents = $this->view->file_get_contents($path);
|
||||
if ($filecontents !== false) {
|
||||
// default of 4MB
|
||||
$maxSize = 4194304;
|
||||
if ($this->view->filesize($path) > $maxSize) {
|
||||
return new DataResponse(['message' => (string)$this->l->t('The file is too big.')], Http::STATUS_BAD_REQUEST);
|
||||
}
|
||||
$fileContents = $this->view->file_get_contents($path);
|
||||
if ($fileContents !== false) {
|
||||
$writable = $this->view->isUpdatable($path);
|
||||
$mime = $this->view->getMimeType($path);
|
||||
$mtime = $this->view->filemtime($path);
|
||||
$encoding = mb_detect_encoding($filecontents . "a", "UTF-8, WINDOWS-1252, ISO-8859-15, ISO-8859-1, ASCII", true);
|
||||
$mTime = $this->view->filemtime($path);
|
||||
$encoding = mb_detect_encoding($fileContents . "a", "UTF-8, WINDOWS-1252, ISO-8859-15, ISO-8859-1, ASCII", true);
|
||||
if ($encoding == "") {
|
||||
// set default encoding if it couldn't be detected
|
||||
$encoding = 'ISO-8859-15';
|
||||
}
|
||||
$filecontents = iconv($encoding, "UTF-8", $filecontents);
|
||||
$fileContents = iconv($encoding, "UTF-8", $fileContents);
|
||||
return new DataResponse(
|
||||
[
|
||||
'filecontents' => $filecontents,
|
||||
'filecontents' => $fileContents,
|
||||
'writeable' => $writable,
|
||||
'mime' => $mime,
|
||||
'mtime' => $mtime
|
||||
'mtime' => $mTime
|
||||
],
|
||||
Http::STATUS_OK
|
||||
);
|
||||
|
|
Загрузка…
Ссылка в новой задаче