From b96e04ecf1e882d3de082a585ff0e39d9eab73de Mon Sep 17 00:00:00 2001 From: Stefan Froemken Date: Mon, 6 Nov 2023 20:11:08 +0100 Subject: [PATCH 1/3] Update documentation --- .../AdministratorManual/Update/Index.rst | 19 ++++++ Documentation/ChangeLog/Index.rst | 7 +++ Documentation/Configuration/Index.rst | 48 ++++++--------- Documentation/FAQ/Index.rst | 59 ++++++++++--------- Documentation/Introduction/Index.rst | 4 +- 5 files changed, 78 insertions(+), 59 deletions(-) diff --git a/Documentation/AdministratorManual/Update/Index.rst b/Documentation/AdministratorManual/Update/Index.rst index 375bf09..b945294 100644 --- a/Documentation/AdministratorManual/Update/Index.rst +++ b/Documentation/AdministratorManual/Update/Index.rst @@ -8,6 +8,25 @@ Updating If you update `dropbox` to a newer version, please read this section carefully! +Update to Version 5.0.0 +======================= + +Please execute the token wizard in driver record again to retrieve a fresh +refresh token. With that refresh token EXT:dropbox is available to generate +a new access token which is available for 4 hours. Remaining time of +current access token you can see in dropbox info section of dropbos driver +record. + +Im future files get bigger and bigger. Downloading these files just to access +the image dimension (width/height) can be very slow, costs traffic and of +cause CPU time. With version 5.0.0 I use the dropbox API to retrieve this +information. This is faster if you have a lot of huge files in your selected +folder, but it's slower, if you have a lot of tiny small files in your folder. + +Dropbox API can only retrieve image dimension (width/height) for images up to +20 MB. + + Update to Version 4.3.0 ======================= diff --git a/Documentation/ChangeLog/Index.rst b/Documentation/ChangeLog/Index.rst index 5a9ae84..c3601aa 100644 --- a/Documentation/ChangeLog/Index.rst +++ b/Documentation/ChangeLog/Index.rst @@ -13,6 +13,13 @@ Version 5.0.0 * Add TYPO3 12 compatibility * Remove TYPO3 10 compatibility * BUGFIX: Auto refresh AccessToken +* Get image width/height by dropbox API +* Render image preview with thumbnail provided by dropbox API +* Show remaining time of current AccessToken in driver configuration +* New client factory to use dropbox API nearly everywhere +* New PathInfoFactory to create path objects for files and folders +* New FlashMessageHelper to reduce complexity of other classes +* Update documentation. New configuration section. Version 4.3.0 ============= diff --git a/Documentation/Configuration/Index.rst b/Documentation/Configuration/Index.rst index 7a05a04..7ff2c5e 100644 --- a/Documentation/Configuration/Index.rst +++ b/Documentation/Configuration/Index.rst @@ -7,28 +7,7 @@ Configuration ============= -Create File Storage -=================== - -* Go to list module and choose PID 0 (Rootpage with TYPO3 logo in front). -* Create a new record of type ``File Storage`` -* On tab ``General`` choose a name like ``Dropbox`` -* On tab ``Configuration`` you have to choose the ``Dropbox`` driver - - -Driver Configuration -==================== - -To communicate over the Dropbox-API you need an Access Token. - -#. Create an App API at Dropbox.com -#. Copy ``App Key`` and ``App Secret`` -#. Get Access Token from developer area of www.dropbox.com - or you can create an access token with help of the wizard you can reach over ``GetAccessToken`` -#. Save the record - - -Create API at dropbox.com +Create APP at dropbox.com ------------------------- .. rst-class:: bignums @@ -81,11 +60,20 @@ Create API at dropbox.com an access token which you can copy&paste directly into the FAL storage record. +Create File Storage +=================== + +* Go to list module and choose PID 0 (Rootpage with TYPO3 logo in front). +* Create a new record of type ``File Storage`` +* On tab ``General`` choose a name like ``Dropbox`` +* On tab ``Configuration`` you have to choose the ``Dropbox`` driver + + Start Driver Wizard ------------------- -While editing the ``File storage`` click on ``GetAccessToken`` to start the wizard. -Paste in the ``App Key`` and ``App Secret`` from Dropbox App explained above. +While editing the ``File storage`` click on the + icon to start the wizard. +Paste in the ``App Key`` from Dropbox App explained above. Click on ``Get AuthCode Link`` .. figure:: ../Images/AdministratorManual/dropbox_insert_app_secret.jpg @@ -93,8 +81,8 @@ Click on ``Get AuthCode Link`` :align: left :alt: Insert app key and app secret -On the next page you have to click on the ``authorization link`` which will open a new tab -where you have to give access to your Dropbox App. +On the next page you have to click on the ``authorization link`` which will +open a new tab where you have to give access to your Dropbox App. Copy the AuthCode from Dropbox page into the AuthCode field of the Wizard. @@ -103,11 +91,11 @@ Copy the AuthCode from Dropbox page into the AuthCode field of the Wizard. :align: left :alt: Get Access Toekn from Dropbox -With a click on ``Get AccessToken`` a further request to dropbox.com will start in the background. -On success the Access Token will automatically inserted in ``File Storage`` record and -the wizard will close. +With a click on ``Get AccessToken`` a further request to dropbox.com will +start in the background. On success the Refresh Token will automatically +inserted in ``File Storage`` record and the wizard will close. -Save the record. On success we show you some user data. +Save the record. On success it will show you some user data. .. figure:: ../Images/AdministratorManual/dropbox_connect_success.jpg :width: 500px diff --git a/Documentation/FAQ/Index.rst b/Documentation/FAQ/Index.rst index 6b2f293..abcc065 100644 --- a/Documentation/FAQ/Index.rst +++ b/Documentation/FAQ/Index.rst @@ -7,40 +7,45 @@ FAQ === -My access token expires after 4 hours -===================================== +Upload of file XY failed +======================== -Please try following way to get an access token: +If you get this error message while uploading a new file, this is because you +have missed to activate the Dropbox Permission `files.content.write` in your +Dropbox App. Please visit: https://www.dropbox.com/developers +Choose your App, switch to tab `permission` and activate that option. -#. Visit https://www.dropbox.com/developers -#. Go to App Console -#. Open your Dropbox App -#. On "settings" tab you will find a "Generate" button to get an access token -#. Copy access token into configuration of your dropbox FAL storage -#. save +Uploaded file could not be moved! +================================= -PHP 8.0/8.1 compatibility -========================= +If you get this error message you have to activate the `files.content.write` +permission in Developer corner of Dropbox: https://www.dropbox.com/developers +but you have missed to re-authenticate your connection to Dropbox. Please move +to your Dropbox FAL storage and start the Authentication Wizard again. -My extension `dropbox` should be compatible with PHP 8.0 and 8.1, but the used PHP SDK -`kunalvarma05/dropbox-php-sdk` installs a complete out-dated `tightenco/collect` in version 5.2 which is not -compatible with PHP 8.0. That's why I have added the complete `tightenco/collect` package into my -`dropbox` extension and updated the out-dated classes on my own. -See: https://github.com/kunalvarma05/dropbox-php-sdk/pull/191 +Using Dropbox Storage is slow +============================= -Upload of file XY failed -======================== - -If you get this error message while uploading a new file, this is because you have missed to activate the -Dropbox Permission `files.content.write` in your Dropbox App. Please visit: https://www.dropbox.com/developers -Choose your App, switch to tab `permission` and activate that option. +I know, but let me explain: +Dropbox delivers an API call to retrieve all folders and files of a given +folder. But this request does not contain any image metadata like image +dimension (width/height) anymore since 2019. As TYPO3 needs this information +to render previews and the image in crop wizard, I have to start a second +request for EACH image in selected folder to retrieve the image dimensions +with help of another API endpoint. And if you have activated the image preview +in filelist module it needs a third dropbox call to retrieve a specific +thumbnail. All that costs a lot of time. -Uploaded file could not be moved! -================================= +How to solve that? -If you get this error message you have activate the `files.content.write` permission in Developer corner of -Dropbox: https://www.dropbox.com/developers but you have missed to re-authenticate your connection to Dropbox. -Please move to your Dropbox FAL storage and start the Authentication Wizard again. +* Disable image preview in filelist and file browser. If you have a lot of + images in your folder that would speed up the listing a lot +* Good structure in your dropbox folder. Try to keep the amount of folders + and files within a folder as small as possible +* Move the temporary folder for dropbox storage to a faster storage + (local storage/SSD). I have explained it + in section :ref:`Configure dropbox ` +* Keep your files as small as possible in dropbox storage. diff --git a/Documentation/Introduction/Index.rst b/Documentation/Introduction/Index.rst index 7ac5c1e..64628d8 100644 --- a/Documentation/Introduction/Index.rst +++ b/Documentation/Introduction/Index.rst @@ -7,8 +7,8 @@ What does it do? ================ -This extension adds a Dropbox FAL driver to TYPO3. With that driver you can browse, modify and delete files -from your Dropbox account. +This extension adds a Dropbox FAL driver to TYPO3. With that driver you can +browse, modify and delete files from your Dropbox account. Screenshot From be71767e2a37b2734ab5111d88f20ec0b777bef4 Mon Sep 17 00:00:00 2001 From: Stefan Froemken Date: Mon, 6 Nov 2023 20:13:29 +0100 Subject: [PATCH 2/3] Update explaination in ext_localconf.php --- ext_localconf.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/ext_localconf.php b/ext_localconf.php index f44bb06..b0386b7 100644 --- a/ext_localconf.php +++ b/ext_localconf.php @@ -11,7 +11,7 @@ 'label' => 'Dropbox', ]; - // create a temporary cache + // Create a temporary cache $GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations']['dropbox']['backend'] = \TYPO3\CMS\Core\Cache\Backend\TransientMemoryBackend::class; @@ -28,6 +28,7 @@ 'class' => \StefanFroemken\Dropbox\Form\Element\DropboxStatusElement::class, ]; + // Image Extractor is used to get image dimension from Dropbox API \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance( \TYPO3\CMS\Core\Resource\Index\ExtractorRegistry::class )->registerExtractionService(\StefanFroemken\Dropbox\Extractor\ImageExtractor::class); From cb7a22c5ea1764e8db944413926033082d61b209 Mon Sep 17 00:00:00 2001 From: Stefan Froemken Date: Mon, 6 Nov 2023 21:47:43 +0100 Subject: [PATCH 3/3] Update README. Use fixed image dim for dropbox API request --- Classes/Client/DropboxThumbnailSizes.php | 74 +++++++++++++++++++ Classes/Driver/DropboxDriver.php | 19 ++--- .../Resource/Processing/ImageProcessing.php | 15 +++- Documentation/FAQ/Index.rst | 7 ++ README.md | 17 ++--- 5 files changed, 106 insertions(+), 26 deletions(-) create mode 100644 Classes/Client/DropboxThumbnailSizes.php diff --git a/Classes/Client/DropboxThumbnailSizes.php b/Classes/Client/DropboxThumbnailSizes.php new file mode 100644 index 0000000..87432f5 --- /dev/null +++ b/Classes/Client/DropboxThumbnailSizes.php @@ -0,0 +1,74 @@ + [ + 'width' => 32, + 'height' => 32, + ], + 'w64h64' => [ + 'width' => 64, + 'height' => 64, + ], + 'w128h128' => [ + 'width' => 128, + 'height' => 128, + ], + 'w256h256' => [ + 'width' => 256, + 'height' => 256, + ], + 'w480h320' => [ + 'width' => 480, + 'height' => 320, + ], + 'w640h480' => [ + 'width' => 640, + 'height' => 480, + ], + 'w960h640' => [ + 'width' => 960, + 'height' => 640, + ], + 'w1024h768' => [ + 'width' => 1024, + 'height' => 768, + ], + 'w2048h1536' => [ + 'width' => 2048, + 'height' => 1536, + ], + ]; + + /** + * Returns a specific dropbox API string for thumbnail dimension like: w64h64 + * Returns empty string, if someone tries to retrive too huge dimensions (> 2048 pixel) + */ + public function getThumbnailSize(int $width, int $height): string + { + foreach ($this->thumbnailDimensions as $key => $thumbnailDimension) { + if ($width < $thumbnailDimension['width'] && $height < $thumbnailDimension['height']) { + return $key; + } + } + + return ''; + } +} diff --git a/Classes/Driver/DropboxDriver.php b/Classes/Driver/DropboxDriver.php index acdacc8..fa2c7fc 100644 --- a/Classes/Driver/DropboxDriver.php +++ b/Classes/Driver/DropboxDriver.php @@ -115,21 +115,12 @@ public function createFolder($newFolderName, $parentFolderIdentifier = '', $recu public function renameFolder($folderIdentifier, $newName): array { - $folderIdentifier = $this->canonicalizeAndCheckFolderIdentifier($folderIdentifier); - $newName = $this->sanitizeFileName($newName); - - $targetIdentifier = PathUtility::dirname($folderIdentifier) . '/' . $newName; - $targetIdentifier = $this->canonicalizeAndCheckFolderIdentifier($targetIdentifier); - - // dropbox don't like slashes at the end of identifier - $this->dropboxClient->getClient()->move( - rtrim($folderIdentifier, '/'), - rtrim($targetIdentifier, '/') + throw new \Exception( + 'Renaming is not implemented in EXT:dropbox as every file and folder has to be retrieved ' . + 'recursively, checked for existance, updated in sys_file and requests new thumbnails. That operation ' . + 'would need more time than configured in your PHP settings. Sorry.', + 1699301573 ); - - $this->cache->flush(); - - return []; } public function deleteFolder($folderIdentifier, $deleteRecursively = false): bool diff --git a/Classes/Resource/Processing/ImageProcessing.php b/Classes/Resource/Processing/ImageProcessing.php index 68c2bff..d5c39bd 100644 --- a/Classes/Resource/Processing/ImageProcessing.php +++ b/Classes/Resource/Processing/ImageProcessing.php @@ -14,6 +14,7 @@ use Psr\Http\Message\ServerRequestInterface; use StefanFroemken\Dropbox\Client\DropboxClient; use StefanFroemken\Dropbox\Client\DropboxClientFactory; +use StefanFroemken\Dropbox\Client\DropboxThumbnailSizes; use TYPO3\CMS\Core\Http\ApplicationType; use TYPO3\CMS\Core\Imaging\GraphicalFunctions; use TYPO3\CMS\Core\Resource\File; @@ -29,14 +30,19 @@ class ImageProcessing implements ProcessorInterface { private DropboxClientFactory $dropboxClientFactory; + private DropboxThumbnailSizes $dropboxThumbnailSizes; + private array $defaultConfiguration = [ 'width' => 64, 'height' => 64, ]; - public function __construct(DropboxClientFactory $dropboxClientFactory) - { + public function __construct( + DropboxClientFactory $dropboxClientFactory, + DropboxThumbnailSizes $dropboxThumbnailSizes + ) { $this->dropboxClientFactory = $dropboxClientFactory; + $this->dropboxThumbnailSizes = $dropboxThumbnailSizes; } public function canProcessTask(TaskInterface $task): bool @@ -56,7 +62,10 @@ public function processTask(TaskInterface $task): void $content = $dropboClient->getClient()->getThumbnail( $task->getSourceFile()->getIdentifier(), 'jpeg', - 'w' . $configuration['width'] . 'h' . $configuration['height'] + $this->dropboxThumbnailSizes->getThumbnailSize( + (int)$configuration['width'], + (int)$configuration['height'] + ) ); $temporaryFilePath = $this->getTemporaryFilePath($task); diff --git a/Documentation/FAQ/Index.rst b/Documentation/FAQ/Index.rst index abcc065..631deb0 100644 --- a/Documentation/FAQ/Index.rst +++ b/Documentation/FAQ/Index.rst @@ -49,3 +49,10 @@ How to solve that? (local storage/SSD). I have explained it in section :ref:`Configure dropbox ` * Keep your files as small as possible in dropbox storage. + +Cut and Paste copies files +========================== + +That happens if you have deactivated the clipboard. Please activate the +clipboard. You will find a button to activate "moving" files instead of +"copying". If you know paste the file, it will be moved instead. diff --git a/README.md b/README.md index 5cb3e8a..e2003b9 100644 --- a/README.md +++ b/README.md @@ -4,9 +4,9 @@ ## 1 What does it do? -`dropbox` is an Extension for TYPO3 >= 10.4.0. +`dropbox` is an Extension for TYPO3 >= 11.5.30. It extends TYPO3's FAL (File Abstraction Layer) to show files from your -Dropbox Account in file list module of TYPO3. +Dropbox Account in filelist module of TYPO3. ## 2 Installation @@ -59,14 +59,9 @@ up to 5 devices can connect to this app: Have fun using your dropbox files in TYPO3. -**ToDo:** +**Features:** -* rename folder -* delete folder - -** Done:** - -* you can create folders +* you can create and delete folders * you can navigate through the folders * move files * copy files @@ -75,3 +70,7 @@ Have fun using your dropbox files in TYPO3. * rename file * creation of thumbs works * copy files to upload folder + +**Not implemented** + +* Renaming folders (will throw exception)