mirror of
https://github.com/Karaka-Management/oms-Media.git
synced 2026-02-09 05:58: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\Local\Directory;
|
||||
use phpOMS\System\MimeType;
|
||||
use phpOMS\Utils\ImageUtils;
|
||||
use phpOMS\Utils\Parser\Markdown\Markdown;
|
||||
use phpOMS\Utils\Parser\Pdf\PdfParser;
|
||||
use phpOMS\Views\View;
|
||||
|
|
@ -212,9 +213,10 @@ final class ApiController extends Controller
|
|||
/**
|
||||
* Uploads a file to a destination
|
||||
*
|
||||
* @param array $files Files to upload
|
||||
* @param array $fileNames Names on the directory
|
||||
* @param string $path Upload path
|
||||
* @param array $files Files to upload
|
||||
* @param array $fileNames Names on the directory
|
||||
* @param string $path Upload path
|
||||
* @param bool $preserveFileName Preserve file name
|
||||
*
|
||||
* @return array
|
||||
*
|
||||
|
|
@ -224,10 +226,12 @@ final class ApiController extends Controller
|
|||
array $files,
|
||||
array $fileNames = [],
|
||||
string $path = '',
|
||||
bool $preserveFileName = true
|
||||
) : array
|
||||
{
|
||||
$upload = new UploadFile();
|
||||
$upload->outputDir = $path;
|
||||
$upload = new UploadFile();
|
||||
$upload->outputDir = $path; //empty($path) ? $upload->outputDir : $path;
|
||||
$upload->preserveFileName = $preserveFileName;
|
||||
|
||||
return $upload->upload($files, $fileNames, true, '');
|
||||
}
|
||||
|
|
@ -583,7 +587,7 @@ final class ApiController extends Controller
|
|||
*
|
||||
* @param string $path Virtual path of the 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
|
||||
*
|
||||
|
|
@ -1021,4 +1025,35 @@ final class ApiController extends Controller
|
|||
|
||||
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/title')
|
||||
->with('content')
|
||||
->where('id', $media->source->getId())
|
||||
->where('id', $media->source?->getId() ?? 0)
|
||||
->where('tags/title/language', $request->getLanguage())
|
||||
->execute();
|
||||
|
||||
|
|
|
|||
|
|
@ -58,7 +58,7 @@ class MediaType implements \JsonSerializable
|
|||
* @var string|MediaTypeL11n
|
||||
* @since 1.0.0
|
||||
*/
|
||||
protected $title;
|
||||
protected $title = '';
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
|
|
@ -108,7 +108,7 @@ class MediaType implements \JsonSerializable
|
|||
{
|
||||
if ($title instanceof MediaTypeL11n) {
|
||||
$this->title = $title;
|
||||
} elseif (isset($this->title) && $this->title instanceof MediaTypeL11n) {
|
||||
} elseif ($this->title instanceof MediaTypeL11n) {
|
||||
$this->title->title = $title;
|
||||
} else {
|
||||
$this->title = new MediaTypeL11n();
|
||||
|
|
|
|||
|
|
@ -120,8 +120,7 @@ class UploadFile
|
|||
$path = $this->outputDir;
|
||||
|
||||
$subdir = '';
|
||||
if (\stripos($f['name'], '/') !== false) {
|
||||
$last = \strripos($f['name'], '/');
|
||||
if (($last = \strripos($f['name'], '/')) !== false) {
|
||||
$subdir = \substr($f['name'], 0, $last);
|
||||
$f['name'] = \substr($f['name'], $last + 1);
|
||||
}
|
||||
|
|
@ -265,7 +264,7 @@ class UploadFile
|
|||
|
||||
do {
|
||||
++$limit;
|
||||
$sha = empty($nameWithoutExtension) ? \sha1($tempName . $rnd) : $nameWithoutExtension . '_' . $rnd;
|
||||
$sha = empty($nameWithoutExtension) ? \sha1($tempName . $rnd) : $nameWithoutExtension . (empty($rnd) ? '' : '_' . $rnd);
|
||||
|
||||
if ($sha === false) {
|
||||
throw new \Exception('No file path could be found. Potential attack!');
|
||||
|
|
@ -273,7 +272,7 @@ class UploadFile
|
|||
|
||||
$sha .= '.' . $extension;
|
||||
$fileName = $sha;
|
||||
$rnd = \mt_rand();
|
||||
$rnd = (string) \mt_rand();
|
||||
} while (\is_file($path . '/' . $fileName) && $limit < self::PATH_GENERATION_LIMIT);
|
||||
|
||||
if ($limit >= self::PATH_GENERATION_LIMIT) {
|
||||
|
|
@ -293,6 +292,7 @@ class UploadFile
|
|||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
/*
|
||||
private function interlace(string $extension, string $path) : void
|
||||
{
|
||||
if ($extension === 'png') {
|
||||
|
|
@ -319,6 +319,7 @@ class UploadFile
|
|||
|
||||
\imagedestroy($img);
|
||||
}
|
||||
*/
|
||||
|
||||
/**
|
||||
* Find unique output path for batch of files
|
||||
|
|
|
|||
|
|
@ -257,6 +257,25 @@ $CONFIG = [
|
|||
'root' => '/',
|
||||
'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' => [
|
||||
'master' => [
|
||||
'host' => '127.0.0.1',
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user