-
Notifications
You must be signed in to change notification settings - Fork 17
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
FEATURE: Add TUS file upload #106
Open
daniellienert
wants to merge
19
commits into
Flowpack:main
Choose a base branch
from
punktDeForks:feature/use-tus-for-upload-on-separate-endpoint
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
5ebff00
FEATURE: Add first draft of tus upload backend
daniellienert 54632b7
TASK: Add tus-php to composer.json
daniellienert f87a494
TASK: Fullfill cache backend method interfaces
daniellienert 86f15f3
TASK: Change method headers to please PHPStan
daniellienert d7dbfca
TASK: Optinally accept rsource identifier
daniellienert c3dc792
TASK: Set upload directorxy path
daniellienert 2ee5eb9
TASK: adjust upload files hook to use tus client
andrehoffmann30 391cea2
TASK: Split maximimFileUploadSize from MaxChunkUploadSize
daniellienert cf770ee
TASK: Unify configuration setting keys
daniellienert df48123
TASK: Remove complete uploaded file after importing
daniellienert cf8bbbf
TASK: adjust media ui graphql schema for new config variables
andrehoffmann30 57c394e
TASK: Mute PhpStan complaint
daniellienert b3e889d
TASK: Refactor configuration into own service
daniellienert 553a3bf
BUGFIX: Fix logical error and conversion in getMaximumUploadChunkSize
daniellienert d7d90a6
BUGFIX: Correct Status code and do not create asset twice
daniellienert 6d7cd01
FEATURE: refactor upload files hook, add progress info and indicator
andrehoffmann30 df7b3c2
TASK: add progress bar animation, add production build of assets
andrehoffmann30 bfefdff
TASK: Use flow cache adapter again
daniellienert d5f78ab
BUGFIX: Fix maximumUploadFileSize variable
daniellienert File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
<?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['maximumUploadFileSize'] ?? '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 min( | ||
(int)(Files::sizeStringToBytes($this->configuration['maximumUploadChunkSize']) ?? '5MB'), | ||
(int)Files::sizeStringToBytes(ini_get('post_max_size')), | ||
(int)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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
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 ''; | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This dependency doesn't seem to be included in the
composer.json
. Maybe we can get rid of this and replace the one method used?