fix(explainshell, ocr-image): honour the configured mirrors

Offline, explainshell now always uses the configured explainchain.url.
Before, a URL the browser had stored earlier (the public
explainshell.com) overrode it.

ocr-image's lang-url template may now name the file
(.../{lang}.traineddata.gz). tesseract.js appends that file name itself,
so the template is reduced to its directory instead of requesting a
duplicated path.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
Sebastian DanielssonandClaude Opus 5.5 authored and sharevb committed 2026-10-25 18:51:17 +01:00
1 parent b64d2a1742
commit 8ec559012d
5 files changed
+63 -5

No files matched your search

+1 -1
View File
@@ -262,7 +262,7 @@ Some tools work offline once you point them at an intranet mirror; without one,
| Setting | Used by | Expected content |
| --- | --- | --- |
| `transformers.models-url` | translator, remove-background, math-ocr | A mirror of the Hugging Face model repos with the same layout: `<url>/<org>/<model>/resolve/main/<file>`, e.g. `Xenova/opus-mt-en-fr/resolve/main/onnx/encoder_model_quantized.onnx`. Relative URLs resolve against the app. |
| `ocr-image.lang-url` | ocr-image | A directory of `<lang>.traineddata.gz` files (the `4.0.0_best_int` variant from the `@tesseract.js-data/<lang>` npm packages), or a URL containing a `{lang}` placeholder. |
| `ocr-image.lang-url` | ocr-image | A directory of `<lang>.traineddata.gz` files (the `4.0.0_best_int` variant from the `@tesseract.js-data/<lang>` npm packages). The path may contain a `{lang}` placeholder, e.g. `https://intranet.example/npm/@tesseract.js-data/{lang}/4.0.0_best_int` for a mirror of jsDelivr. |
| `json-schemas.catalog-url` | json-viewer, yaml-viewer, json-editor, json-linter | A copy of the [SchemaStore](https://www.schemastore.org) catalog. The schema URLs listed in it must be reachable too. |
| `currency-converter.url` | currency-converter | A mirror of the `@fawazahmed0/currency-api` npm package, serving `v1/currencies/<code>.json`. |
| `geo-coordinates-converter.tile-url` | geo-coordinates-converter | A Leaflet tile URL template; `tile-attribution` is optional. |
+8 -2
View File
@@ -1,11 +1,17 @@
<script setup lang="ts">
import { useI18n } from 'vue-i18n';
import { useITStorage, useQueryParam } from '@/composable/queryParams';
import { getToolsSettingString, isOfflineMode, toolsSettings } from '@/tools-settings';
const { t } = useI18n();
const command = useQueryParam({ tool: 'explainshell', name: 'command', defaultValue: '' });
const explainshellUrl = useITStorage('explainchain:url', 'https://explainshell.com');
// Offline, the deployment's self-hosted instance is the only one reachable (the tool is hidden without it), so it
// overrides any URL the browser stored earlier.
const fixedExplainshellUrl = isOfflineMode ? getToolsSettingString(toolsSettings, 'explainchain', 'url') : '';
const explainshellUrl = fixedExplainshellUrl
? ref(fixedExplainshellUrl)
: useITStorage('explainchain:url', 'https://explainshell.com');
const iframeUrl = ref('');
function openExplain() {
@@ -16,7 +22,7 @@ function openExplain() {
<template>
<div>
<details mb-1>
<details v-if="!fixedExplainshellUrl" mb-1>
<summary>{{ t('tools.explainshell.texts.tag-explain-shell-configuration') }}</summary>
<n-card>
<c-input-text
+38
View File
@@ -0,0 +1,38 @@
import { describe, expect, it } from 'vitest';
import { getMirrorLangPath } from './lang-path';
describe('getMirrorLangPath', () => {
it('uses a plain directory as is, with or without a trailing slash', () => {
expect(getMirrorLangPath('https://intranet.example/tessdata/', 'fra', 'https://it-tools.example/')).to.equal(
'https://intranet.example/tessdata/',
);
expect(getMirrorLangPath('https://intranet.example/tessdata', 'fra', 'https://it-tools.example/')).to.equal(
'https://intranet.example/tessdata',
);
});
it('fills a {lang} placeholder in the directory path', () => {
expect(
getMirrorLangPath(
'https://intranet.example/npm/@tesseract.js-data/{lang}/4.0.0_best_int',
'deu',
'https://it-tools.example/',
),
).to.equal('https://intranet.example/npm/@tesseract.js-data/deu/4.0.0_best_int');
});
it('reduces a template naming the file to its directory', () => {
expect(
getMirrorLangPath('https://intranet.example/tessdata/{lang}.traineddata.gz', 'fra', 'https://it-tools.example/'),
).to.equal('https://intranet.example/tessdata');
expect(
getMirrorLangPath('https://intranet.example/{lang}/{lang}.traineddata', 'fra', 'https://it-tools.example/'),
).to.equal('https://intranet.example/fra');
});
it('resolves relative mirrors against the app base', () => {
expect(getMirrorLangPath('tessdata/', 'fra', 'https://it-tools.example/sub/')).to.equal(
'https://it-tools.example/sub/tessdata/',
);
});
});
+12
View File
@@ -0,0 +1,12 @@
/**
* The tesseract.js `langPath` for a language served by the `ocr-image.lang-url` mirror from tools-settings.json.
*
* tesseract.js always appends `/<lang>.traineddata.gz` to langPath, so the mirror is a directory, optionally with a
* `{lang}` placeholder in the path (e.g. a mirror of jsDelivr's `.../@tesseract.js-data/{lang}/4.0.0_best_int`). A
* template that names the file itself (`.../{lang}.traineddata.gz`) is reduced to its directory. Relative URLs resolve
* against `baseUrl`.
*/
export function getMirrorLangPath(template: string, lang: string, baseUrl: string) {
const directory = template.replace(/\/?\{lang\}\.traineddata(\.gz)?$/, '');
return new URL(directory.replaceAll('{lang}', lang), baseUrl).href;
}
+4 -2
View File
@@ -12,6 +12,7 @@ import { getDocument } from 'pdfjs-dist';
import * as pdfJS from 'pdfjs-dist';
import pdfJSWorkerURL from 'pdfjs-dist/build/pdf.worker?url';
import { textStatistics } from '../text-statistics/text-statistics.service';
import { getMirrorLangPath } from './lang-path';
import TextareaCopyable from '@/components/TextareaCopyable.vue';
import { useQueryParamOrStorage } from '@/composable/queryParams';
import { getToolsSettingString, isOfflineMode, toolsSettings } from '@/tools-settings';
@@ -126,7 +127,8 @@ const languages = [
const bundledLanguageData: Record<string, string> = { eng: engDataUrl, chi_sim: chiSimDataUrl };
// Other languages come from `{ "ocr-image": { "lang-url": "..." } }` in tools-settings.json when set (a directory
// of `<lang>.traineddata.gz` files, or a URL with a `{lang}` placeholder), otherwise from tesseract.js' default CDN.
// of `<lang>.traineddata.gz` files, optionally with a `{lang}` placeholder in the path, e.g. a mirror of jsDelivr's
// `.../@tesseract.js-data/{lang}/4.0.0_best_int`), otherwise from tesseract.js' default CDN.
const languageDataUrl = getToolsSettingString(toolsSettings, 'ocr-image', 'lang-url');
function getLangPath(lang: string) {
@@ -135,7 +137,7 @@ function getLangPath(lang: string) {
return new URL('.', new URL(bundled, document.baseURI)).href;
}
if (languageDataUrl) {
return new URL(languageDataUrl.replaceAll('{lang}', lang), document.baseURI).href;
return getMirrorLangPath(languageDataUrl, lang, document.baseURI);
}
return undefined;
}