From 525c9edc65156460addfb99b49d5c5a64a3e7d84 Mon Sep 17 00:00:00 2001 From: F4ilji Date: Fri, 5 Sep 2025 23:42:06 +0500 Subject: [PATCH] Refactor VK service URLs to use 'vk.ru' instead of 'vk.com' for consistency; update CORS configuration to allow additional methods and origins, enhancing API security and flexibility. --- app/Filament/Components/Forms/PostForm.php | 8 +++--- app/Services/VK/Album/VkAlbumService.php | 2 +- app/Services/VK/VkAuthService.php | 8 +++--- app/Services/VK/VkService.php | 8 +++--- app/Services/VK/Wall/VkWallService.php | 4 +-- config/cors.php | 32 ++++++++++------------ 6 files changed, 29 insertions(+), 33 deletions(-) diff --git a/app/Filament/Components/Forms/PostForm.php b/app/Filament/Components/Forms/PostForm.php index 4d7125a..e082864 100644 --- a/app/Filament/Components/Forms/PostForm.php +++ b/app/Filament/Components/Forms/PostForm.php @@ -126,10 +126,10 @@ class PostForm ->label('Опубликовать в VK') ->default(true) ->helperText('Новость будет автоматически опубликована в VK'), - Toggle::make('publication.telegram') - ->label('Опубликовать в Telegram') - ->default(true) - ->helperText('Новость будет автоматически опубликована в Telegram'), +// Toggle::make('publication.telegram') +// ->label('Опубликовать в Telegram') +// ->default(true) +// ->helperText('Новость будет автоматически опубликована в Telegram'), ]), ]), ]), diff --git a/app/Services/VK/Album/VkAlbumService.php b/app/Services/VK/Album/VkAlbumService.php index 91c86ec..6755994 100644 --- a/app/Services/VK/Album/VkAlbumService.php +++ b/app/Services/VK/Album/VkAlbumService.php @@ -103,7 +103,7 @@ class VkAlbumService public function saveImagesToUploadServer($albumId, $server, $photosList, $hash) { // URL для запроса - $url = 'https://api.vk.com/method/photos.save'; + $url = 'https://api.vk.ru/method/photos.save'; // Подготовка данных для отправки $postFields = [ diff --git a/app/Services/VK/VkAuthService.php b/app/Services/VK/VkAuthService.php index f4503c0..270f479 100644 --- a/app/Services/VK/VkAuthService.php +++ b/app/Services/VK/VkAuthService.php @@ -44,7 +44,7 @@ class VkAuthService // session(['vk_code_verifier' => $code_verifier]); // // -// $url = 'https://id.vk.com/authorize?' . http_build_query([ +// $url = 'https://id.vk.ru/authorize?' . http_build_query([ // 'response_type' => 'code', // 'client_id' => env('VK_APP_ID'), // 'redirect_uri' => env('VK_REDIRECT_URI'), @@ -67,7 +67,7 @@ class VkAuthService session(['vk_code_verifier' => $code_verifier]); // Сохраняет code_verifier в сессии под ключом 'vk_code_verifier'. - $url = 'https://id.vk.com/authorize?' . http_build_query([ // Формирует URL для перенаправления на страницу авторизации VK ID с параметрами: + $url = 'https://id.vk.ru/authorize?' . http_build_query([ // Формирует URL для перенаправления на страницу авторизации VK ID с параметрами: 'response_type' => 'code', // Указывает, что нужен код авторизации. 'client_id' => env('VK_APP_ID'), // ID приложения VK из переменных окружения. 'redirect_uri' => env('VK_REDIRECT_URI'), // URI для перенаправления после авторизации. @@ -112,7 +112,7 @@ class VkAuthService private function exchangeCodeForTokens(Request $request, $codeVerifier) { - return Http::asForm()->post('https://id.vk.com/oauth2/auth', [ + return Http::asForm()->post('https://id.vk.ru/oauth2/auth', [ 'grant_type' => 'authorization_code', 'code_verifier' => $codeVerifier, 'redirect_uri' => env('VK_REDIRECT_URI_AFTER_AUTH'), @@ -126,7 +126,7 @@ class VkAuthService private function refreshToken($refresh_token, $state, $device_id) { - $response = Http::asForm()->post('https://id.vk.com/oauth2/auth', [ + $response = Http::asForm()->post('https://id.vk.ru/oauth2/auth', [ 'grant_type' => 'refresh_token', 'refresh_token' => $refresh_token, 'client_id' => env('VK_APP_ID'), diff --git a/app/Services/VK/VkService.php b/app/Services/VK/VkService.php index 9baf425..6138c5e 100644 --- a/app/Services/VK/VkService.php +++ b/app/Services/VK/VkService.php @@ -66,7 +66,7 @@ class VkService $album = $this->createAlbum($title, $images); if (isset($album['id'])) { - $albumLink = "https://vk.com/album-{$this->public_id}_{$album['id']}"; + $albumLink = "https://vk.ru/album-{$this->public_id}_{$album['id']}"; $message .= "\n[{$albumLink}|Ссылка на все фотографии]"; } else { Log::error('Не удалось создать альбом'); @@ -168,7 +168,7 @@ class VkService foreach ($videoPaths as $videoPath) { try { // Шаг 1: Получение сервера для загрузки - $saveResponse = Http::get('https://api.vk.com/method/video.save', [ + $saveResponse = Http::get('https://api.vk.ru/method/video.save', [ 'group_id' => $groupId, 'access_token' => $this->vkAuthService->getToken()->access_token, 'v' => '5.131', @@ -209,7 +209,7 @@ class VkService foreach ($imagePaths as $imagePath) { try { - $uploadServerResponse = Http::get('https://api.vk.com/method/photos.getWallUploadServer', [ + $uploadServerResponse = Http::get('https://api.vk.ru/method/photos.getWallUploadServer', [ 'group_id' => $groupId, 'access_token' => $this->vkAuthService->getToken()->access_token, 'v' => '5.131', @@ -234,7 +234,7 @@ class VkService } // Шаг 3: Сохранение фотографии - $saveResponse = Http::get('https://api.vk.com/method/photos.saveWallPhoto', [ + $saveResponse = Http::get('https://api.vk.ru/method/photos.saveWallPhoto', [ 'group_id' => $groupId, 'photo' => $uploadData['photo'], 'server' => $uploadData['server'], diff --git a/app/Services/VK/Wall/VkWallService.php b/app/Services/VK/Wall/VkWallService.php index 17bf5e5..6623fcb 100644 --- a/app/Services/VK/Wall/VkWallService.php +++ b/app/Services/VK/Wall/VkWallService.php @@ -62,7 +62,7 @@ class VkWallService ]; try { - $response = Http::asForm()->post('https://api.vk.com/method/wall.post', $params); + $response = Http::asForm()->post('https://api.vk.ru/method/wall.post', $params); if ($response->successful() && isset($response['response'])) { return [ @@ -122,7 +122,7 @@ class VkWallService ]; try { - $response = Http::asForm()->post('https://api.vk.com/method/wall.delete', $params); + $response = Http::asForm()->post('https://api.vk.ru/method/wall.delete', $params); if ($response->successful() && isset($response['response']) && $response['response'] == 1) { return [ diff --git a/config/cors.php b/config/cors.php index d663276..362ae89 100644 --- a/config/cors.php +++ b/config/cors.php @@ -2,23 +2,19 @@ return [ - /* - |-------------------------------------------------------------------------- - | Cross-Origin Resource Sharing (CORS) Configuration - |-------------------------------------------------------------------------- - | - | Here you may configure your settings for cross-origin resource sharing - | or "CORS". This determines what cross-origin operations may execute - | in web browsers. You are free to adjust these settings as needed. - | - | To learn more: https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS - | - */ + 'paths' => ['api/*'], + + 'allowed_methods' => ['GET', 'POST', 'PUT', 'DELETE'], + + 'allowed_origins' => explode(',', env('CORS_ALLOWED_ORIGINS', 'https://www.ntspi.ru')), + + 'allowed_origins_patterns' => [], + + 'allowed_headers' => ['Content-Type', 'X-Requested-With', 'Authorization'], + + 'exposed_headers' => [], + + 'max_age' => 3600, - 'allowed_origins' => ['http://localhost', 'http://127.0.0.1'], - 'allowed_methods' => ['GET', 'POST'], - 'allowed_headers' => ['Content-Type', 'Authorization'], 'supports_credentials' => true, - - -]; +]; \ No newline at end of file