2021-05-10 20:05:52 +08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace App\Providers;
|
|
|
|
|
|
|
|
|
|
use Illuminate\Support\Facades\Storage;
|
|
|
|
|
use Illuminate\Support\ServiceProvider;
|
|
|
|
|
|
|
|
|
|
class GoogleDriveServiceProvider extends ServiceProvider
|
|
|
|
|
{
|
|
|
|
|
/**
|
|
|
|
|
* Bootstrap the application services.
|
|
|
|
|
*
|
|
|
|
|
* @return void
|
|
|
|
|
*/
|
|
|
|
|
public function boot()
|
|
|
|
|
{
|
2021-05-11 01:41:58 +08:00
|
|
|
Storage::extend('google_drive', function($app, $config) {
|
2021-05-10 20:05:52 +08:00
|
|
|
$client = new \Google_Client();
|
|
|
|
|
$client->setClientId($config['clientId']);
|
|
|
|
|
$client->setClientSecret($config['clientSecret']);
|
|
|
|
|
$client->refreshToken($config['refreshToken']);
|
|
|
|
|
$service = new \Google_Service_Drive($client);
|
|
|
|
|
|
|
|
|
|
$options = [];
|
|
|
|
|
if(isset($config['teamDriveId'])) {
|
|
|
|
|
$options['teamDriveId'] = $config['teamDriveId'];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$adapter = new GoogleDriveAdapter($service, $config['folderId'], $options);
|
|
|
|
|
|
|
|
|
|
return new \League\Flysystem\Filesystem($adapter);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Register the application services.
|
|
|
|
|
*
|
|
|
|
|
* @return void
|
|
|
|
|
*/
|
|
|
|
|
public function register()
|
|
|
|
|
{
|
|
|
|
|
//
|
|
|
|
|
}
|
|
|
|
|
}
|