mirror of
https://github.com/foss42/apidash.git
synced 2025-05-25 02:06:44 +08:00
51 lines
1.3 KiB
Dart
51 lines
1.3 KiB
Dart
import 'package:apidash_core/apidash_core.dart';
|
|
import '../consts.dart';
|
|
|
|
String getRequestTitleFromUrl(String? url) {
|
|
if (url == null || url.trim() == "") {
|
|
return kUntitled;
|
|
}
|
|
if (url.contains("://")) {
|
|
String rem = url.split("://")[1];
|
|
if (rem.trim() == "") {
|
|
return kUntitled;
|
|
}
|
|
return rem;
|
|
}
|
|
return url;
|
|
}
|
|
|
|
(List<ResponseBodyView>, String?) getResponseBodyViewOptions(
|
|
MediaType? mediaType) {
|
|
if (mediaType == null) {
|
|
return (kRawBodyViewOptions, null);
|
|
}
|
|
var type = mediaType.type;
|
|
var subtype = mediaType.subtype;
|
|
if (kResponseBodyViewOptions.containsKey(type)) {
|
|
if (kResponseBodyViewOptions[type]!.containsKey(subtype)) {
|
|
return (
|
|
kResponseBodyViewOptions[type]![subtype]!,
|
|
kCodeHighlighterMap[subtype] ?? subtype
|
|
);
|
|
}
|
|
if (subtype.contains(kSubTypeJson)) {
|
|
subtype = kSubTypeJson;
|
|
}
|
|
if (subtype.contains(kSubTypeXml)) {
|
|
subtype = kSubTypeXml;
|
|
}
|
|
if (kResponseBodyViewOptions[type]!.containsKey(subtype)) {
|
|
return (
|
|
kResponseBodyViewOptions[type]![subtype]!,
|
|
kCodeHighlighterMap[subtype] ?? subtype
|
|
);
|
|
}
|
|
return (
|
|
kResponseBodyViewOptions[type]![kSubTypeDefaultViewOptions]!,
|
|
subtype
|
|
);
|
|
}
|
|
return (kNoBodyViewOptions, null);
|
|
}
|