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

Set root folder for appDataFolder spaces #54

Merged
merged 1 commit into from
Feb 17, 2022
Merged

Set root folder for appDataFolder spaces #54

merged 1 commit into from
Feb 17, 2022

Conversation

dragermrb
Copy link
Contributor

This PR allows to use appDataFolder as spaces.

Actually this library uses 'root' as the root folder. The name 'root' is an alias to My Drive, but this alias only works on 'drive' spaces.

If you want to use appDataFolder space it doesn't works because 'root' is not a valid parent root folder.

Taking the Laravel Example, at the ServiceProvider, look at $options:

namespace App\Providers;

use Illuminate\Support\Facades\Storage;
use Illuminate\Support\ServiceProvider;

class AppServiceProvider extends ServiceProvider { // can be a custom ServiceProvider
    // ...
    public function boot(){
        // ...
        try {
            \Storage::extend('google', function($app, $config) {
                $options = [
                    'spaces' => 'appDataFolder', // <==== This will fail without this PR
                ];

                if (!empty($config['teamDriveId'] ?? null)) {
                    $options['teamDriveId'] = $config['teamDriveId'];
                }

                $client = new \Google\Client();
                $client->setClientId($config['clientId']);
                $client->setClientSecret($config['clientSecret']);
                $client->refreshToken($config['refreshToken']);
                
                $service = new \Google\Service\Drive($client);
                $adapter = new \Masbug\Flysystem\GoogleDriveAdapter($service, $config['folder'] ?? '/', $options);
                $driver = new \League\Flysystem\Filesystem($adapter);

                return new \Illuminate\Filesystem\FilesystemAdapter($driver, $adapter);
            });
        } catch(\Exception $e) {
            // your exception handling logic
        }
        // ...
    }
    // ...
}

@masbug masbug merged commit 81afc0d into masbug:1.x Feb 17, 2022
@masbug
Copy link
Owner

masbug commented Feb 17, 2022

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants