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.
34 lines
1.1 KiB
Dart
34 lines
1.1 KiB
Dart
import 'dart:convert';
|
|
import 'dart:io';
|
|
import 'dart:typed_data';
|
|
|
|
import '../../../../core/session/server_session.dart';
|
|
import 'chat_upload.dart';
|
|
|
|
Future<ChatUploadReply> postChatUpload(
|
|
Uri uri, {
|
|
required String name,
|
|
required String mime,
|
|
required Uint8List bytes,
|
|
Map<String, String> headers = const {},
|
|
}) async {
|
|
final client = HttpClient()..connectionTimeout = const Duration(seconds: 15);
|
|
try {
|
|
final request = await client.postUrl(uri);
|
|
request.followRedirects = false;
|
|
// A phone behind the web login carries its kept session.
|
|
ServerSession.headersFor(uri).forEach(request.headers.set);
|
|
request.headers
|
|
..set(chatUploadNameHeader, Uri.encodeComponent(name))
|
|
..set(HttpHeaders.contentTypeHeader, mime)
|
|
..contentLength = bytes.length;
|
|
headers.forEach(request.headers.set);
|
|
request.add(bytes);
|
|
final response = await request.close();
|
|
final body = await response.transform(utf8.decoder).join();
|
|
return (status: response.statusCode, body: body);
|
|
} finally {
|
|
client.close(force: true);
|
|
}
|
|
}
|