mirror of
https://github.com/HChaZZY/PiliPlus.git
synced 2025-12-18 08:06:21 +08:00
fix: handle grpc response
Signed-off-by: bggRGjQaUbCoE <githubaccount56556@proton.me>
This commit is contained in:
@@ -122,8 +122,7 @@ class GrpcRepo {
|
|||||||
'x-bili-exps-bin': '',
|
'x-bili-exps-bin': '',
|
||||||
};
|
};
|
||||||
|
|
||||||
static final unprintableRegExp =
|
static final unprintableRegExp = RegExp(r"[^\u4e00-\u9fa5,。;!?UP]");
|
||||||
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 {
|
||||||
data = decompressProtobuf(data);
|
Uint8List data = response.data;
|
||||||
final grpcResponse = grpcParser(data);
|
data = decompressProtobuf(data);
|
||||||
return {
|
final grpcResponse = grpcParser(data);
|
||||||
'status': true,
|
return {
|
||||||
'data': onSuccess == null ? grpcResponse : onSuccess(grpcResponse)
|
'status': true,
|
||||||
};
|
'data': onSuccess == null ? grpcResponse : onSuccess(grpcResponse),
|
||||||
// } catch (e) {}
|
};
|
||||||
// }
|
} catch (e) {
|
||||||
|
return {'status': false, 'msg': e.toString()};
|
||||||
// if (data.isNotEmpty) {
|
}
|
||||||
// try {
|
} else {
|
||||||
// String msg = utf8
|
try {
|
||||||
// .decode(data, allowMalformed: true)
|
String msg = response.headers.value('Grpc-Status-Details-Bin') ?? '';
|
||||||
// .replaceAll(unprintableRegExp, '');
|
if (msg != '') {
|
||||||
// if (msg.isNotEmpty) {
|
while (msg.length % 4 != 0) {
|
||||||
// return {'status': false, 'msg': msg};
|
msg += '=';
|
||||||
// }
|
}
|
||||||
// } catch (e1) {}
|
msg = utf8
|
||||||
// }
|
.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({
|
||||||
|
|||||||
Reference in New Issue
Block a user