mirror of
https://github.com/Karaka-Management/oms-Media.git
synced 2026-01-27 00:08:40 +00:00
formatting fixes, bug fixes and support impl.
This commit is contained in:
parent
391b48dbff
commit
d0f7703b54
|
|
@ -186,7 +186,7 @@ final class Installer extends InstallerAbstract
|
|||
? ApiController::createMediaPath()
|
||||
: __DIR__ . '/../../..' . $data['path'];
|
||||
|
||||
$status = $upload->upload($files, $data['name'], true);
|
||||
$status = $upload->upload($files, [$data['name']], true);
|
||||
|
||||
$mediaFiles = [];
|
||||
foreach ($status as $uFile) {
|
||||
|
|
|
|||
|
|
@ -69,7 +69,7 @@ final class ApiController extends Controller
|
|||
public function apiMediaUpload(RequestAbstract $request, ResponseAbstract $response, $data = null) : void
|
||||
{
|
||||
$uploads = $this->uploadFiles(
|
||||
$request->getData('name') === null || \count($request->getFiles()) > 1 ? '' : $request->getData('name'),
|
||||
[$request->getData('name') === null ? '' : $request->getData('name')],
|
||||
$request->getFiles(),
|
||||
$request->header->account,
|
||||
__DIR__ . '/../../../Modules/Media/Files' . \urldecode((string) ($request->getData('path') ?? '')),
|
||||
|
|
@ -120,7 +120,7 @@ final class ApiController extends Controller
|
|||
/**
|
||||
* Upload a media file
|
||||
*
|
||||
* @param string $name Name
|
||||
* @param array $names Name
|
||||
* @param array $files Files
|
||||
* @param int $account Uploader
|
||||
* @param string $basePath Base path. The path which is used for the upload.
|
||||
|
|
@ -138,7 +138,7 @@ final class ApiController extends Controller
|
|||
* @since 1.0.0
|
||||
*/
|
||||
public function uploadFiles(
|
||||
string $name,
|
||||
array $names,
|
||||
array $files,
|
||||
int $account,
|
||||
string $basePath = '/Modules/Media/Files',
|
||||
|
|
@ -147,7 +147,8 @@ final class ApiController extends Controller
|
|||
string $password = '',
|
||||
string $encryptionKey = '',
|
||||
int $pathSettings = PathSettings::RANDOM_PATH
|
||||
) : array {
|
||||
) : array
|
||||
{
|
||||
if (empty($files)) {
|
||||
return [];
|
||||
}
|
||||
|
|
@ -167,7 +168,7 @@ final class ApiController extends Controller
|
|||
$upload = new UploadFile();
|
||||
$upload->outputDir = $outputDir;
|
||||
|
||||
$status = $upload->upload($files, $name, $absolute, $encryptionKey);
|
||||
$status = $upload->upload($files, $names, $absolute, $encryptionKey);
|
||||
|
||||
return $this->createDbEntries($status, $account, $virtualPath, $type);
|
||||
}
|
||||
|
|
@ -176,7 +177,7 @@ final class ApiController extends Controller
|
|||
* Uploads a file to a destination
|
||||
*
|
||||
* @param array $files Files to upload
|
||||
* @param string $name Name of the file (only if a single file is provided)
|
||||
* @param array $names Name of the file (only if a single file is provided)
|
||||
* @param string $path Upload path
|
||||
*
|
||||
* @return array
|
||||
|
|
@ -185,13 +186,14 @@ final class ApiController extends Controller
|
|||
*/
|
||||
public static function uploadFilesToDestination(
|
||||
array $files,
|
||||
string $name = '',
|
||||
array $names = [],
|
||||
string $path = '',
|
||||
) : array {
|
||||
) : array
|
||||
{
|
||||
$upload = new UploadFile();
|
||||
$upload->outputDir = $path;
|
||||
|
||||
$status = $upload->upload($files, $name, true, '');
|
||||
$status = $upload->upload($files, $names, true, '');
|
||||
|
||||
return $status;
|
||||
}
|
||||
|
|
@ -212,6 +214,8 @@ final class ApiController extends Controller
|
|||
}
|
||||
|
||||
/**
|
||||
* Create database entries for uploaded files
|
||||
*
|
||||
* @param array $status Files
|
||||
* @param int $account Uploader
|
||||
* @param string $virtualPath Virtual path
|
||||
|
|
@ -228,7 +232,8 @@ final class ApiController extends Controller
|
|||
string $virtualPath = '',
|
||||
string $type = '',
|
||||
string $ip = '127.0.0.1'
|
||||
) : array {
|
||||
) : array
|
||||
{
|
||||
$mediaCreated = [];
|
||||
|
||||
foreach ($status as $uFile) {
|
||||
|
|
|
|||
|
|
@ -82,11 +82,11 @@ class UploadFile
|
|||
/**
|
||||
* Upload file to server.
|
||||
*
|
||||
* @param array $files File data ($_FILE)
|
||||
* @param string $name File name
|
||||
* @param bool $absolute Use absolute path
|
||||
* @param string $encryptionKey Encryption key
|
||||
* @param string $encoding Encoding used for uploaded file. Empty string will not convert file content.
|
||||
* @param array $files File data ($_FILE)
|
||||
* @param string[] $names File name
|
||||
* @param bool $absolute Use absolute path
|
||||
* @param string $encryptionKey Encryption key
|
||||
* @param string $encoding Encoding used for uploaded file. Empty string will not convert file content.
|
||||
*
|
||||
* @return array
|
||||
*
|
||||
|
|
@ -96,26 +96,30 @@ class UploadFile
|
|||
*/
|
||||
public function upload(
|
||||
array $files,
|
||||
string $name = '',
|
||||
array $names = [],
|
||||
bool $absolute = false,
|
||||
string $encryptionKey = '',
|
||||
string $encoding = 'UTF-8'
|
||||
) : array {
|
||||
) : array
|
||||
{
|
||||
$result = [];
|
||||
|
||||
if (\count($files) === \count($files, \COUNT_RECURSIVE)) {
|
||||
$files = [$files];
|
||||
}
|
||||
|
||||
$fileCount = \count($files);
|
||||
|
||||
if (!$absolute && \count($files) > 1) {
|
||||
$this->outputDir = $this->findOutputDir();
|
||||
}
|
||||
|
||||
$path = $this->outputDir;
|
||||
$path = $this->outputDir;
|
||||
$fCounter = -1;
|
||||
$areNamed = \count($files) === \count($names);
|
||||
|
||||
foreach ($files as $key => $f) {
|
||||
++$fCounter;
|
||||
$name = $areNamed ? $names[$fCounter] : '';
|
||||
|
||||
if ($path === '') {
|
||||
$path = File::dirpath($f['tmp_name']);
|
||||
}
|
||||
|
|
@ -148,9 +152,7 @@ class UploadFile
|
|||
}
|
||||
|
||||
$split = \explode('.', $f['name']);
|
||||
$result[$key]['filename'] = \count($files) === 1 && !empty($name)
|
||||
? $name
|
||||
: $f['name'];
|
||||
$result[$key]['filename'] = !empty($name) ? $name : $f['name'];
|
||||
|
||||
$extension = \count($split) > 1 ? $split[\count($split) - 1] : '';
|
||||
$result[$key]['extension'] = $extension;
|
||||
|
|
@ -160,7 +162,7 @@ class UploadFile
|
|||
$result[$key]['filename'] = $name;
|
||||
}
|
||||
|
||||
if (!$this->preserveFileName || $fileCount !== 1 || empty($name) || \is_file($path . '/' . $name)) {
|
||||
if (!$this->preserveFileName || empty($name) || \is_file($path . '/' . $name)) {
|
||||
try {
|
||||
$name = $this->createFileName($path, $f['tmp_name'], $extension);
|
||||
$result[$key]['filename'] = $name;
|
||||
|
|
|
|||
|
|
@ -172,7 +172,7 @@ trait ApiControllerMediaTrait
|
|||
{
|
||||
self::assertEquals(
|
||||
[],
|
||||
$this->module->uploadFiles('test', ['test'], 1, '/test', '', '', '', '', 99)
|
||||
$this->module->uploadFiles(['test'], ['test'], 1, '/test', '', '', '', '', 99)
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user