mirror of
https://github.com/sharevb/it-tools.git
synced 2026-11-22 22:02:38 +03:00
feat(settings): add an offline mode that hides internet-only tools
"offline": true in tools-settings.json hides tools that need internet access (menus and routes). Tools declare it with requiresInternet, either always or unless an intranet mirror is configured. The settings helper lives in a module without top-level await so eagerly loaded tool index.ts files can use it without delaying app boot. Refs sharevb/it-tools#571 Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
ea30976669
commit
4a80283786
12 files changed
+47
-4
No files matched your search
+11
-2
@@ -1,8 +1,17 @@
|
|||||||
import { appBaseUrl as base } from '@/utils/base-url';
|
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
|
// 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
|
// fetch runs concurrently with the config fetches in src/tools/index.ts (sibling async
|
||||||
// module subgraphs evaluate in parallel) instead of serially after them.
|
// module subgraphs evaluate in parallel) instead of serially after them.
|
||||||
export const toolsSettings: Record<string, Record<string, any> | any> = await fetch(`${base}tools-settings.json`)
|
export const toolsSettings: ToolsSettings = await fetch(`${base}tools-settings.json`)
|
||||||
.then((response) => (response.ok ? (response.json() as Promise<Record<string, Record<string, any> | any>>) : {}))
|
.then((response) => (response.ok ? (response.json() as Promise<ToolsSettings>) : {}))
|
||||||
.catch(() => ({}));
|
.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;
|
||||||
@@ -11,4 +11,5 @@ export const tool = defineTool({
|
|||||||
createdAt: new Date('2026-05-11'),
|
createdAt: new Date('2026-05-11'),
|
||||||
category: 'Forensic',
|
category: 'Forensic',
|
||||||
externAccessDescription: t('tools.dns-propagation-tester.externalAccess'),
|
externAccessDescription: t('tools.dns-propagation-tester.externalAccess'),
|
||||||
|
requiresInternet: true,
|
||||||
});
|
});
|
||||||
@@ -11,4 +11,5 @@ export const tool = defineTool({
|
|||||||
createdAt: new Date('2024-08-15'),
|
createdAt: new Date('2024-08-15'),
|
||||||
category: 'Network',
|
category: 'Network',
|
||||||
externAccessDescription: t('tools.dns-queries.externalAccess'),
|
externAccessDescription: t('tools.dns-queries.externalAccess'),
|
||||||
|
requiresInternet: true,
|
||||||
});
|
});
|
||||||
@@ -11,4 +11,5 @@ export const tool = defineTool({
|
|||||||
createdAt: new Date('2025-08-15'),
|
createdAt: new Date('2025-08-15'),
|
||||||
category: 'Network',
|
category: 'Network',
|
||||||
externAccessDescription: t('tools.dnsbl-checker.externalAccess'),
|
externAccessDescription: t('tools.dnsbl-checker.externalAccess'),
|
||||||
|
requiresInternet: true,
|
||||||
});
|
});
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
import { translate as t } from '@/plugins/i18n.plugin';
|
import { translate as t } from '@/plugins/i18n.plugin';
|
||||||
import { defineTool } from '../tool';
|
import { defineTool } from '../tool';
|
||||||
|
import { getToolsSettingString } from '@/utils/tools-settings';
|
||||||
|
|
||||||
export const tool = defineTool({
|
export const tool = defineTool({
|
||||||
name: t('tools.explainshell.title'),
|
name: t('tools.explainshell.title'),
|
||||||
@@ -11,4 +12,5 @@ export const tool = defineTool({
|
|||||||
createdAt: new Date('2026-01-30'),
|
createdAt: new Date('2026-01-30'),
|
||||||
category: 'Data',
|
category: 'Data',
|
||||||
externAccessDescription: t('tools.explainshell.externalAccess'),
|
externAccessDescription: t('tools.explainshell.externalAccess'),
|
||||||
|
requiresInternet: (settings) => !getToolsSettingString(settings, 'explainchain', 'url'),
|
||||||
});
|
});
|
||||||
@@ -11,4 +11,5 @@ export const tool = defineTool({
|
|||||||
createdAt: new Date('2025-10-03'),
|
createdAt: new Date('2025-10-03'),
|
||||||
category: 'Network',
|
category: 'Network',
|
||||||
externAccessDescription: t('tools.iana-whois-checker.externalAccess'),
|
externAccessDescription: t('tools.iana-whois-checker.externalAccess'),
|
||||||
|
requiresInternet: true,
|
||||||
});
|
});
|
||||||
+11
-2
@@ -5,14 +5,17 @@ import { appBaseUrl as base } from '@/utils/base-url';
|
|||||||
const modules = import.meta.glob<true, string, ToolWithCategory>('./*/index.ts', { eager: true, import: 'tool' });
|
const modules = import.meta.glob<true, string, ToolWithCategory>('./*/index.ts', { eager: true, import: 'tool' });
|
||||||
|
|
||||||
// Both config files are optional; fetch them in parallel so app boot waits on at
|
// 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.
|
// most one network round-trip instead of two sequential ones. tools-settings.json is
|
||||||
const [filterConfig, externalTools] = await Promise.all([
|
// 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`)
|
fetch(`${base}tools-filter.json`)
|
||||||
.then((response) => (response.ok ? (response.json() as Promise<ToolsFilter>) : ({} as ToolsFilter)))
|
.then((response) => (response.ok ? (response.json() as Promise<ToolsFilter>) : ({} as ToolsFilter)))
|
||||||
.catch(() => ({}) as ToolsFilter),
|
.catch(() => ({}) as ToolsFilter),
|
||||||
fetch(`${base}external-tools.json`)
|
fetch(`${base}external-tools.json`)
|
||||||
.then((response) => (response.ok ? (response.json() as Promise<ExternalTool[]>) : ([] as ExternalTool[])))
|
.then((response) => (response.ok ? (response.json() as Promise<ExternalTool[]>) : ([] as ExternalTool[])))
|
||||||
.catch(() => [] as ExternalTool[]),
|
.catch(() => [] as ExternalTool[]),
|
||||||
|
import('@/tools-settings'),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
const allModules: ToolWithCategory[] = Object.values(modules);
|
const allModules: ToolWithCategory[] = Object.values(modules);
|
||||||
@@ -45,7 +48,13 @@ const filters = {
|
|||||||
includeToolsFilterRegex: makeRegExp(filterConfig.includeToolsFilterRegex),
|
includeToolsFilterRegex: makeRegExp(filterConfig.includeToolsFilterRegex),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const requiresInternet = ({ requiresInternet }: ToolWithCategory) =>
|
||||||
|
typeof requiresInternet === 'function' ? requiresInternet(toolsSettings) : Boolean(requiresInternet);
|
||||||
|
|
||||||
const filteredModules = allModules.filter((tool) => {
|
const filteredModules = allModules.filter((tool) => {
|
||||||
|
if (isOfflineMode && requiresInternet(tool)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
const category = tool.category || 'Development';
|
const category = tool.category || 'Development';
|
||||||
if (filters.includeToolsFilterRegex?.test(tool.path)) {
|
if (filters.includeToolsFilterRegex?.test(tool.path)) {
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
@@ -11,4 +11,5 @@ export const tool = defineTool({
|
|||||||
createdAt: new Date('2024-01-17'),
|
createdAt: new Date('2024-01-17'),
|
||||||
category: 'Network',
|
category: 'Network',
|
||||||
externAccessDescription: t('tools.ip-geo-location.externalAccess'),
|
externAccessDescription: t('tools.ip-geo-location.externalAccess'),
|
||||||
|
requiresInternet: true,
|
||||||
});
|
});
|
||||||
@@ -11,4 +11,5 @@ export const tool = defineTool({
|
|||||||
createdAt: new Date('2025-01-01'),
|
createdAt: new Date('2025-01-01'),
|
||||||
category: 'Network',
|
category: 'Network',
|
||||||
externAccessDescription: t('tools.my-ip.externalAccess'),
|
externAccessDescription: t('tools.my-ip.externalAccess'),
|
||||||
|
requiresInternet: true,
|
||||||
});
|
});
|
||||||
@@ -11,4 +11,5 @@ export const tool = defineTool({
|
|||||||
createdAt: new Date('2026-01-03'),
|
createdAt: new Date('2026-01-03'),
|
||||||
category: 'Data',
|
category: 'Data',
|
||||||
externAccessDescription: t('tools.online-wiktionary.externalAccess'),
|
externAccessDescription: t('tools.online-wiktionary.externalAccess'),
|
||||||
|
requiresInternet: true,
|
||||||
});
|
});
|
||||||
@@ -1,3 +1,4 @@
|
|||||||
|
import type { ToolsSettings } from '@/utils/tools-settings';
|
||||||
import type { Component } from 'vue';
|
import type { Component } from 'vue';
|
||||||
|
|
||||||
export interface Tool {
|
export interface Tool {
|
||||||
@@ -12,6 +13,12 @@ export interface Tool {
|
|||||||
createdAt?: Date;
|
createdAt?: Date;
|
||||||
npmPackages?: string[];
|
npmPackages?: string[];
|
||||||
externAccessDescription?: 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;
|
footer?: string;
|
||||||
category: string;
|
category: string;
|
||||||
externalHTMLContent?: string;
|
externalHTMLContent?: string;
|
||||||
|
|||||||
@@ -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<string, any>;
|
||||||
|
|
||||||
|
/** A second-level `tools-settings.json` value (`{ "<tool>": { "<key>": "..." } }`), trimmed, or '' when unset. */
|
||||||
|
export function getToolsSettingString(settings: ToolsSettings, tool: string, key: string): string {
|
||||||
|
return String(settings[tool]?.[key] ?? '').trim();
|
||||||
|
}
|
||||||
Reference in new issue
Block a user