Files
pipelines/app/lib/features/chat/data/upload/chat_upload_web.dart
T
alan 9702d68d2d Ask for the password once and retry when a machine requires elevation
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.
2026-11-10 01:21:28 +00:00

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);
}