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.

This commit is contained in:
F4ilji
2025-09-05 23:42:06 +05:00
parent 2a5df7bc59
commit 525c9edc65
6 changed files with 29 additions and 33 deletions
+4 -4
View File
@@ -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'),
]),
]),
]),
+1 -1
View File
@@ -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 = [
+4 -4
View File
@@ -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'),
+4 -4
View File
@@ -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'],
+2 -2
View File
@@ -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 [
+14 -18
View File
@@ -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,
];
];