9702d68d2d
Carry the protocol error code, wrap each machine's gateway so an elevation_required refusal shows one native password dialog, elevates that connection and retries; send the upload token with file uploads; add a Settings sign-in security section with the weak-password warning and sign out everywhere; accept the __Host- session cookie.
49 lines
1.1 KiB
Dart
49 lines
1.1 KiB
Dart
import 'dart:js_interop';
|
|
import 'dart:typed_data';
|
|
|
|
import 'chat_upload.dart';
|
|
|
|
@JS('fetch')
|
|
external JSPromise<_Response> _fetch(JSString input, _Init init);
|
|
|
|
extension type _Init._(JSObject _) implements JSObject {
|
|
external factory _Init({
|
|
JSString method,
|
|
JSAny headers,
|
|
JSAny body,
|
|
JSString credentials,
|
|
});
|
|
}
|
|
|
|
extension type _Response._(JSObject _) implements JSObject {
|
|
external int get status;
|
|
|
|
external JSPromise<JSString> text();
|
|
}
|
|
|
|
/// The browser keeps the login cookie; `same-origin` sends it only to the
|
|
/// page's own server.
|
|
Future<ChatUploadReply> postChatUpload(
|
|
Uri uri, {
|
|
required String name,
|
|
required String mime,
|
|
required Uint8List bytes,
|
|
Map<String, String> headers = const {},
|
|
}) async {
|
|
final response = await _fetch(
|
|
uri.toString().toJS,
|
|
_Init(
|
|
method: 'POST'.toJS,
|
|
headers: {
|
|
chatUploadNameHeader: Uri.encodeComponent(name),
|
|
'Content-Type': mime,
|
|
...headers,
|
|
}.jsify()!,
|
|
body: bytes.toJS,
|
|
credentials: 'same-origin'.toJS,
|
|
),
|
|
).toDart;
|
|
final body = (await response.text().toDart).toDart;
|
|
return (status: response.status, body: body);
|
|
}
|