Skip to content

Commit

Permalink
Merge pull request #575 from hearchco/as/fix/favicons
Browse files Browse the repository at this point in the history
fix: switch to FQDN favicon logic on agent
  • Loading branch information
aleksasiriski authored Oct 24, 2024
2 parents f2841a0 + 4395ec0 commit 92cbc04
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 20 deletions.
6 changes: 1 addition & 5 deletions src/lib/components/results/general/single.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
30 changes: 17 additions & 13 deletions src/lib/functions/api/proxyimage.js
Original file line number Diff line number Diff line change
Expand Up @@ -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} */
Expand All @@ -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();
}
5 changes: 3 additions & 2 deletions src/lib/types/search/result.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 92cbc04

Please sign in to comment.