feat(chat): files upload over HTTP before the prompt, up to 100 MiB each

This commit is contained in:
2026-10-23 21:25:41 +01:00
parent 39a68a00b3
commit e507f554c3
17 changed files with 634 additions and 74 deletions
@@ -0,0 +1,46 @@
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,
}) async {
final response = await _fetch(
uri.toString().toJS,
_Init(
method: 'POST'.toJS,
headers: {
chatUploadNameHeader: Uri.encodeComponent(name),
'Content-Type': mime,
}.jsify()!,
body: bytes.toJS,
credentials: 'same-origin'.toJS,
),
).toDart;
final body = (await response.text().toDart).toDart;
return (status: response.status, body: body);
}