@@ -18,31 +44,31 @@ const progress = getProgress();
Percentage of Ipv4 scanned |
- {{progress.percentageOfIpv4Scanned}} |
+ {{data.percentageOfIpv4Scanned}} |
Total filtered |
- {{progress.totalFiltered}} |
+ {{data.totalFiltered}} |
Total Discarded |
- {{progress.totalDiscarded}} |
+ {{data.totalDiscarded}} |
Amount of Ipv4 left |
- {{progress.amountOfIpv4Left}} |
+ {{data.amountOfIpv4Left}} |
Discarded db size |
- {{progress.discardedDbSize}} |
+ {{data.discardedDbSize}} |
Filtered db size |
- {{progress.filteredDbSize}} |
+ {{data.filteredDbSize}} |
Unfiltered db size |
- {{progress.myDbSize}} |
+ {{data.myDbSize}} |
diff --git a/frontend/plugins/getProgress.ts b/frontend/plugins/getProgress.ts
deleted file mode 100644
index 4fc53e2..0000000
--- a/frontend/plugins/getProgress.ts
+++ /dev/null
@@ -1,20 +0,0 @@
-export default function getProgress(){
-
- const progress = ref(null as Progress | null);
-
- fetch('https://proxy.rbwr.dk/progress', {
- method: 'GET',
- headers: {'Content-Type': 'application/json'}
- })
- .then(response => response.json())
- .then((data: Progress) => {
- if (data && data.percentageOfIpv4Scanned) {
- progress.value = data;
- } else {
- console.error("Invalid data received from API");
- console.error(data);
- }
- });
-
- return progress;
-}
\ No newline at end of file
diff --git a/frontend/types/global.d.ts b/frontend/types/global.d.ts
index 072a453..d64c252 100644
--- a/frontend/types/global.d.ts
+++ b/frontend/types/global.d.ts
@@ -1,4 +1,4 @@
-interface Progress {
+interface ProgressType {
percentageOfIpv4Scanned: number; // assuming this is a number
totalFiltered: bigint;
amountOfIpv4Left: bigint;
@@ -6,4 +6,9 @@ interface Progress {
discardedDbSize: bigint;
filteredDbSize: bigint;
myDbSize: bigint;
-}
\ No newline at end of file
+}
+
+type CacheEntry
= {
+ data: T;
+ timestamp: number;
+};
\ No newline at end of file
diff --git a/frontend/utils/cacheUtil.ts b/frontend/utils/cacheUtil.ts
new file mode 100644
index 0000000..72befce
--- /dev/null
+++ b/frontend/utils/cacheUtil.ts
@@ -0,0 +1,34 @@
+export function fetchWithCache(
+ cacheKey: string,
+ fetchFunction: () => Promise,
+ maxAge: number = 5 // 30 seconds
+): Promise {
+ return new Promise(async (resolve, reject) => {
+ try {
+ const cachedData = localStorage.getItem(cacheKey);
+
+ if (cachedData) {
+ const { data, timestamp } = JSON.parse(cachedData) as CacheEntry;
+ const now = Date.now();
+ const ageInSeconds = (now - timestamp) / 1000;
+
+ // Check if cache is still valid
+ if (ageInSeconds < maxAge) {
+ return resolve(data);
+ }
+ }
+
+ // Cache is missing or expired, fetch fresh data
+ const freshData = await fetchFunction();
+ const cacheEntry: CacheEntry = {
+ data: freshData,
+ timestamp: Date.now(),
+ };
+
+ localStorage.setItem(cacheKey, JSON.stringify(cacheEntry));
+ resolve(freshData);
+ } catch (error) {
+ reject(error);
+ }
+ });
+}
\ No newline at end of file