You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
67 lines
1.6 KiB
Dart
67 lines
1.6 KiB
Dart
import 'package:intl/intl.dart';
|
|
import 'package:isekai_wiki/api/mw/mw_api.dart';
|
|
import 'package:isekai_wiki/api/response/parse.dart';
|
|
import 'package:isekai_wiki/global.dart';
|
|
|
|
class MWApiParse {
|
|
static Future<MWResponse<MWParseInfo>> parse({
|
|
String? title,
|
|
int? pageId,
|
|
List<String>? prop,
|
|
String? useSkin,
|
|
String? section,
|
|
bool disableEditSection = true,
|
|
bool disableTOC = true,
|
|
bool mobileMode = true,
|
|
}) async {
|
|
prop ??= [
|
|
"text",
|
|
"langlinks",
|
|
"categories",
|
|
"links",
|
|
"templates",
|
|
"images",
|
|
"externallinks",
|
|
"sections",
|
|
"revid",
|
|
"displaytitle",
|
|
"iwlinks",
|
|
"properties",
|
|
"parsewarnings",
|
|
"modules",
|
|
"jsconfigvars",
|
|
];
|
|
|
|
useSkin ??= Global.siteConfig.renderTheme;
|
|
|
|
Map<String, dynamic> query = {
|
|
"prop": prop.join("|"),
|
|
"useskin": useSkin,
|
|
};
|
|
|
|
if (title != null) query["page"] = title;
|
|
if (pageId != null) query["pageid"] = pageId;
|
|
if (disableEditSection) query["disableeditsection"] = 1;
|
|
if (section != null) query["section"] = section;
|
|
if (disableTOC) query["disabletoc"] = 1;
|
|
if (mobileMode) query["mobilenode"] = 1;
|
|
|
|
var mwRes = await MWApi.get("parse", params: query);
|
|
var parseInfo = MWParseInfo.fromJson(mwRes.data);
|
|
|
|
if (parseInfo.sections.isNotEmpty) {
|
|
parseInfo = parseInfo.copyWith(
|
|
sections: parseInfo.sections
|
|
.map(
|
|
(section) => section.copyWith(
|
|
line: Bidi.stripHtmlIfNeeded(section.line),
|
|
),
|
|
)
|
|
.toList(),
|
|
);
|
|
}
|
|
|
|
return mwRes.replaceData(parseInfo);
|
|
}
|
|
}
|