mirror of
https://github.com/Karaka-Management/oms-Media.git
synced 2026-02-17 09:48:41 +00:00
test fixes and changes for release
This commit is contained in:
parent
de045f4b25
commit
a66a359e0a
|
|
@ -50,6 +50,7 @@ use phpOMS\Model\Message\FormValidation;
|
||||||
use phpOMS\System\File\FileUtils;
|
use phpOMS\System\File\FileUtils;
|
||||||
use phpOMS\System\File\Local\Directory;
|
use phpOMS\System\File\Local\Directory;
|
||||||
use phpOMS\System\MimeType;
|
use phpOMS\System\MimeType;
|
||||||
|
use phpOMS\Utils\ImageUtils;
|
||||||
use phpOMS\Utils\Parser\Markdown\Markdown;
|
use phpOMS\Utils\Parser\Markdown\Markdown;
|
||||||
use phpOMS\Utils\Parser\Pdf\PdfParser;
|
use phpOMS\Utils\Parser\Pdf\PdfParser;
|
||||||
use phpOMS\Views\View;
|
use phpOMS\Views\View;
|
||||||
|
|
@ -212,9 +213,10 @@ final class ApiController extends Controller
|
||||||
/**
|
/**
|
||||||
* Uploads a file to a destination
|
* Uploads a file to a destination
|
||||||
*
|
*
|
||||||
* @param array $files Files to upload
|
* @param array $files Files to upload
|
||||||
* @param array $fileNames Names on the directory
|
* @param array $fileNames Names on the directory
|
||||||
* @param string $path Upload path
|
* @param string $path Upload path
|
||||||
|
* @param bool $preserveFileName Preserve file name
|
||||||
*
|
*
|
||||||
* @return array
|
* @return array
|
||||||
*
|
*
|
||||||
|
|
@ -224,10 +226,12 @@ final class ApiController extends Controller
|
||||||
array $files,
|
array $files,
|
||||||
array $fileNames = [],
|
array $fileNames = [],
|
||||||
string $path = '',
|
string $path = '',
|
||||||
|
bool $preserveFileName = true
|
||||||
) : array
|
) : array
|
||||||
{
|
{
|
||||||
$upload = new UploadFile();
|
$upload = new UploadFile();
|
||||||
$upload->outputDir = $path;
|
$upload->outputDir = $path; //empty($path) ? $upload->outputDir : $path;
|
||||||
|
$upload->preserveFileName = $preserveFileName;
|
||||||
|
|
||||||
return $upload->upload($files, $fileNames, true, '');
|
return $upload->upload($files, $fileNames, true, '');
|
||||||
}
|
}
|
||||||
|
|
@ -583,7 +587,7 @@ final class ApiController extends Controller
|
||||||
*
|
*
|
||||||
* @param string $path Virtual path of the collection
|
* @param string $path Virtual path of the collection
|
||||||
* @param int $account Account who creates this collection
|
* @param int $account Account who creates this collection
|
||||||
* @param int $physicalPath The physical path where the corresponding directory should be created
|
* @param string $physicalPath The physical path where the corresponding directory should be created
|
||||||
*
|
*
|
||||||
* @return Collection
|
* @return Collection
|
||||||
*
|
*
|
||||||
|
|
@ -1021,4 +1025,35 @@ final class ApiController extends Controller
|
||||||
|
|
||||||
return $l11nMediaType;
|
return $l11nMediaType;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Resize image file
|
||||||
|
*
|
||||||
|
* @param Media $media Media object
|
||||||
|
* @param int $width New width
|
||||||
|
* @param int $height New height
|
||||||
|
* @param bool $crop Crop image instead of resizing
|
||||||
|
*
|
||||||
|
* @return Media
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
|
public function resizeImage(
|
||||||
|
Media $media,
|
||||||
|
int $width,
|
||||||
|
int $height,
|
||||||
|
bool $crop = false)
|
||||||
|
: Media {
|
||||||
|
ImageUtils::resize(
|
||||||
|
$media->getAbsolutePath(),
|
||||||
|
$media->getAbsolutePath(),
|
||||||
|
$width,
|
||||||
|
$height,
|
||||||
|
$crop
|
||||||
|
);
|
||||||
|
|
||||||
|
$temp = \filesize($media->getAbsolutePath());
|
||||||
|
$media->size = $temp === false ? 0 : $temp;
|
||||||
|
|
||||||
|
return $media;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -262,7 +262,7 @@ final class BackendController extends Controller
|
||||||
->with('tags')
|
->with('tags')
|
||||||
->with('tags/title')
|
->with('tags/title')
|
||||||
->with('content')
|
->with('content')
|
||||||
->where('id', $media->source->getId())
|
->where('id', $media->source?->getId() ?? 0)
|
||||||
->where('tags/title/language', $request->getLanguage())
|
->where('tags/title/language', $request->getLanguage())
|
||||||
->execute();
|
->execute();
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -58,7 +58,7 @@ class MediaType implements \JsonSerializable
|
||||||
* @var string|MediaTypeL11n
|
* @var string|MediaTypeL11n
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
*/
|
*/
|
||||||
protected $title;
|
protected $title = '';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor.
|
* Constructor.
|
||||||
|
|
@ -108,7 +108,7 @@ class MediaType implements \JsonSerializable
|
||||||
{
|
{
|
||||||
if ($title instanceof MediaTypeL11n) {
|
if ($title instanceof MediaTypeL11n) {
|
||||||
$this->title = $title;
|
$this->title = $title;
|
||||||
} elseif (isset($this->title) && $this->title instanceof MediaTypeL11n) {
|
} elseif ($this->title instanceof MediaTypeL11n) {
|
||||||
$this->title->title = $title;
|
$this->title->title = $title;
|
||||||
} else {
|
} else {
|
||||||
$this->title = new MediaTypeL11n();
|
$this->title = new MediaTypeL11n();
|
||||||
|
|
|
||||||
|
|
@ -120,8 +120,7 @@ class UploadFile
|
||||||
$path = $this->outputDir;
|
$path = $this->outputDir;
|
||||||
|
|
||||||
$subdir = '';
|
$subdir = '';
|
||||||
if (\stripos($f['name'], '/') !== false) {
|
if (($last = \strripos($f['name'], '/')) !== false) {
|
||||||
$last = \strripos($f['name'], '/');
|
|
||||||
$subdir = \substr($f['name'], 0, $last);
|
$subdir = \substr($f['name'], 0, $last);
|
||||||
$f['name'] = \substr($f['name'], $last + 1);
|
$f['name'] = \substr($f['name'], $last + 1);
|
||||||
}
|
}
|
||||||
|
|
@ -265,7 +264,7 @@ class UploadFile
|
||||||
|
|
||||||
do {
|
do {
|
||||||
++$limit;
|
++$limit;
|
||||||
$sha = empty($nameWithoutExtension) ? \sha1($tempName . $rnd) : $nameWithoutExtension . '_' . $rnd;
|
$sha = empty($nameWithoutExtension) ? \sha1($tempName . $rnd) : $nameWithoutExtension . (empty($rnd) ? '' : '_' . $rnd);
|
||||||
|
|
||||||
if ($sha === false) {
|
if ($sha === false) {
|
||||||
throw new \Exception('No file path could be found. Potential attack!');
|
throw new \Exception('No file path could be found. Potential attack!');
|
||||||
|
|
@ -273,7 +272,7 @@ class UploadFile
|
||||||
|
|
||||||
$sha .= '.' . $extension;
|
$sha .= '.' . $extension;
|
||||||
$fileName = $sha;
|
$fileName = $sha;
|
||||||
$rnd = \mt_rand();
|
$rnd = (string) \mt_rand();
|
||||||
} while (\is_file($path . '/' . $fileName) && $limit < self::PATH_GENERATION_LIMIT);
|
} while (\is_file($path . '/' . $fileName) && $limit < self::PATH_GENERATION_LIMIT);
|
||||||
|
|
||||||
if ($limit >= self::PATH_GENERATION_LIMIT) {
|
if ($limit >= self::PATH_GENERATION_LIMIT) {
|
||||||
|
|
@ -293,6 +292,7 @@ class UploadFile
|
||||||
*
|
*
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
*/
|
*/
|
||||||
|
/*
|
||||||
private function interlace(string $extension, string $path) : void
|
private function interlace(string $extension, string $path) : void
|
||||||
{
|
{
|
||||||
if ($extension === 'png') {
|
if ($extension === 'png') {
|
||||||
|
|
@ -319,6 +319,7 @@ class UploadFile
|
||||||
|
|
||||||
\imagedestroy($img);
|
\imagedestroy($img);
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Find unique output path for batch of files
|
* Find unique output path for batch of files
|
||||||
|
|
|
||||||
|
|
@ -257,6 +257,25 @@ $CONFIG = [
|
||||||
'root' => '/',
|
'root' => '/',
|
||||||
'https' => false,
|
'https' => false,
|
||||||
],
|
],
|
||||||
|
'app' => [
|
||||||
|
'path' => __DIR__,
|
||||||
|
'default' => [
|
||||||
|
'app' => 'Backend',
|
||||||
|
'id' => 'backend',
|
||||||
|
'lang' => 'en',
|
||||||
|
'theme' => 'Backend',
|
||||||
|
'org' => 1,
|
||||||
|
],
|
||||||
|
'domains' => [
|
||||||
|
'127.0.0.1' => [
|
||||||
|
'app' => 'Backend',
|
||||||
|
'id' => 'backend',
|
||||||
|
'lang' => 'en',
|
||||||
|
'theme' => 'Backend',
|
||||||
|
'org' => 1,
|
||||||
|
],
|
||||||
|
],
|
||||||
|
],
|
||||||
'socket' => [
|
'socket' => [
|
||||||
'master' => [
|
'master' => [
|
||||||
'host' => '127.0.0.1',
|
'host' => '127.0.0.1',
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user