Подключен к серверу
This commit is contained in:
parent
2d28fcc1fe
commit
7ea3d8dc28
|
|
@ -1,3 +1,4 @@
|
||||||
class AppConstants {
|
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';
|
||||||
}
|
}
|
||||||
|
|
@ -29,7 +29,7 @@ class SocketService {
|
||||||
}
|
}
|
||||||
|
|
||||||
// В FastAPI эндпоинт обычно ожидает токен в URL или подзаголовке
|
// В 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);
|
_channel = WebSocketChannel.connect(uri);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,7 @@ class ContactRepository {
|
||||||
}
|
}
|
||||||
|
|
||||||
final response = await _client.get(
|
final response = await _client.get(
|
||||||
Uri.http(AppConstants.baseUrl, 'users/chats'),
|
Uri.parse('${AppConstants.baseUrl}/users/chats'),
|
||||||
headers: {
|
headers: {
|
||||||
'Authorization': 'Bearer $token',
|
'Authorization': 'Bearer $token',
|
||||||
'Content-Type': 'application/json',
|
'Content-Type': 'application/json',
|
||||||
|
|
@ -37,7 +37,7 @@ class ContactRepository {
|
||||||
}
|
}
|
||||||
|
|
||||||
final response = await _client.get(
|
final response = await _client.get(
|
||||||
Uri.http(AppConstants.baseUrl, 'users/all'),
|
Uri.parse('${AppConstants.baseUrl}/users/all'),
|
||||||
headers: {
|
headers: {
|
||||||
'Authorization': 'Bearer $token',
|
'Authorization': 'Bearer $token',
|
||||||
'Content-Type': 'application/json',
|
'Content-Type': 'application/json',
|
||||||
|
|
@ -55,7 +55,7 @@ class ContactRepository {
|
||||||
Future<Contact> fetchContactById(int userId) async {
|
Future<Contact> fetchContactById(int userId) async {
|
||||||
final token = await _apiService.getAccessToken();
|
final token = await _apiService.getAccessToken();
|
||||||
final response = await _client.get(
|
final response = await _client.get(
|
||||||
Uri.http(AppConstants.baseUrl, 'users/$userId'),
|
Uri.parse('${AppConstants.baseUrl}/users/$userId'),
|
||||||
headers: {
|
headers: {
|
||||||
'Authorization': 'Bearer $token',
|
'Authorization': 'Bearer $token',
|
||||||
'Content-Type': 'application/json',
|
'Content-Type': 'application/json',
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,7 @@ class ApiService extends ChangeNotifier {
|
||||||
try {
|
try {
|
||||||
final refreshToken = await _storage.read(key: 'refresh_token');
|
final refreshToken = await _storage.read(key: 'refresh_token');
|
||||||
final response = await _client.post(
|
final response = await _client.post(
|
||||||
Uri.http(AppConstants.baseUrl, 'auth/refresh'),
|
Uri.parse('${AppConstants.baseUrl}/auth/refresh'),
|
||||||
body: jsonEncode({'refresh_token': refreshToken}),
|
body: jsonEncode({'refresh_token': refreshToken}),
|
||||||
headers: {'Content-Type': 'application/json'},
|
headers: {'Content-Type': 'application/json'},
|
||||||
);
|
);
|
||||||
|
|
@ -70,7 +70,7 @@ class ApiService extends ChangeNotifier {
|
||||||
try {
|
try {
|
||||||
final token = await getAccessToken();
|
final token = await getAccessToken();
|
||||||
final response = await _client.post(
|
final response = await _client.post(
|
||||||
Uri.http(AppConstants.baseUrl, 'auth/update-fcm', {'token': fcmtoken}),
|
Uri.parse('${AppConstants.baseUrl}/auth/update-fcm?token=$fcmtoken'),
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/json',
|
'Content-Type': 'application/json',
|
||||||
'Authorization': 'Bearer $token',
|
'Authorization': 'Bearer $token',
|
||||||
|
|
@ -96,7 +96,7 @@ class ApiService extends ChangeNotifier {
|
||||||
try {
|
try {
|
||||||
final token = await getAccessToken();
|
final token = await getAccessToken();
|
||||||
final response = await _client.post(
|
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}),
|
body: jsonEncode({'public_key': publicKey}),
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/json',
|
'Content-Type': 'application/json',
|
||||||
|
|
@ -120,7 +120,7 @@ class ApiService extends ChangeNotifier {
|
||||||
Future<Map<String, dynamic>> getMe() async {
|
Future<Map<String, dynamic>> getMe() async {
|
||||||
final token = await getAccessToken();
|
final token = await getAccessToken();
|
||||||
final response = await _client.get(
|
final response = await _client.get(
|
||||||
Uri.http(AppConstants.baseUrl, 'users/me'),
|
Uri.parse('${AppConstants.baseUrl}/users/me'),
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/json',
|
'Content-Type': 'application/json',
|
||||||
'Authorization': 'Bearer $token',
|
'Authorization': 'Bearer $token',
|
||||||
|
|
@ -136,7 +136,7 @@ class ApiService extends ChangeNotifier {
|
||||||
Future<bool> updateEncryptedPrivateKey(String encryptedPrivateKey) async {
|
Future<bool> updateEncryptedPrivateKey(String encryptedPrivateKey) async {
|
||||||
final token = await getAccessToken();
|
final token = await getAccessToken();
|
||||||
final response = await _client.put(
|
final response = await _client.put(
|
||||||
Uri.http(AppConstants.baseUrl, 'users/me/encryption-key'),
|
Uri.parse('${AppConstants.baseUrl}/users/me/encryption-key'),
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/json',
|
'Content-Type': 'application/json',
|
||||||
'Authorization': 'Bearer $token',
|
'Authorization': 'Bearer $token',
|
||||||
|
|
@ -150,7 +150,7 @@ class ApiService extends ChangeNotifier {
|
||||||
Future<bool> changePassword(String currentPassword, String newPassword) async {
|
Future<bool> changePassword(String currentPassword, String newPassword) async {
|
||||||
final token = await getAccessToken();
|
final token = await getAccessToken();
|
||||||
final response = await _client.put(
|
final response = await _client.put(
|
||||||
Uri.http(AppConstants.baseUrl, 'users/me/password'),
|
Uri.parse('${AppConstants.baseUrl}/users/me/password'),
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/json',
|
'Content-Type': 'application/json',
|
||||||
'Authorization': 'Bearer $token',
|
'Authorization': 'Bearer $token',
|
||||||
|
|
@ -166,11 +166,8 @@ class ApiService extends ChangeNotifier {
|
||||||
|
|
||||||
Future<List<dynamic>> getChatHistory(int contactId) async {
|
Future<List<dynamic>> getChatHistory(int contactId) async {
|
||||||
final token = await getAccessToken();
|
final token = await getAccessToken();
|
||||||
final response = await http.get(
|
final response = await _client.get(
|
||||||
Uri.http(
|
Uri.parse('${AppConstants.baseUrl}/messages/history/${contactId.toString()}'),
|
||||||
AppConstants.baseUrl,
|
|
||||||
'messages/history/${contactId.toString()}',
|
|
||||||
),
|
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/json',
|
'Content-Type': 'application/json',
|
||||||
"Authorization": "Bearer $token",
|
"Authorization": "Bearer $token",
|
||||||
|
|
@ -189,7 +186,7 @@ class ApiService extends ChangeNotifier {
|
||||||
}) async {
|
}) async {
|
||||||
final token = await getAccessToken();
|
final token = await getAccessToken();
|
||||||
final response = await _client.put(
|
final response = await _client.put(
|
||||||
Uri.http(AppConstants.baseUrl, 'users/me'),
|
Uri.parse('${AppConstants.baseUrl}/users/me'),
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/json',
|
'Content-Type': 'application/json',
|
||||||
'Authorization': 'Bearer $token',
|
'Authorization': 'Bearer $token',
|
||||||
|
|
@ -214,7 +211,7 @@ class ApiService extends ChangeNotifier {
|
||||||
Future<Map<String, dynamic>> getUserById(int userId) async {
|
Future<Map<String, dynamic>> getUserById(int userId) async {
|
||||||
final token = await getAccessToken();
|
final token = await getAccessToken();
|
||||||
final response = await _client.get(
|
final response = await _client.get(
|
||||||
Uri.http(AppConstants.baseUrl, 'users/$userId'),
|
Uri.parse('${AppConstants.baseUrl}/users/$userId'),
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/json',
|
'Content-Type': 'application/json',
|
||||||
'Authorization': 'Bearer $token',
|
'Authorization': 'Bearer $token',
|
||||||
|
|
@ -236,7 +233,7 @@ class ApiService extends ChangeNotifier {
|
||||||
}) async {
|
}) async {
|
||||||
final token = await getAccessToken();
|
final token = await getAccessToken();
|
||||||
final response = await _client.put(
|
final response = await _client.put(
|
||||||
Uri.http(AppConstants.baseUrl, 'users/me/privacy'),
|
Uri.parse('${AppConstants.baseUrl}/users/me/privacy'),
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/json',
|
'Content-Type': 'application/json',
|
||||||
'Authorization': 'Bearer $token',
|
'Authorization': 'Bearer $token',
|
||||||
|
|
@ -256,7 +253,7 @@ class ApiService extends ChangeNotifier {
|
||||||
Future<Map<String, dynamic>> getPrivacySettings() async {
|
Future<Map<String, dynamic>> getPrivacySettings() async {
|
||||||
final token = await getAccessToken();
|
final token = await getAccessToken();
|
||||||
final response = await _client.get(
|
final response = await _client.get(
|
||||||
Uri.http(AppConstants.baseUrl, 'users/me/privacy'),
|
Uri.parse('${AppConstants.baseUrl}/users/me/privacy'),
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/json',
|
'Content-Type': 'application/json',
|
||||||
'Authorization': 'Bearer $token',
|
'Authorization': 'Bearer $token',
|
||||||
|
|
|
||||||
|
|
@ -87,7 +87,7 @@ class AuthProvider extends ChangeNotifier {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
final response = await _client.post(
|
final response = await _client.post(
|
||||||
Uri.http(AppConstants.baseUrl, 'auth/login'),
|
Uri.parse('${AppConstants.baseUrl}/auth/login'),
|
||||||
body: {'username': username, 'password': password},
|
body: {'username': username, 'password': password},
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
@ -161,7 +161,7 @@ class AuthProvider extends ChangeNotifier {
|
||||||
try {
|
try {
|
||||||
final response = await _client
|
final response = await _client
|
||||||
.get(
|
.get(
|
||||||
Uri.http(AppConstants.baseUrl, 'users/me'),
|
Uri.parse('${AppConstants.baseUrl}/users/me'),
|
||||||
headers: {'Authorization': 'Bearer $token'},
|
headers: {'Authorization': 'Bearer $token'},
|
||||||
)
|
)
|
||||||
.timeout(const Duration(seconds: 5));
|
.timeout(const Duration(seconds: 5));
|
||||||
|
|
@ -200,7 +200,7 @@ class AuthProvider extends ChangeNotifier {
|
||||||
final keys = await _cryptoService.initAccountSecurity(masterPassword);
|
final keys = await _cryptoService.initAccountSecurity(masterPassword);
|
||||||
|
|
||||||
final response = await _client.post(
|
final response = await _client.post(
|
||||||
Uri.http(AppConstants.baseUrl, 'auth/setup-account'),
|
Uri.parse('${AppConstants.baseUrl}/auth/setup-account'),
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/json',
|
'Content-Type': 'application/json',
|
||||||
'Authorization': 'Bearer $token',
|
'Authorization': 'Bearer $token',
|
||||||
|
|
@ -234,7 +234,7 @@ class AuthProvider extends ChangeNotifier {
|
||||||
try {
|
try {
|
||||||
final token = await _apiService.getAccessToken();
|
final token = await _apiService.getAccessToken();
|
||||||
final response = await _client.get(
|
final response = await _client.get(
|
||||||
Uri.http(AppConstants.baseUrl, 'users/me'),
|
Uri.parse('${AppConstants.baseUrl}/users/me'),
|
||||||
headers: {'Authorization': 'Bearer $token'},
|
headers: {'Authorization': 'Bearer $token'},
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -17,3 +17,7 @@ app.add_middleware(
|
||||||
allow_methods=["*"],
|
allow_methods=["*"],
|
||||||
allow_headers=["*"],
|
allow_headers=["*"],
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
import uvicorn
|
||||||
|
uvicorn.run(app, host="0.0.0.0", port=8587)
|
||||||
Loading…
Reference in New Issue