mirror of
https://github.com/immich-app/immich.git
synced 2025-07-19 22:44:24 +02:00
fix: mobile user agent
This commit is contained in:
parent
bc8e08f5e8
commit
c270fa8a38
5 changed files with 34 additions and 3 deletions
mobile
|
@ -1,3 +1,3 @@
|
||||||
{
|
{
|
||||||
"flutter": "3.29.3"
|
"flutter": "3.29.3"
|
||||||
}
|
}
|
2
mobile/.vscode/settings.json
vendored
2
mobile/.vscode/settings.json
vendored
|
@ -1,5 +1,5 @@
|
||||||
{
|
{
|
||||||
"dart.flutterSdkPath": ".fvm/versions/3.24.3",
|
"dart.flutterSdkPath": ".fvm/versions/3.29.3",
|
||||||
"search.exclude": {
|
"search.exclude": {
|
||||||
"**/.fvm": true
|
"**/.fvm": true
|
||||||
},
|
},
|
||||||
|
|
|
@ -10,6 +10,7 @@ import 'package:immich_mobile/entities/store.entity.dart';
|
||||||
import 'package:immich_mobile/utils/url_helper.dart';
|
import 'package:immich_mobile/utils/url_helper.dart';
|
||||||
import 'package:logging/logging.dart';
|
import 'package:logging/logging.dart';
|
||||||
import 'package:openapi/api.dart';
|
import 'package:openapi/api.dart';
|
||||||
|
import 'package:immich_mobile/utils/user_agent.dart';
|
||||||
|
|
||||||
class ApiService implements Authentication {
|
class ApiService implements Authentication {
|
||||||
late ApiClient _apiClient;
|
late ApiClient _apiClient;
|
||||||
|
@ -48,6 +49,7 @@ class ApiService implements Authentication {
|
||||||
|
|
||||||
setEndpoint(String endpoint) {
|
setEndpoint(String endpoint) {
|
||||||
_apiClient = ApiClient(basePath: endpoint, authentication: this);
|
_apiClient = ApiClient(basePath: endpoint, authentication: this);
|
||||||
|
_setUserAgentHeader();
|
||||||
if (_accessToken != null) {
|
if (_accessToken != null) {
|
||||||
setAccessToken(_accessToken!);
|
setAccessToken(_accessToken!);
|
||||||
}
|
}
|
||||||
|
@ -72,6 +74,11 @@ class ApiService implements Authentication {
|
||||||
memoriesApi = MemoriesApi(_apiClient);
|
memoriesApi = MemoriesApi(_apiClient);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Future<void> _setUserAgentHeader() async {
|
||||||
|
final userAgent = await getUserAgentString();
|
||||||
|
_apiClient.addDefaultHeader('User-Agent', userAgent);
|
||||||
|
}
|
||||||
|
|
||||||
Future<String> resolveAndSetEndpoint(String serverUrl) async {
|
Future<String> resolveAndSetEndpoint(String serverUrl) async {
|
||||||
final endpoint = await resolveEndpoint(serverUrl);
|
final endpoint = await resolveEndpoint(serverUrl);
|
||||||
setEndpoint(endpoint);
|
setEndpoint(endpoint);
|
||||||
|
|
|
@ -2,13 +2,22 @@ import 'package:immich_mobile/mixins/error_logger.mixin.dart';
|
||||||
import 'package:immich_mobile/models/map/map_marker.model.dart';
|
import 'package:immich_mobile/models/map/map_marker.model.dart';
|
||||||
import 'package:immich_mobile/services/api.service.dart';
|
import 'package:immich_mobile/services/api.service.dart';
|
||||||
import 'package:logging/logging.dart';
|
import 'package:logging/logging.dart';
|
||||||
|
import 'package:maplibre_gl/maplibre_gl.dart';
|
||||||
|
import 'package:immich_mobile/utils/user_agent.dart';
|
||||||
|
|
||||||
class MapSerivce with ErrorLoggerMixin {
|
class MapSerivce with ErrorLoggerMixin {
|
||||||
final ApiService _apiService;
|
final ApiService _apiService;
|
||||||
@override
|
@override
|
||||||
final logger = Logger("MapService");
|
final logger = Logger("MapService");
|
||||||
|
|
||||||
MapSerivce(this._apiService);
|
MapSerivce(this._apiService) {
|
||||||
|
_setMapUserAgentHeader();
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> _setMapUserAgentHeader() async {
|
||||||
|
final userAgent = await getUserAgentString();
|
||||||
|
setHttpHeaders({'User-Agent': userAgent});
|
||||||
|
}
|
||||||
|
|
||||||
Future<Iterable<MapMarker>> getMapMarkers({
|
Future<Iterable<MapMarker>> getMapMarkers({
|
||||||
bool? isFavorite,
|
bool? isFavorite,
|
||||||
|
|
15
mobile/lib/utils/user_agent.dart
Normal file
15
mobile/lib/utils/user_agent.dart
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
import 'dart:io' show Platform;
|
||||||
|
import 'package:package_info_plus/package_info_plus.dart';
|
||||||
|
|
||||||
|
Future<String> getUserAgentString() async {
|
||||||
|
final packageInfo = await PackageInfo.fromPlatform();
|
||||||
|
String platform;
|
||||||
|
if (Platform.isAndroid) {
|
||||||
|
platform = 'Android';
|
||||||
|
} else if (Platform.isIOS) {
|
||||||
|
platform = 'iOS';
|
||||||
|
} else {
|
||||||
|
platform = 'Unknown';
|
||||||
|
}
|
||||||
|
return 'Immich_${platform}_${packageInfo.version}';
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue