mirror of
https://git.selfprivacy.org/kherel/selfprivacy.org.app.git
synced 2025-01-09 01:21:14 +00:00
Merge pull request 'feat(graphql): Implement Accept-Language header for GraphQL API map' (#243) from graphql-locale into master
Reviewed-on: https://git.selfprivacy.org/SelfPrivacy/selfprivacy.org.app/pulls/243 Reviewed-by: Inex Code <inex.code@selfprivacy.org>
This commit is contained in:
commit
ac6a4c192e
|
@ -71,15 +71,14 @@ abstract class GraphQLApiMap {
|
||||||
'https://api.$rootAddress/graphql',
|
'https://api.$rootAddress/graphql',
|
||||||
httpClient: ioClient,
|
httpClient: ioClient,
|
||||||
parser: ResponseLoggingParser(),
|
parser: ResponseLoggingParser(),
|
||||||
|
defaultHeaders: {'Accept-Language': _locale},
|
||||||
);
|
);
|
||||||
|
|
||||||
final String token = _getApiToken();
|
|
||||||
|
|
||||||
final Link graphQLLink = RequestLoggingLink().concat(
|
final Link graphQLLink = RequestLoggingLink().concat(
|
||||||
isWithToken
|
isWithToken
|
||||||
? AuthLink(
|
? AuthLink(
|
||||||
getToken: () async =>
|
getToken: () async =>
|
||||||
customToken == '' ? 'Bearer $token' : customToken,
|
customToken == '' ? 'Bearer $_token' : customToken,
|
||||||
).concat(httpLink)
|
).concat(httpLink)
|
||||||
: httpLink,
|
: httpLink,
|
||||||
);
|
);
|
||||||
|
@ -95,13 +94,16 @@ abstract class GraphQLApiMap {
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<GraphQLClient> getSubscriptionClient() async {
|
Future<GraphQLClient> getSubscriptionClient() async {
|
||||||
final String token = _getApiToken();
|
|
||||||
|
|
||||||
final WebSocketLink webSocketLink = WebSocketLink(
|
final WebSocketLink webSocketLink = WebSocketLink(
|
||||||
'ws://api.$rootAddress/graphql',
|
'ws://api.$rootAddress/graphql',
|
||||||
config: SocketClientConfig(
|
config: SocketClientConfig(
|
||||||
autoReconnect: true,
|
autoReconnect: true,
|
||||||
headers: token.isEmpty ? null : {'Authorization': 'Bearer $token'},
|
headers: _token.isEmpty
|
||||||
|
? null
|
||||||
|
: {
|
||||||
|
'Authorization': 'Bearer $_token',
|
||||||
|
'Accept-Language': _locale,
|
||||||
|
},
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -111,7 +113,9 @@ abstract class GraphQLApiMap {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
String _getApiToken() {
|
String get _locale => getIt.get<ApiConfigModel>().localeCode ?? 'en';
|
||||||
|
|
||||||
|
String get _token {
|
||||||
String token = '';
|
String token = '';
|
||||||
final serverDetails = getIt<ApiConfigModel>().serverDetails;
|
final serverDetails = getIt<ApiConfigModel>().serverDetails;
|
||||||
if (serverDetails != null) {
|
if (serverDetails != null) {
|
||||||
|
|
|
@ -9,6 +9,7 @@ class ApiConfigModel {
|
||||||
final Box _box = Hive.box(BNames.serverInstallationBox);
|
final Box _box = Hive.box(BNames.serverInstallationBox);
|
||||||
|
|
||||||
ServerHostingDetails? get serverDetails => _serverDetails;
|
ServerHostingDetails? get serverDetails => _serverDetails;
|
||||||
|
String? get localeCode => _localeCode;
|
||||||
String? get serverProviderKey => _serverProviderKey;
|
String? get serverProviderKey => _serverProviderKey;
|
||||||
String? get serverLocation => _serverLocation;
|
String? get serverLocation => _serverLocation;
|
||||||
String? get serverType => _serverType;
|
String? get serverType => _serverType;
|
||||||
|
@ -20,6 +21,7 @@ class ApiConfigModel {
|
||||||
ServerDomain? get serverDomain => _serverDomain;
|
ServerDomain? get serverDomain => _serverDomain;
|
||||||
BackblazeBucket? get backblazeBucket => _backblazeBucket;
|
BackblazeBucket? get backblazeBucket => _backblazeBucket;
|
||||||
|
|
||||||
|
String? _localeCode;
|
||||||
String? _serverProviderKey;
|
String? _serverProviderKey;
|
||||||
String? _serverLocation;
|
String? _serverLocation;
|
||||||
String? _dnsProviderKey;
|
String? _dnsProviderKey;
|
||||||
|
@ -31,6 +33,10 @@ class ApiConfigModel {
|
||||||
ServerDomain? _serverDomain;
|
ServerDomain? _serverDomain;
|
||||||
BackblazeBucket? _backblazeBucket;
|
BackblazeBucket? _backblazeBucket;
|
||||||
|
|
||||||
|
Future<void> setLocaleCode(final String value) async {
|
||||||
|
_localeCode = value;
|
||||||
|
}
|
||||||
|
|
||||||
Future<void> storeServerProviderType(final ServerProviderType value) async {
|
Future<void> storeServerProviderType(final ServerProviderType value) async {
|
||||||
await _box.put(BNames.serverProvider, value);
|
await _box.put(BNames.serverProvider, value);
|
||||||
_serverProvider = value;
|
_serverProvider = value;
|
||||||
|
@ -82,6 +88,7 @@ class ApiConfigModel {
|
||||||
}
|
}
|
||||||
|
|
||||||
void clear() {
|
void clear() {
|
||||||
|
_localeCode = null;
|
||||||
_serverProviderKey = null;
|
_serverProviderKey = null;
|
||||||
_dnsProvider = null;
|
_dnsProvider = null;
|
||||||
_serverLocation = null;
|
_serverLocation = null;
|
||||||
|
@ -95,6 +102,7 @@ class ApiConfigModel {
|
||||||
}
|
}
|
||||||
|
|
||||||
void init() {
|
void init() {
|
||||||
|
_localeCode = 'en';
|
||||||
_serverProviderKey = _box.get(BNames.hetznerKey);
|
_serverProviderKey = _box.get(BNames.hetznerKey);
|
||||||
_serverLocation = _box.get(BNames.serverLocation);
|
_serverLocation = _box.get(BNames.serverLocation);
|
||||||
_dnsProviderKey = _box.get(BNames.cloudFlareKey);
|
_dnsProviderKey = _box.get(BNames.cloudFlareKey);
|
||||||
|
|
|
@ -71,8 +71,11 @@ class SelfprivacyApp extends StatelessWidget {
|
||||||
builder: (
|
builder: (
|
||||||
final BuildContext context,
|
final BuildContext context,
|
||||||
final AppSettingsState appSettings,
|
final AppSettingsState appSettings,
|
||||||
) =>
|
) {
|
||||||
MaterialApp.router(
|
getIt.get<ApiConfigModel>().setLocaleCode(
|
||||||
|
context.locale.languageCode,
|
||||||
|
);
|
||||||
|
return MaterialApp.router(
|
||||||
routeInformationParser: _appRouter.defaultRouteParser(),
|
routeInformationParser: _appRouter.defaultRouteParser(),
|
||||||
routerDelegate: _appRouter.delegate(),
|
routerDelegate: _appRouter.delegate(),
|
||||||
scaffoldMessengerKey:
|
scaffoldMessengerKey:
|
||||||
|
@ -98,7 +101,8 @@ class SelfprivacyApp extends StatelessWidget {
|
||||||
(final FlutterErrorDetails errorDetails) => error;
|
(final FlutterErrorDetails errorDetails) => error;
|
||||||
return widget!;
|
return widget!;
|
||||||
},
|
},
|
||||||
),
|
);
|
||||||
|
},
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
Loading…
Reference in a new issue