fix(ocr): correctly load data from API
Also for some reason eng traineddata were missing in the app, hopefully fixed by this
This commit is contained in:
parent
1c85e0150d
commit
2f13b295c9
3 changed files with 13 additions and 11 deletions
|
@ -11,21 +11,22 @@ class TessdataApi {
|
||||||
static final Dio _client = Dio(
|
static final Dio _client = Dio(
|
||||||
BaseOptions(
|
BaseOptions(
|
||||||
validateStatus: (status) => true,
|
validateStatus: (status) => true,
|
||||||
|
headers: {"User-Agent": "prasule/1.0.0"},
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
/// Gets available languages from the repo
|
/// Gets available languages from the repo
|
||||||
static Future<List<String>> getAvailableData() async {
|
static Future<List<String>> getAvailableData() async {
|
||||||
final res = await _client.get<List<Map<String, dynamic>>>(
|
final res = await _client.get<List<dynamic>>(
|
||||||
"https://git.mnau.xyz/api/v1/repos/hernik/tessdata_fast/contents",
|
"https://git.mnau.xyz/api/v1/repos/hernik/tessdata_fast/contents",
|
||||||
options: Options(headers: {"Accept": "application/json"}),
|
options: Options(headers: {"Accept": "application/json"}),
|
||||||
);
|
);
|
||||||
if ((res.statusCode ?? 500) > 399) {
|
if ((res.statusCode ?? 500) > 399) {
|
||||||
return Future.error("The server returned status code ${res.statusCode}");
|
return Future.error("The server returned status code ${res.statusCode}");
|
||||||
}
|
}
|
||||||
final data = res.data;
|
final data = List<Map<String, dynamic>>.from(res.data ?? []);
|
||||||
final dataFiles = <String>[];
|
final dataFiles = <String>[];
|
||||||
for (final file in data ?? <Map<String, dynamic>>[]) {
|
for (final file in data) {
|
||||||
if (!(file["name"] as String).endsWith(".traineddata")) continue;
|
if (!(file["name"] as String).endsWith(".traineddata")) continue;
|
||||||
dataFiles.add((file["name"] as String).replaceAll(".traineddata", ""));
|
dataFiles.add((file["name"] as String).replaceAll(".traineddata", ""));
|
||||||
}
|
}
|
||||||
|
|
|
@ -472,12 +472,13 @@ class _HomeViewState extends State<HomeView> {
|
||||||
PlatformButton(
|
PlatformButton(
|
||||||
text: AppLocalizations.of(context).download,
|
text: AppLocalizations.of(context).download,
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
Navigator.of(context).push(
|
Navigator.of(context)
|
||||||
platformRoute(
|
.push(
|
||||||
(c) => const TessdataListView(),
|
platformRoute(
|
||||||
),
|
(c) => const TessdataListView(),
|
||||||
);
|
),
|
||||||
Navigator.of(c).pop();
|
)
|
||||||
|
.then((value) => Navigator.of(c).pop());
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
PlatformButton(
|
PlatformButton(
|
||||||
|
|
|
@ -84,8 +84,8 @@ flutter:
|
||||||
# the material Icons class.
|
# the material Icons class.
|
||||||
uses-material-design: true
|
uses-material-design: true
|
||||||
assets:
|
assets:
|
||||||
- assets/
|
- assets/tessdata_config.json
|
||||||
- assets/tessdata/
|
- assets/tessdata/eng.traineddata
|
||||||
# To add assets to your application, add an assets section, like this:
|
# To add assets to your application, add an assets section, like this:
|
||||||
# assets:
|
# assets:
|
||||||
# - images/a_dot_burr.jpeg
|
# - images/a_dot_burr.jpeg
|
||||||
|
|
Loading…
Reference in a new issue