stuff
Some checks are pending
Backend CI / test (push) Waiting to run
Backend CI / build (push) Blocked by required conditions
Deploy Mnemo Cards / Deploy Backend (push) Waiting to run
Deploy Mnemo Cards / Deploy Web App (push) Blocked by required conditions
Deploy Mnemo Cards / Final Verification (push) Blocked by required conditions

This commit is contained in:
Dmitry 2025-12-19 05:22:29 +03:00
parent a882b9c7e6
commit c14a7ba87e
2 changed files with 35 additions and 49 deletions

View file

@ -23,15 +23,18 @@ class MediaApiV2 {
Router get router => _$MediaApiV2Router(this);
Response _ok(Object? object, {Map<String, String> headers = const {}}) =>
Response(
200,
body: object == null ? null : jsonEncode(object),
headers: {
'Content-Type': 'application/json',
...headers,
},
);
Response _ok(Object? object, {Map<String, String> headers = const {}}) {
final body = object == null ? null : jsonEncode(object);
final responseHeaders = <String, String>{
'Content-Type': 'application/json; charset=utf-8',
if (body != null) 'Content-Length': body.length.toString(),
...headers,
};
return Response.ok(
body,
headers: responseHeaders,
);
}
Response _badRequest(String message) => Response.badRequest(
body: jsonEncode({'error': 'Bad Request', 'message': message}),
@ -74,29 +77,30 @@ class MediaApiV2 {
await for (final part in multipart.parts) {
// Check if this is the 'file' field
final contentDisposition = part.headers['content-disposition'] ?? '';
if (!contentDisposition.contains('name="file"')) {
continue;
if (contentDisposition.contains('name="file"')) {
// Read file bytes
final chunks = <List<int>>[];
await for (final chunk in part) {
chunks.add(chunk);
}
fileBytes = Uint8List.fromList(
chunks.expand((chunk) => chunk).toList(),
);
// Get content type from part headers
fileContentType = part.headers['content-type'] ??
'application/octet-stream';
// Extract filename from content-disposition header
final filenameMatch =
RegExp(r'filename="?([^"]+)"?').firstMatch(contentDisposition);
filename = filenameMatch?.group(1);
} else {
// Read and discard other parts to ensure full request is consumed
await for (final _ in part) {
// Discard chunks from other parts
}
}
// Read file bytes
final chunks = <List<int>>[];
await for (final chunk in part) {
chunks.add(chunk);
}
fileBytes = Uint8List.fromList(
chunks.expand((chunk) => chunk).toList(),
);
// Get content type from part headers
fileContentType = part.headers['content-type'] ??
'application/octet-stream';
// Extract filename from content-disposition header
final filenameMatch =
RegExp(r'filename="?([^"]+)"?').firstMatch(contentDisposition);
filename = filenameMatch?.group(1);
break; // Found file, no need to continue
}
if (fileBytes == null) {

View file

@ -224,22 +224,4 @@ class MockPackManager extends _i1.Mock implements _i8.PackManager {
),
)
as _i5.Future<_i3.CardPackDto>);
@override
_i5.Future<List<String>> getPackPreviewImages(String? packId) =>
(super.noSuchMethod(
Invocation.method(#getPackPreviewImages, [packId]),
returnValue: _i5.Future<List<String>>.value(<String>[]),
)
as _i5.Future<List<String>>);
@override
_i5.Future<Map<String, _i6.Uint8List>> getPackImages(String? packId) =>
(super.noSuchMethod(
Invocation.method(#getPackImages, [packId]),
returnValue: _i5.Future<Map<String, _i6.Uint8List>>.value(
<String, _i6.Uint8List>{},
),
)
as _i5.Future<Map<String, _i6.Uint8List>>);
}