Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
sugeng-sulistiyawan committed Oct 18, 2024
1 parent 4853386 commit 4236ffd
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions src/GoogleDriveComponent.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Google\Client;
use Google\Service\Drive;
use League\Flysystem\PathPrefixing\PathPrefixedAdapter;
use Masbug\Flysystem\GoogleDriveAdapter;
use yii\base\InvalidConfigException;

Expand All @@ -19,6 +20,7 @@
* 'clientId' => '',
* 'clientSecret' => '',
* 'refreshToken' => '',
* 'folder' => '',
* // 'teamDriveId' => '',
* // 'sharedFolderId' => '',
* // 'options' => [],
Expand Down Expand Up @@ -54,6 +56,11 @@ class GoogleDriveComponent extends AbstractComponent
*/
public $refreshToken;

/**
* @var string
*/
public $folder;

/**
* @var string
*/
Expand Down Expand Up @@ -115,11 +122,19 @@ protected function initAdapter()
$client->setClientId($this->clientId);
$client->setClientSecret($this->clientSecret);
$client->refreshToken(refreshToken: $this->refreshToken);
$client->setApplicationName($this->applicationName);

if (!empty($this->applicationName)) {
$client->setApplicationName($this->applicationName);
}

$this->client = $client;
$service = new Drive($this->client);
$adapter = new GoogleDriveAdapter($service, $this->folder, $this->options);

if ($this->prefix) {
$adapter = new PathPrefixedAdapter($adapter, $this->prefix);
}

return new GoogleDriveAdapter($service, $this->prefix, $this->options);
return $adapter;
}
}

0 comments on commit 4236ffd

Please sign in to comment.