-
Couldn't load subscription status.
- Fork 18
FEATURE: Add TUS file upload #106
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 13 commits
5ebff00
54632b7
f87a494
86f15f3
d7dbfca
c3dc792
2ee5eb9
391cea2
cf770ee
df48123
cf8bbbf
57c394e
b3e889d
553a3bf
d7d90a6
6d7cd01
df7b3c2
bfefdff
d5f78ab
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,71 @@ | ||
| <?php | ||
| declare(strict_types=1); | ||
|
|
||
| namespace Flowpack\Media\Ui\Service; | ||
|
|
||
| /* | ||
| * This file is part of the Flowpack.Media.Ui package. | ||
| * | ||
| * (c) Contributors of the Neos Project - www.neos.io | ||
| * | ||
| * This package is Open Source Software. For the full copyright and license | ||
| * information, please view the LICENSE file which was distributed with this | ||
| * source code. | ||
| */ | ||
|
|
||
| use Neos\Flow\Annotations as Flow; | ||
| use Neos\Utility\Exception\FilesException; | ||
| use Neos\Utility\Files; | ||
|
|
||
| class ConfigurationService | ||
| { | ||
| /** | ||
| * @Flow\InjectConfiguration(package="Flowpack.Media.Ui") | ||
| * @var array | ||
| */ | ||
| protected $configuration; | ||
|
|
||
| /** | ||
| * Returns the maximum size of files that can be uploaded | ||
| * | ||
| * @return int | ||
| */ | ||
| public function getMaximumUploadFileSize(): int | ||
| { | ||
| try { | ||
| return (int)Files::sizeStringToBytes($this->configuration['maximimFileUploadSize'] ?? '100MB'); | ||
| } catch (FilesException $e) { | ||
| return 0; | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Returns the maximum of server capable upload size and configured maximum chunk size | ||
| * | ||
| * @return int | ||
| */ | ||
| public function getMaximumUploadChunkSize(): int | ||
| { | ||
| try { | ||
| return max( | ||
| (int)($this->configuration['maximumUploadChunkSize'] ?? '5MB'), | ||
| (int)min( | ||
| Files::sizeStringToBytes(ini_get('post_max_size')), | ||
| Files::sizeStringToBytes(ini_get('upload_max_filesize')) | ||
| ) | ||
| ); | ||
| } catch (FilesException $e) { | ||
| return 5*1024*1024; | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Returns the maximum number of files that can be uploaded | ||
| * | ||
| * @return int | ||
| */ | ||
| public function getMaximumUploadFileCount(): int | ||
| { | ||
| return (int)($this->configuration['maximumUploadFileCount'] ?? 10); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,108 @@ | ||
| <?php | ||
| declare(strict_types=1); | ||
|
|
||
| namespace Flowpack\Media\Ui\Tus; | ||
|
|
||
| /* | ||
| * This file is part of the Flowpack.Media.Ui package. | ||
| * | ||
| * (c) Contributors of the Neos Project - www.neos.io | ||
| * | ||
| * This package is Open Source Software. For the full copyright and license | ||
| * information, please view the LICENSE file which was distributed with this | ||
| * source code. | ||
| */ | ||
|
|
||
| use Carbon\Carbon; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This dependency doesn't seem to be included in the |
||
| use Neos\Cache\Frontend\StringFrontend; | ||
| use Neos\Utility\Exception\PropertyNotAccessibleException; | ||
| use Neos\Utility\ObjectAccess; | ||
| use TusPhp\Cache\Cacheable; | ||
|
|
||
| class PartialUploadFileCacheAdapter implements Cacheable | ||
| { | ||
|
|
||
| /** | ||
| * @var StringFrontend | ||
| */ | ||
| protected $partialUploadFileCache; | ||
|
|
||
| /** | ||
| * @param string $key | ||
| * @param bool $withExpired | ||
| * @return mixed|null | ||
| * @throws \JsonException | ||
| */ | ||
| public function get(string $key, bool $withExpired = false) | ||
| { | ||
| $contents = $this->partialUploadFileCache->get($key); | ||
| if (!is_string($contents)) { | ||
| return null; | ||
| } | ||
|
|
||
| $contents = json_decode($contents, true, 512, JSON_THROW_ON_ERROR); | ||
|
|
||
| if ($withExpired) { | ||
| return $contents; | ||
| } | ||
|
|
||
| if (!$contents) { | ||
| return null; | ||
| } | ||
|
|
||
| $isExpired = Carbon::parse($contents['expires_at'])->lt(Carbon::now()); | ||
|
|
||
| return $isExpired ? null : $contents; | ||
| } | ||
|
|
||
| public function set(string $key, $value) | ||
| { | ||
| $contents = $this->get($key) ?? []; | ||
|
|
||
| if (\is_array($value)) { | ||
| $contents = $value + $contents; | ||
| } else { | ||
| $contents[] = $value; | ||
| } | ||
|
|
||
| $this->partialUploadFileCache->set($this->getPrefix() . $key, json_encode($contents)); | ||
|
|
||
| return true; | ||
| } | ||
|
|
||
| public function delete(string $key): bool | ||
| { | ||
| return $this->partialUploadFileCache->remove($key); | ||
| } | ||
|
|
||
| public function deleteAll(array $keys): bool | ||
| { | ||
| $this->partialUploadFileCache->flush(); | ||
| return true; | ||
| } | ||
|
|
||
| /** | ||
| * @throws PropertyNotAccessibleException | ||
| */ | ||
| public function getTtl(): int | ||
| { | ||
| return 60*60*24; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This line should go right? |
||
| return (int)ObjectAccess::getProperty($this->partialUploadFileCache->getBackend(), 'defaultLifetime', true); | ||
| } | ||
|
|
||
| public function keys(): array | ||
| { | ||
| // @todo implement a replacement for keys() for flow cache backends | ||
| return []; | ||
| } | ||
|
|
||
| public function setPrefix(string $prefix): Cacheable | ||
| { | ||
| return $this; | ||
| } | ||
|
|
||
| public function getPrefix(): string | ||
| { | ||
| return ''; | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.