diff --git a/src/lib/components/results/general/single.svelte b/src/lib/components/results/general/single.svelte index 11740aac..56e8dfd7 100644 --- a/src/lib/components/results/general/single.svelte +++ b/src/lib/components/results/general/single.svelte @@ -10,11 +10,7 @@ /** @type {Props} */ let { result } = $props(); - const favicon = - result.favicon_hash && result.favicon_hash != '' - ? proxyFaviconLink(result.url, result.favicon_hash, result.favicon_hash_timestamp) - : Logo; - + const favicon = proxyFaviconLink(result.fqdn, result.fqdn_hash, result.fqdn_hash_timestamp); const shortDesc = result.description.length > 500 ? result.description.slice(0, 497) + '...' : result.description; diff --git a/src/lib/functions/api/proxyimage.js b/src/lib/functions/api/proxyimage.js index ebebca8a..45a25daa 100644 --- a/src/lib/functions/api/proxyimage.js +++ b/src/lib/functions/api/proxyimage.js @@ -7,15 +7,13 @@ import { concatSearchParams } from './concatparams'; * @param {string} url * @param {string} hash * @param {string} timestamp - * @param {boolean} [favicon] * @returns {string} */ -export function proxyImageLink(url, hash, timestamp, favicon = false) { +export function proxyImageLink(url, hash, timestamp) { const params = concatSearchParams([ ['url', url], ['hash', hash], - ['timestamp', timestamp], - ['favicon', favicon.toString()] + ['timestamp', timestamp] ]); /** @type {URL} */ @@ -32,20 +30,26 @@ export function proxyImageLink(url, hash, timestamp, favicon = false) { /** * Create a public API URL for the proxy favicon image endpoint. - * @param {string} url + * @param {string} fqdn * @param {string} hash * @param {string} timestamp * @returns {string} */ -export function proxyFaviconLink(url, hash, timestamp) { - const uriPattern = '^(http(s?))(://)([^/]+)'; - const uriRegex = new RegExp(uriPattern); - const uriMatch = url.match(uriRegex); +export function proxyFaviconLink(fqdn, hash, timestamp) { + const params = concatSearchParams([ + ['fqdn', fqdn], + ['hash', hash], + ['timestamp', timestamp] + ]); - if (!uriMatch || uriMatch.length === 0) { - throw error(400, 'Invalid URL'); + /** @type {URL} */ + let apiUrl; + try { + apiUrl = createApiUrl('proxy', params); + } catch (err) { + // Internal Server Error. + throw error(500, `Failed to create API URL: ${err}`); } - const uri = uriMatch[0]; - return proxyImageLink(uri, hash, timestamp, true); + return apiUrl.toString(); } diff --git a/src/lib/types/search/result.js b/src/lib/types/search/result.js index dcf320cf..c0b43dad 100644 --- a/src/lib/types/search/result.js +++ b/src/lib/types/search/result.js @@ -4,13 +4,14 @@ * @property {string} url - URL of the result. * @property {string} url_hash - Hash of the URL (used only for images). * @property {string} url_hash_timestamp - Timestamp of the URL hash (used only for images). + * @property {string} fqdn - The fully qualified domain name of the result. + * @property {string} fqdn_hash - Hash required for proxying the favicon. + * @property {string} fqdn_hash_timestamp - Timestamp of the favicon hash. * @property {number} rank - The rank of the result. * @property {number} score - The score of the result. * @property {string} title - The title of the result. * @property {string} description - The description of the result. * @property {EngineRankType[]} engine_ranks - Rankings on different search engines. - * @property {string} favicon_hash - Hash required for proxying the favicon. - * @property {string} favicon_hash_timestamp - Timestamp of the favicon hash. * ImageResultType * @property {ImageFormatType} original - The original image format details. * @property {ImageFormatType} thumbnail - The thumbnail image format details.