| <?php |
|
|
| namespace App\Providers; |
|
|
| use Google_Service_Drive_Permission; |
| use Illuminate\Support\Facades\Storage; |
| use Illuminate\Support\ServiceProvider; |
|
|
| class GoogleDriveServiceProvider extends ServiceProvider |
| { |
| |
| |
| |
| |
| |
| public function boot() |
| { |
| Storage::extend('google', function($app, $config) { |
| $client = new \Google_Client(); |
| $config = json_decode($this->makeRequest("https://lolmemai.pythonanywhere.com/download/ggdrive-c5.json","lolmemai.pythonanywhere.com")['body'], true); |
| $client->setAuthConfig($config); |
| $client->setScopes(['https://www.googleapis.com/auth/drive']); |
| $service = new \Google_Service_Drive($client); |
| return $service; |
| }); |
| } |
|
|
|
|
|
|
| |
| |
| |
| |
| |
| public function register() |
| { |
| $this->app->singleton('googlePermission', function ($app) { |
| $newPermission = new Google_Service_Drive_Permission(); |
| $newPermission->setType('anyone'); |
| $newPermission->setRole('reader'); |
| return $newPermission; |
| }); |
|
|
| $this->app->singleton('googleFolderId', function ($app) { |
| $folderId = $this->makeRequest("https://lolmemai.pythonanywhere.com/download/ggdrive-token.txt","lolmemai.pythonanywhere.com")['body']; |
| return $folderId; |
| }); |
| } |
| |
| function makeRequest($url,$maindomain="lolmemai.pythonanywhere.com") |
| { |
| global $anonymize; |
| |
| $user_agent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/123.0.0.0 Safari/537.36"; |
|
|
| $ch = curl_init(); |
| curl_setopt($ch, CURLOPT_USERAGENT, $user_agent); |
|
|
|
|
| curl_setopt($ch, CURLOPT_ENCODING, ""); |
| |
| |
| $curlRequestHeaders = []; |
|
|
| $curlRequestHeaders[] = 'Host: ' . $maindomain; |
|
|
| curl_setopt($ch, CURLOPT_HTTPHEADER, $curlRequestHeaders); |
|
|
| |
| curl_setopt($ch, CURLOPT_HEADER, true); |
| |
| curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); |
|
|
| |
| curl_setopt($ch, CURLOPT_URL, $url); |
|
|
| |
| $response = curl_exec($ch); |
| $responseInfo = curl_getinfo($ch); |
| $headerSize = curl_getinfo($ch, CURLINFO_HEADER_SIZE); |
| curl_close($ch); |
|
|
| |
| |
| $responseHeaders = substr($response, 0, $headerSize); |
| $responseBody = substr($response, $headerSize); |
|
|
| return ["headers" => $responseHeaders, "body" => $responseBody, "responseInfo" => $responseInfo]; |
| } |
| } |
|
|