ente/mobile/lib/gateways/cast_gw.dart
Manav Rathi 7be9963303
[API] Remove trailing slash from inconsistent cast endpoints
None of our other endpoints have a trailing slash. Remove this inconsistency,
otherwise clients who'd not provide a trailing slash would get an unnecessary
redirect.

Note that the CORS-aware clients (web, desktop) do not automatically follow the
redirect because the ACAO is missing on the 307, so we need keep the old
endpoints around temporarily.

Tested: with web and museum running locally
2024-11-26 09:53:44 +05:30

59 lines
1.2 KiB
Dart

import "package:dio/dio.dart";
class CastGateway {
final Dio _enteDio;
CastGateway(this._enteDio);
Future<String?> getPublicKey(String deviceCode) async {
try {
final response = await _enteDio.get(
"/cast/device-info/$deviceCode",
);
return response.data["publicKey"];
} catch (e) {
if (e is DioError && e.response != null) {
if (e.response!.statusCode == 404) {
return null;
} else if (e.response!.statusCode == 403) {
throw CastIPMismatchException();
} else {
rethrow;
}
}
rethrow;
}
}
Future<void> publishCastPayload(
String code,
String castPayload,
int collectionID,
String castToken,
) {
return _enteDio.post(
"/cast/cast-data",
data: {
"deviceCode": code,
"encPayload": castPayload,
"collectionID": collectionID,
"castToken": castToken,
},
);
}
Future<void> revokeAllTokens() async {
try {
await _enteDio.delete(
"/cast/revoke-all-tokens",
);
} catch (e) {
// swallow error
}
}
}
class CastIPMismatchException implements Exception {
CastIPMismatchException();
}