-
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathPlugin.php
More file actions
53 lines (46 loc) · 1.54 KB
/
Copy pathPlugin.php
File metadata and controls
53 lines (46 loc) · 1.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
<?php namespace Winter\DriverGoogleDrive;
use Google\Client;
use Google\Service\Drive;
use Illuminate\Filesystem\FilesystemAdapter;
use Illuminate\Support\Facades\Storage;
use League\Flysystem\Filesystem;
use Masbug\Flysystem\GoogleDriveAdapter;
use System\Classes\PluginBase;
/**
* DriverGoogleDrive Plugin Information File
*/
class Plugin extends PluginBase
{
/**
* Returns information about this plugin.
*/
public function pluginDetails(): array
{
return [
'name' => 'winter.drivergoogledrive::lang.plugin.name',
'description' => 'winter.drivergoogledrive::lang.plugin.description',
'author' => 'Winter',
'icon' => 'icon-leaf',
];
}
/**
* Boot method, called right before the request route.
*/
public function boot(): void
{
Storage::extend('googledrive', function($app, $config) {
$options = [];
if (!empty($config['teamDriveId'] ?? null)) {
$options['teamDriveId'] = $config['teamDriveId'];
}
$client = new Client();
$client->setClientId($config['clientId']);
$client->setClientSecret($config['clientSecret']);
$client->refreshToken($config['refreshToken']);
$service = new Drive($client);
$adapter = new GoogleDriveAdapter($service, $config['folder'] ?? '/', $options);
$driver = new Filesystem($adapter);
return new FilesystemAdapter($driver, $adapter);
});
}
}