Skip to content
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

Update readme #36

Merged
merged 3 commits into from
Nov 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 74 additions & 0 deletions Classes/Client/DropboxThumbnailSizes.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
<?php

declare(strict_types=1);

/*
* This file is part of the package stefanfroemken/dropbox.
*
* For the full copyright and license information, please read the
* LICENSE file that was distributed with this source code.
*/

namespace StefanFroemken\Dropbox\Client;

class DropboxThumbnailSizes
{
/**
* Dropbox API can only retrieve thumbnails in a specific dimension:
* @link: https://www.dropbox.com/developers/documentation/http/documentation#files-get_thumbnail
* List must be lower to higher
*/
private array $thumbnailDimensions = [
'w32h32' => [
'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 '';
}
}
19 changes: 5 additions & 14 deletions Classes/Driver/DropboxDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 12 additions & 3 deletions Classes/Resource/Processing/ImageProcessing.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand All @@ -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);
Expand Down
19 changes: 19 additions & 0 deletions Documentation/AdministratorManual/Update/Index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
=======================

Expand Down
7 changes: 7 additions & 0 deletions Documentation/ChangeLog/Index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
=============
Expand Down
48 changes: 18 additions & 30 deletions Documentation/Configuration/Index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -81,20 +60,29 @@ 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
:width: 500px
: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.

Expand All @@ -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
Expand Down
64 changes: 38 additions & 26 deletions Documentation/FAQ/Index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,40 +7,52 @@
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
========================
I know, but let me explain:

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.
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.

How to solve that?

Uploaded file could not be moved!
=================================
* 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 <configuration>`
* Keep your files as small as possible in dropbox storage.

Cut and Paste copies files
==========================

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.
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.
4 changes: 2 additions & 2 deletions Documentation/Introduction/Index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
17 changes: 8 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand All @@ -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)
Loading
Loading