From 1f94c3f7de5127b7658c01e1525067cc62975095 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Aleksa=20Siri=C5=A1ki?=
<31509435+aleksasiriski@users.noreply.github.com>
Date: Mon, 2 Sep 2024 22:37:03 +0200
Subject: [PATCH 1/2] feat(proxy): make hashes expire after time
---
src/lib/components/results/general/single.svelte | 2 +-
src/lib/components/results/images/single.svelte | 6 +++++-
src/lib/functions/api/proxyimage.js | 11 +++++++----
src/lib/types/search/result.js | 5 ++++-
4 files changed, 17 insertions(+), 7 deletions(-)
diff --git a/src/lib/components/results/general/single.svelte b/src/lib/components/results/general/single.svelte
index 7f9501a4..5acb8b95 100644
--- a/src/lib/components/results/general/single.svelte
+++ b/src/lib/components/results/general/single.svelte
@@ -12,7 +12,7 @@
const favicon =
result.favicon_hash && result.favicon_hash != ''
- ? proxyFaviconLink(result.url, result.favicon_hash)
+ ? proxyFaviconLink(result.url, result.favicon_hash, result.favicon_hash_timestamp)
: Logo;
const shortDesc =
diff --git a/src/lib/components/results/images/single.svelte b/src/lib/components/results/images/single.svelte
index e15b0b47..c93c469d 100644
--- a/src/lib/components/results/images/single.svelte
+++ b/src/lib/components/results/images/single.svelte
@@ -37,7 +37,11 @@
diff --git a/src/lib/functions/api/proxyimage.js b/src/lib/functions/api/proxyimage.js
index 727ab5e0..96e61d7d 100644
--- a/src/lib/functions/api/proxyimage.js
+++ b/src/lib/functions/api/proxyimage.js
@@ -6,13 +6,15 @@ import { concatSearchParams } from './concatparams';
* Create a public API URL for the proxy image endpoint.
* @param {string} url
* @param {string} hash
+ * @param {string} timestamp
* @param {boolean} [favicon]
* @returns {string}
*/
-export function proxyImageLink(url, hash, favicon = false) {
+export function proxyImageLink(url, hash, timestamp, favicon = false) {
const params = concatSearchParams([
- ['hash', hash],
['url', url],
+ ['hash', hash],
+ ['timestamp', timestamp],
['favicon', favicon.toString()]
]);
@@ -32,9 +34,10 @@ export function proxyImageLink(url, hash, favicon = false) {
* Create a public API URL for the proxy favicon image endpoint.
* @param {string} url
* @param {string} hash
+ * @param {string} timestamp
* @returns {string}
*/
-export function proxyFaviconLink(url, hash) {
+export function proxyFaviconLink(url, hash, timestamp) {
const uriPattern = '^(http(s?))(://)([^/]+)';
const uriRegex = new RegExp(uriPattern);
const uriMatch = url.match(uriRegex);
@@ -44,5 +47,5 @@ export function proxyFaviconLink(url, hash) {
}
const uri = uriMatch[0];
- return proxyImageLink(uri, hash, true);
+ return proxyImageLink(uri, hash, timestamp, true);
}
diff --git a/src/lib/types/search/result.js b/src/lib/types/search/result.js
index 72cd9e7a..dcf320cf 100644
--- a/src/lib/types/search/result.js
+++ b/src/lib/types/search/result.js
@@ -2,18 +2,21 @@
* Describes the properties of a search result.
* @typedef {Object} ResultType
* @property {string} url - URL of the result.
- * @property {string} url_hash - Hash of the URL.
+ * @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 {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.
* @property {string} thumbnail_url - URL to the thumbnail image.
* @property {string} thumbnail_url_hash - Hash of the thumbnail URL.
+ * @property {string} thumbnail_url_hash_timestamp - Timestamp of the thumbnail URL hash.
* @property {string} source - The source of the image.
* @property {string} source_url - URL of the image source.
*/
From a03a689dc32b4dc988f46452c26012c2af253263 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Aleksa=20Siri=C5=A1ki?=
<31509435+aleksasiriski@users.noreply.github.com>
Date: Mon, 2 Sep 2024 23:54:16 +0200
Subject: [PATCH 2/2] fix(proxy): forgot preview image proxy
---
src/lib/components/results/images/preview.svelte | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/src/lib/components/results/images/preview.svelte b/src/lib/components/results/images/preview.svelte
index b06a5b51..3b3dd878 100644
--- a/src/lib/components/results/images/preview.svelte
+++ b/src/lib/components/results/images/preview.svelte
@@ -49,7 +49,11 @@