diff --git a/src/tools-settings.ts b/src/tools-settings.ts index ebf34e1f..987df7ca 100644 --- a/src/tools-settings.ts +++ b/src/tools-settings.ts @@ -1,8 +1,17 @@ import { appBaseUrl as base } from '@/utils/base-url'; +import type { ToolsSettings } from '@/utils/tools-settings'; + +export { type ToolsSettings, getToolsSettingString } from '@/utils/tools-settings'; // Optional per-deployment settings. Lives in its own top-level-await module so the // fetch runs concurrently with the config fetches in src/tools/index.ts (sibling async // module subgraphs evaluate in parallel) instead of serially after them. -export const toolsSettings: Record | any> = await fetch(`${base}tools-settings.json`) - .then((response) => (response.ok ? (response.json() as Promise | any>>) : {})) +export const toolsSettings: ToolsSettings = await fetch(`${base}tools-settings.json`) + .then((response) => (response.ok ? (response.json() as Promise) : {})) .catch(() => ({})); + +/** + * `"offline": true` in tools-settings.json marks a deployment without internet access (an air-gapped intranet). + * Tools that only work with internet are hidden, and tools with a bundled or mirrored fallback switch to it. + */ +export const isOfflineMode = toolsSettings.offline === true; diff --git a/src/tools/dns-propagation-tester/index.ts b/src/tools/dns-propagation-tester/index.ts index 699d34ab..b58d88b8 100644 --- a/src/tools/dns-propagation-tester/index.ts +++ b/src/tools/dns-propagation-tester/index.ts @@ -11,4 +11,5 @@ export const tool = defineTool({ createdAt: new Date('2026-05-11'), category: 'Forensic', externAccessDescription: t('tools.dns-propagation-tester.externalAccess'), + requiresInternet: true, }); diff --git a/src/tools/dns-queries/index.ts b/src/tools/dns-queries/index.ts index 7fe29930..0a3fa795 100644 --- a/src/tools/dns-queries/index.ts +++ b/src/tools/dns-queries/index.ts @@ -11,4 +11,5 @@ export const tool = defineTool({ createdAt: new Date('2024-08-15'), category: 'Network', externAccessDescription: t('tools.dns-queries.externalAccess'), + requiresInternet: true, }); diff --git a/src/tools/dnsbl-checker/index.ts b/src/tools/dnsbl-checker/index.ts index 0e37dc21..10eed385 100644 --- a/src/tools/dnsbl-checker/index.ts +++ b/src/tools/dnsbl-checker/index.ts @@ -11,4 +11,5 @@ export const tool = defineTool({ createdAt: new Date('2025-08-15'), category: 'Network', externAccessDescription: t('tools.dnsbl-checker.externalAccess'), + requiresInternet: true, }); diff --git a/src/tools/explainshell/index.ts b/src/tools/explainshell/index.ts index 82b4d674..219efd58 100644 --- a/src/tools/explainshell/index.ts +++ b/src/tools/explainshell/index.ts @@ -1,5 +1,6 @@ import { translate as t } from '@/plugins/i18n.plugin'; import { defineTool } from '../tool'; +import { getToolsSettingString } from '@/utils/tools-settings'; export const tool = defineTool({ name: t('tools.explainshell.title'), @@ -11,4 +12,5 @@ export const tool = defineTool({ createdAt: new Date('2026-01-30'), category: 'Data', externAccessDescription: t('tools.explainshell.externalAccess'), + requiresInternet: (settings) => !getToolsSettingString(settings, 'explainchain', 'url'), }); diff --git a/src/tools/iana-whois-checker/index.ts b/src/tools/iana-whois-checker/index.ts index 7db0153d..48136360 100644 --- a/src/tools/iana-whois-checker/index.ts +++ b/src/tools/iana-whois-checker/index.ts @@ -11,4 +11,5 @@ export const tool = defineTool({ createdAt: new Date('2025-10-03'), category: 'Network', externAccessDescription: t('tools.iana-whois-checker.externalAccess'), + requiresInternet: true, }); diff --git a/src/tools/index.ts b/src/tools/index.ts index 2e1b7097..4c290d8e 100644 --- a/src/tools/index.ts +++ b/src/tools/index.ts @@ -5,14 +5,17 @@ import { appBaseUrl as base } from '@/utils/base-url'; const modules = import.meta.glob('./*/index.ts', { eager: true, import: 'tool' }); // Both config files are optional; fetch them in parallel so app boot waits on at -// most one network round-trip instead of two sequential ones. -const [filterConfig, externalTools] = await Promise.all([ +// most one network round-trip instead of two sequential ones. tools-settings.json is +// imported dynamically for the same reason: a static import would evaluate (and fetch) +// it before this module's own fetches start. +const [filterConfig, externalTools, { toolsSettings, isOfflineMode }] = await Promise.all([ fetch(`${base}tools-filter.json`) .then((response) => (response.ok ? (response.json() as Promise) : ({} as ToolsFilter))) .catch(() => ({}) as ToolsFilter), fetch(`${base}external-tools.json`) .then((response) => (response.ok ? (response.json() as Promise) : ([] as ExternalTool[]))) .catch(() => [] as ExternalTool[]), + import('@/tools-settings'), ]); const allModules: ToolWithCategory[] = Object.values(modules); @@ -45,7 +48,13 @@ const filters = { includeToolsFilterRegex: makeRegExp(filterConfig.includeToolsFilterRegex), }; +const requiresInternet = ({ requiresInternet }: ToolWithCategory) => + typeof requiresInternet === 'function' ? requiresInternet(toolsSettings) : Boolean(requiresInternet); + const filteredModules = allModules.filter((tool) => { + if (isOfflineMode && requiresInternet(tool)) { + return false; + } const category = tool.category || 'Development'; if (filters.includeToolsFilterRegex?.test(tool.path)) { return true; diff --git a/src/tools/ip-geo-location/index.ts b/src/tools/ip-geo-location/index.ts index e385bbc2..d410fb4f 100644 --- a/src/tools/ip-geo-location/index.ts +++ b/src/tools/ip-geo-location/index.ts @@ -11,4 +11,5 @@ export const tool = defineTool({ createdAt: new Date('2024-01-17'), category: 'Network', externAccessDescription: t('tools.ip-geo-location.externalAccess'), + requiresInternet: true, }); diff --git a/src/tools/my-ip/index.ts b/src/tools/my-ip/index.ts index 8a0d923d..a9578dfb 100644 --- a/src/tools/my-ip/index.ts +++ b/src/tools/my-ip/index.ts @@ -11,4 +11,5 @@ export const tool = defineTool({ createdAt: new Date('2025-01-01'), category: 'Network', externAccessDescription: t('tools.my-ip.externalAccess'), + requiresInternet: true, }); diff --git a/src/tools/online-wiktionary/index.ts b/src/tools/online-wiktionary/index.ts index a2131dbe..82710f10 100644 --- a/src/tools/online-wiktionary/index.ts +++ b/src/tools/online-wiktionary/index.ts @@ -11,4 +11,5 @@ export const tool = defineTool({ createdAt: new Date('2026-01-03'), category: 'Data', externAccessDescription: t('tools.online-wiktionary.externalAccess'), + requiresInternet: true, }); diff --git a/src/tools/tools.types.ts b/src/tools/tools.types.ts index 28057a5b..7ff81a11 100644 --- a/src/tools/tools.types.ts +++ b/src/tools/tools.types.ts @@ -1,3 +1,4 @@ +import type { ToolsSettings } from '@/utils/tools-settings'; import type { Component } from 'vue'; export interface Tool { @@ -12,6 +13,12 @@ export interface Tool { createdAt?: Date; npmPackages?: string[]; externAccessDescription?: string; + /** + * Whether the tool needs internet access to be useful. When the deployment sets `"offline": true` in + * tools-settings.json, tools for which this is (or returns) true are hidden. Use the function form for tools that + * work offline once an intranet mirror is configured in tools-settings.json. + */ + requiresInternet?: boolean | ((settings: ToolsSettings) => boolean); footer?: string; category: string; externalHTMLContent?: string; diff --git a/src/utils/tools-settings.ts b/src/utils/tools-settings.ts new file mode 100644 index 00000000..ee93fbc1 --- /dev/null +++ b/src/utils/tools-settings.ts @@ -0,0 +1,9 @@ +// Kept apart from src/tools-settings.ts, which fetches tools-settings.json with a top-level await: tool index.ts files +// load eagerly, and importing that module from them would hold up src/tools/index.ts until the fetch completes. + +export type ToolsSettings = Record; + +/** A second-level `tools-settings.json` value (`{ "": { "": "..." } }`), trimmed, or '' when unset. */ +export function getToolsSettingString(settings: ToolsSettings, tool: string, key: string): string { + return String(settings[tool]?.[key] ?? '').trim(); +}