Skip to content

TagSpaces is an offline, open source, document manager with tagging support

feat: fetch map tiles via Electron main process to set Referer header

Ilian Sapundshievdd0ad88b4832
diff --git a/release/app/package-lock.json b/release/app/package-lock.json
index dc9d08845..10123fa14 100644
--- a/release/app/package-lock.json
+++ b/release/app/package-lock.json
@@ -1,17 +1,17 @@
{
"name": "tagspaces",
- "version": "6.10.3",
+ "version": "6.10.4",
"lockfileVersion": 2,
"requires": true,
"packages": {
"": {
"name": "tagspaces",
- "version": "6.10.3",
+ "version": "6.10.4",
"hasInstallScript": true,
"license": "AGPL-3.0",
"dependencies": {
"@elife/pm2": "3.6.1",
- "@tagspaces/extensions": "1.0.230",
+ "@tagspaces/extensions": "1.0.231",
"@tagspaces/tagspaces-common-node": "4.5.111",
"@tagspaces/tagspaces-ws": "4.5.111",
"sharp": "0.32.6",
@@ -90,9 +90,9 @@
"license": "MIT"
},
"node_modules/@tagspaces/extensions": {
- "version": "1.0.230",
- "resolved": "https://registry.npmjs.org/@tagspaces/extensions/-/extensions-1.0.230.tgz",
- "integrity": "sha512-ccqHUIre55gMAKehIcqZsea+E80mujkgaEulaNb60uDJ6fEPKfCsW3984oM1KWmFWHiNy1LD1VWnXkcgBbZ7Tw==",
+ "version": "1.0.231",
+ "resolved": "https://registry.npmjs.org/@tagspaces/extensions/-/extensions-1.0.231.tgz",
+ "integrity": "sha512-PmkjzC6CgSCSaXf+Sbk2omLu9OdBT4I7jteCM+PQWvgUKUycozeNFevz4iPu1gbsSPPKlMjDWv4HF4SBIqzJSg==",
"license": "MIT",
"dependencies": {
"@kenjiuno/msgreader": "^1.28.0",
@@ -2532,9 +2532,9 @@
"integrity": "sha512-42aWfPrimMfDKDi4YegyS7x+/0tlzaqwPQCULLanv3DMIlu96KTJR0fM5isWX2UViOqlGnX6YFgqWepcX+XMNg=="
},
"@tagspaces/extensions": {
- "version": "1.0.230",
- "resolved": "https://registry.npmjs.org/@tagspaces/extensions/-/extensions-1.0.230.tgz",
- "integrity": "sha512-ccqHUIre55gMAKehIcqZsea+E80mujkgaEulaNb60uDJ6fEPKfCsW3984oM1KWmFWHiNy1LD1VWnXkcgBbZ7Tw==",
+ "version": "1.0.231",
+ "resolved": "https://registry.npmjs.org/@tagspaces/extensions/-/extensions-1.0.231.tgz",
+ "integrity": "sha512-PmkjzC6CgSCSaXf+Sbk2omLu9OdBT4I7jteCM+PQWvgUKUycozeNFevz4iPu1gbsSPPKlMjDWv4HF4SBIqzJSg==",
"requires": {
"@kenjiuno/msgreader": "^1.28.0",
"@tiptap/core": "^3.19.0",
diff --git a/src/main/mainEvents.ts b/src/main/mainEvents.ts
index 902fb05e0..94bb93e7b 100644
--- a/src/main/mainEvents.ts
+++ b/src/main/mainEvents.ts
@@ -3,6 +3,7 @@ import {
dialog,
globalShortcut,
ipcMain,
+ net,
shell,
nativeImage,
BrowserWindow,
@@ -93,6 +94,21 @@ export default function loadMainEvents() {
//watchFolder(mainWindow, e, path, depth);
});
+ ipcMain.handle('fetchTile', async (_event, url: string) => {
+ const response = await net.fetch(url, {
+ headers: { Referer: 'https://tagspaces.org' },
+ });
+ if (!response.ok) {
+ throw new Error(
+ `Tile fetch failed: ${response.status} ${response.statusText}`,
+ );
+ }
+ const contentType = response.headers.get('content-type') || 'image/png';
+ const buffer = await response.arrayBuffer();
+ const base64 = Buffer.from(buffer).toString('base64');
+ return `data:${contentType};base64,${base64}`;
+ });
+
ipcMain.handle('fetchUrl', async (event, url, targetPath, withProgress) => {
function fetchHttp(url) {
return new Promise((resolve, reject) => {
diff --git a/src/main/preload.ts b/src/main/preload.ts
index 737004aa6..e7cca6bc5 100644
--- a/src/main/preload.ts
+++ b/src/main/preload.ts
@@ -82,7 +82,8 @@ export type Channels =
| 'deleteOllamaModel'
| 'startup-finished'
| 'getAuthor'
- | 'cancelRequest';
+ | 'cancelRequest'
+ | 'fetchTile';
const electronHandler = {
ipcRenderer: {
diff --git a/src/renderer/components/ElectronTileLayer.ts b/src/renderer/components/ElectronTileLayer.ts
new file mode 100644
index 000000000..339c60e62
--- /dev/null
+++ b/src/renderer/components/ElectronTileLayer.ts
@@ -0,0 +1,60 @@
+/**
+ * TagSpaces - universal file and folder organizer
+ * Copyright (C) 2026-present TagSpaces GmbH
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License (version 3) as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
+ *
+ */
+
+import { createTileLayerComponent, updateGridLayer } from '@react-leaflet/core';
+import L from 'leaflet';
+import { TileLayerProps } from 'react-leaflet';
+
+const ElectronTileLayerClass = L.TileLayer.extend({
+ createTile(coords: L.Coords, done: L.DoneCallback) {
+ const img = document.createElement('img');
+ img.alt = '';
+ const url = this.getTileUrl(coords);
+ const electronIO = (window as any).electronIO;
+ if (electronIO) {
+ electronIO.ipcRenderer
+ .invoke('fetchTile', url)
+ .then((dataUrl: string) => {
+ img.onload = () => done(null, img);
+ img.onerror = (e) => done(e as unknown as Error, img);
+ img.src = dataUrl;
+ })
+ .catch((err: Error) => done(err, img));
+ } else {
+ img.src = url;
+ img.addEventListener('load', () => done(undefined, img));
+ img.addEventListener('error', (e) => done(e as unknown as Error, img));
+ }
+ return img;
+ },
+});
+
+const ElectronTileLayer = createTileLayerComponent<L.TileLayer, TileLayerProps>(
+ ({ url, ...options }, context) => ({
+ instance: new (ElectronTileLayerClass as any)(url, options),
+ context,
+ }),
+ (instance, props, prevProps) => {
+ updateGridLayer(instance, props, prevProps);
+ if (props.url !== prevProps.url) {
+ instance.setUrl(props.url);
+ }
+ },
+);
+
+export default ElectronTileLayer;
diff --git a/src/renderer/components/EntryProperties.tsx b/src/renderer/components/EntryProperties.tsx
index 4fb3360f9..cc3fb062c 100644
--- a/src/renderer/components/EntryProperties.tsx
+++ b/src/renderer/components/EntryProperties.tsx
@@ -101,9 +101,9 @@ import {
MapContainer,
Marker,
Popup,
- TileLayer,
} from 'react-leaflet';
import { useSelector } from 'react-redux';
+import ElectronTileLayer from '-/components/ElectronTileLayer';
import { Pro } from '../pro';
const ThumbnailTextField = styled(TsTextField)(({ theme }) => ({
@@ -602,7 +602,7 @@ function EntryProperties({ tileServer }: Props) {
attributionControl={false}
>
{tileServer ? (
- <TileLayer
+ <ElectronTileLayer
attribution={tileServer.serverInfo}
url={tileServer.serverURL}
/>