fix: handle grpc response

Signed-off-by: bggRGjQaUbCoE <githubaccount56556@proton.me>
This commit is contained in:
bggRGjQaUbCoE
2025-02-24 15:54:51 +08:00
parent 307db51aec
commit d9ae1dd97a

View File

@@ -122,8 +122,7 @@ class GrpcRepo {
'x-bili-exps-bin': '', 'x-bili-exps-bin': '',
}; };
static final unprintableRegExp = static final unprintableRegExp = RegExp(r"[^\u4e00-\u9fa5UP]");
RegExp(r"[^\0u0020-\u007e\u4e00-\u9fa5]");
static Uint8List compressProtobuf(Uint8List proto) { static Uint8List compressProtobuf(Uint8List proto) {
proto = gzipEncoder.encodeBytes(proto, level: 0); proto = gzipEncoder.encodeBytes(proto, level: 0);
@@ -156,31 +155,35 @@ class GrpcRepo {
if (response.data is Map) { if (response.data is Map) {
return {'status': false, 'msg': response.data['message']}; return {'status': false, 'msg': response.data['message']};
} }
Uint8List data = response.data;
// if (int.tryParse(response.headers.value('grpc-status') ?? '0') == 0) { if (response.headers.value('Grpc-Status') == '0') {
// try { try {
Uint8List data = response.data;
data = decompressProtobuf(data); data = decompressProtobuf(data);
final grpcResponse = grpcParser(data); final grpcResponse = grpcParser(data);
return { return {
'status': true, 'status': true,
'data': onSuccess == null ? grpcResponse : onSuccess(grpcResponse) 'data': onSuccess == null ? grpcResponse : onSuccess(grpcResponse),
}; };
// } catch (e) {} } catch (e) {
// } return {'status': false, 'msg': e.toString()};
}
// if (data.isNotEmpty) { } else {
// try { try {
// String msg = utf8 String msg = response.headers.value('Grpc-Status-Details-Bin') ?? '';
// .decode(data, allowMalformed: true) if (msg != '') {
// .replaceAll(unprintableRegExp, ''); while (msg.length % 4 != 0) {
// if (msg.isNotEmpty) { msg += '=';
// return {'status': false, 'msg': msg}; }
// } msg = utf8
// } catch (e1) {} .decode(base64Decode(msg), allowMalformed: true)
// } .replaceAll(unprintableRegExp, '');
}
// return {'status': false, 'msg': response.headers.map.toString()}; return {'status': false, 'msg': msg};
} catch (e) {
return {'status': false, 'msg': e.toString()};
}
}
} }
static Future playerOnline({ static Future playerOnline({