Подключен к серверу

This commit is contained in:
Artur 2026-04-26 21:45:12 +05:00
parent 2d28fcc1fe
commit 7ea3d8dc28
6 changed files with 26 additions and 24 deletions

View File

@ -1,3 +1,4 @@
class AppConstants {
static const baseUrl = '192.168.0.180:8000';
//static const baseUrl = '192.168.0.180:8000';
static const baseUrl = 'https://api.chepuhagram.ru';
}

View File

@ -29,7 +29,7 @@ class SocketService {
}
// В FastAPI эндпоинт обычно ожидает токен в URL или подзаголовке
final uri = Uri.parse("ws://${AppConstants.baseUrl}/ws?token=$token");
final uri = Uri.parse("ws://${AppConstants.baseUrl.split('//')[1]}/ws?token=$token");
_channel = WebSocketChannel.connect(uri);

View File

@ -15,7 +15,7 @@ class ContactRepository {
}
final response = await _client.get(
Uri.http(AppConstants.baseUrl, 'users/chats'),
Uri.parse('${AppConstants.baseUrl}/users/chats'),
headers: {
'Authorization': 'Bearer $token',
'Content-Type': 'application/json',
@ -37,7 +37,7 @@ class ContactRepository {
}
final response = await _client.get(
Uri.http(AppConstants.baseUrl, 'users/all'),
Uri.parse('${AppConstants.baseUrl}/users/all'),
headers: {
'Authorization': 'Bearer $token',
'Content-Type': 'application/json',
@ -55,7 +55,7 @@ class ContactRepository {
Future<Contact> fetchContactById(int userId) async {
final token = await _apiService.getAccessToken();
final response = await _client.get(
Uri.http(AppConstants.baseUrl, 'users/$userId'),
Uri.parse('${AppConstants.baseUrl}/users/$userId'),
headers: {
'Authorization': 'Bearer $token',
'Content-Type': 'application/json',

View File

@ -15,7 +15,7 @@ class ApiService extends ChangeNotifier {
try {
final refreshToken = await _storage.read(key: 'refresh_token');
final response = await _client.post(
Uri.http(AppConstants.baseUrl, 'auth/refresh'),
Uri.parse('${AppConstants.baseUrl}/auth/refresh'),
body: jsonEncode({'refresh_token': refreshToken}),
headers: {'Content-Type': 'application/json'},
);
@ -70,7 +70,7 @@ class ApiService extends ChangeNotifier {
try {
final token = await getAccessToken();
final response = await _client.post(
Uri.http(AppConstants.baseUrl, 'auth/update-fcm', {'token': fcmtoken}),
Uri.parse('${AppConstants.baseUrl}/auth/update-fcm?token=$fcmtoken'),
headers: {
'Content-Type': 'application/json',
'Authorization': 'Bearer $token',
@ -96,7 +96,7 @@ class ApiService extends ChangeNotifier {
try {
final token = await getAccessToken();
final response = await _client.post(
Uri.http(AppConstants.baseUrl, 'auth/set-public-key'),
Uri.parse('${AppConstants.baseUrl}/auth/set-public-key'),
body: jsonEncode({'public_key': publicKey}),
headers: {
'Content-Type': 'application/json',
@ -120,7 +120,7 @@ class ApiService extends ChangeNotifier {
Future<Map<String, dynamic>> getMe() async {
final token = await getAccessToken();
final response = await _client.get(
Uri.http(AppConstants.baseUrl, 'users/me'),
Uri.parse('${AppConstants.baseUrl}/users/me'),
headers: {
'Content-Type': 'application/json',
'Authorization': 'Bearer $token',
@ -136,7 +136,7 @@ class ApiService extends ChangeNotifier {
Future<bool> updateEncryptedPrivateKey(String encryptedPrivateKey) async {
final token = await getAccessToken();
final response = await _client.put(
Uri.http(AppConstants.baseUrl, 'users/me/encryption-key'),
Uri.parse('${AppConstants.baseUrl}/users/me/encryption-key'),
headers: {
'Content-Type': 'application/json',
'Authorization': 'Bearer $token',
@ -150,7 +150,7 @@ class ApiService extends ChangeNotifier {
Future<bool> changePassword(String currentPassword, String newPassword) async {
final token = await getAccessToken();
final response = await _client.put(
Uri.http(AppConstants.baseUrl, 'users/me/password'),
Uri.parse('${AppConstants.baseUrl}/users/me/password'),
headers: {
'Content-Type': 'application/json',
'Authorization': 'Bearer $token',
@ -166,11 +166,8 @@ class ApiService extends ChangeNotifier {
Future<List<dynamic>> getChatHistory(int contactId) async {
final token = await getAccessToken();
final response = await http.get(
Uri.http(
AppConstants.baseUrl,
'messages/history/${contactId.toString()}',
),
final response = await _client.get(
Uri.parse('${AppConstants.baseUrl}/messages/history/${contactId.toString()}'),
headers: {
'Content-Type': 'application/json',
"Authorization": "Bearer $token",
@ -189,7 +186,7 @@ class ApiService extends ChangeNotifier {
}) async {
final token = await getAccessToken();
final response = await _client.put(
Uri.http(AppConstants.baseUrl, 'users/me'),
Uri.parse('${AppConstants.baseUrl}/users/me'),
headers: {
'Content-Type': 'application/json',
'Authorization': 'Bearer $token',
@ -214,7 +211,7 @@ class ApiService extends ChangeNotifier {
Future<Map<String, dynamic>> getUserById(int userId) async {
final token = await getAccessToken();
final response = await _client.get(
Uri.http(AppConstants.baseUrl, 'users/$userId'),
Uri.parse('${AppConstants.baseUrl}/users/$userId'),
headers: {
'Content-Type': 'application/json',
'Authorization': 'Bearer $token',
@ -236,7 +233,7 @@ class ApiService extends ChangeNotifier {
}) async {
final token = await getAccessToken();
final response = await _client.put(
Uri.http(AppConstants.baseUrl, 'users/me/privacy'),
Uri.parse('${AppConstants.baseUrl}/users/me/privacy'),
headers: {
'Content-Type': 'application/json',
'Authorization': 'Bearer $token',
@ -256,7 +253,7 @@ class ApiService extends ChangeNotifier {
Future<Map<String, dynamic>> getPrivacySettings() async {
final token = await getAccessToken();
final response = await _client.get(
Uri.http(AppConstants.baseUrl, 'users/me/privacy'),
Uri.parse('${AppConstants.baseUrl}/users/me/privacy'),
headers: {
'Content-Type': 'application/json',
'Authorization': 'Bearer $token',

View File

@ -87,7 +87,7 @@ class AuthProvider extends ChangeNotifier {
try {
final response = await _client.post(
Uri.http(AppConstants.baseUrl, 'auth/login'),
Uri.parse('${AppConstants.baseUrl}/auth/login'),
body: {'username': username, 'password': password},
);
@ -161,7 +161,7 @@ class AuthProvider extends ChangeNotifier {
try {
final response = await _client
.get(
Uri.http(AppConstants.baseUrl, 'users/me'),
Uri.parse('${AppConstants.baseUrl}/users/me'),
headers: {'Authorization': 'Bearer $token'},
)
.timeout(const Duration(seconds: 5));
@ -200,7 +200,7 @@ class AuthProvider extends ChangeNotifier {
final keys = await _cryptoService.initAccountSecurity(masterPassword);
final response = await _client.post(
Uri.http(AppConstants.baseUrl, 'auth/setup-account'),
Uri.parse('${AppConstants.baseUrl}/auth/setup-account'),
headers: {
'Content-Type': 'application/json',
'Authorization': 'Bearer $token',
@ -234,7 +234,7 @@ class AuthProvider extends ChangeNotifier {
try {
final token = await _apiService.getAccessToken();
final response = await _client.get(
Uri.http(AppConstants.baseUrl, 'users/me'),
Uri.parse('${AppConstants.baseUrl}/users/me'),
headers: {'Authorization': 'Bearer $token'},
);

View File

@ -17,3 +17,7 @@ app.add_middleware(
allow_methods=["*"],
allow_headers=["*"],
)
if __name__ == "__main__":
import uvicorn
uvicorn.run(app, host="0.0.0.0", port=8587)