aboutsummaryrefslogtreecommitdiff
path: root/frontend/src/utils
diff options
context:
space:
mode:
authorArda Serdar Pektezol <1669855+pektezol@users.noreply.github.com>2025-10-22 13:59:12 +0400
committerGitHub <noreply@github.com>2025-10-22 12:59:12 +0300
commit69aeb7889ac136a8e4fbe7de1330298e30345479 (patch)
tree6b2cd2d420105dc7ffad3c3649df359f634cae77 /frontend/src/utils
parentfeat/rankings: update wr for 3 maps (#279) (diff)
downloadlphub-69aeb7889ac136a8e4fbe7de1330298e30345479.tar.gz
lphub-69aeb7889ac136a8e4fbe7de1330298e30345479.tar.bz2
lphub-69aeb7889ac136a8e4fbe7de1330298e30345479.zip
feat/frontend: switch to vite, update node to v22 (#281)
Diffstat (limited to 'frontend/src/utils')
-rw-r--r--frontend/src/utils/Jwt.ts20
-rw-r--r--frontend/src/utils/Time.ts30
2 files changed, 25 insertions, 25 deletions
diff --git a/frontend/src/utils/Jwt.ts b/frontend/src/utils/Jwt.ts
index ce351fb..a6d1866 100644
--- a/frontend/src/utils/Jwt.ts
+++ b/frontend/src/utils/Jwt.ts
@@ -3,20 +3,20 @@ export function get_user_id_from_token(token: string | undefined): string | unde
3 if (!token) { 3 if (!token) {
4 return undefined; 4 return undefined;
5 } 5 }
6 const parts = token.split('.'); 6 const parts = token.split(".");
7 if (parts.length !== 3) { 7 if (parts.length !== 3) {
8 return undefined; 8 return undefined;
9 } 9 }
10 const base64Url = parts[1]; 10 const base64Url = parts[1];
11 const base64 = base64Url.replace(/-/g, '+').replace(/_/g, '/'); 11 const base64 = base64Url.replace(/-/g, "+").replace(/_/g, "/");
12 12
13 const jsonPayload = decodeURIComponent( 13 const jsonPayload = decodeURIComponent(
14 atob(base64) 14 atob(base64)
15 .split('') 15 .split("")
16 .map(function (c) { 16 .map(function (c) {
17 return '%' + ('00' + c.charCodeAt(0).toString(16)).slice(-2); 17 return "%" + ("00" + c.charCodeAt(0).toString(16)).slice(-2);
18 }) 18 })
19 .join('') 19 .join("")
20 ); 20 );
21 return JSON.parse(jsonPayload).sub; 21 return JSON.parse(jsonPayload).sub;
22}; 22};
@@ -25,20 +25,20 @@ export function get_user_mod_from_token(token: string | undefined): boolean | un
25 if (!token) { 25 if (!token) {
26 return undefined; 26 return undefined;
27 } 27 }
28 const parts = token.split('.'); 28 const parts = token.split(".");
29 if (parts.length !== 3) { 29 if (parts.length !== 3) {
30 return undefined; 30 return undefined;
31 } 31 }
32 const base64Url = parts[1]; 32 const base64Url = parts[1];
33 const base64 = base64Url.replace(/-/g, '+').replace(/_/g, '/'); 33 const base64 = base64Url.replace(/-/g, "+").replace(/_/g, "/");
34 34
35 const jsonPayload = decodeURIComponent( 35 const jsonPayload = decodeURIComponent(
36 atob(base64) 36 atob(base64)
37 .split('') 37 .split("")
38 .map(function (c) { 38 .map(function (c) {
39 return '%' + ('00' + c.charCodeAt(0).toString(16)).slice(-2); 39 return "%" + ("00" + c.charCodeAt(0).toString(16)).slice(-2);
40 }) 40 })
41 .join('') 41 .join("")
42 ); 42 );
43 return JSON.parse(jsonPayload).mod; 43 return JSON.parse(jsonPayload).mod;
44}; 44};
diff --git a/frontend/src/utils/Time.ts b/frontend/src/utils/Time.ts
index b83a7ed..9cbe793 100644
--- a/frontend/src/utils/Time.ts
+++ b/frontend/src/utils/Time.ts
@@ -5,38 +5,38 @@ export function time_ago(date: any) {
5 const seconds = Math.floor((now - localDate.getTime()) / 1000); 5 const seconds = Math.floor((now - localDate.getTime()) / 1000);
6 6
7 let interval = Math.floor(seconds / 31536000); 7 let interval = Math.floor(seconds / 31536000);
8 if (interval === 1) {return interval + ' year ago';} 8 if (interval === 1) {return interval + " year ago";}
9 if (interval > 1) {return interval + ' years ago';} 9 if (interval > 1) {return interval + " years ago";}
10 10
11 interval = Math.floor(seconds / 2592000); 11 interval = Math.floor(seconds / 2592000);
12 if (interval === 1) {return interval + ' month ago';} 12 if (interval === 1) {return interval + " month ago";}
13 if (interval > 1) {return interval + ' months ago';} 13 if (interval > 1) {return interval + " months ago";}
14 14
15 interval = Math.floor(seconds / 86400); 15 interval = Math.floor(seconds / 86400);
16 if (interval === 1) {return interval + ' day ago';} 16 if (interval === 1) {return interval + " day ago";}
17 if (interval > 1) {return interval + ' days ago';} 17 if (interval > 1) {return interval + " days ago";}
18 18
19 interval = Math.floor(seconds / 3600); 19 interval = Math.floor(seconds / 3600);
20 if (interval === 1) {return interval + ' hour ago';} 20 if (interval === 1) {return interval + " hour ago";}
21 if (interval > 1) {return interval + ' hours ago';} 21 if (interval > 1) {return interval + " hours ago";}
22 22
23 interval = Math.floor(seconds / 60); 23 interval = Math.floor(seconds / 60);
24 if (interval === 1) {return interval + ' minute ago';} 24 if (interval === 1) {return interval + " minute ago";}
25 if (interval > 1) {return interval + ' minutes ago';} 25 if (interval > 1) {return interval + " minutes ago";}
26 26
27 if(seconds < 10) return 'just now'; 27 if(seconds < 10) return "just now";
28 28
29 return Math.floor(seconds) + ' seconds ago'; 29 return Math.floor(seconds) + " seconds ago";
30}; 30};
31 31
32export function ticks_to_time(ticks: number) { 32export function ticks_to_time(ticks: number) {
33 let seconds = Math.floor(ticks / 60) 33 let seconds = Math.floor(ticks / 60)
34 let minutes = Math.floor(seconds / 60) 34 let minutes = Math.floor(seconds / 60)
35 let hours = Math.floor(minutes / 60) 35 const hours = Math.floor(minutes / 60)
36 36
37 let milliseconds = Math.floor((ticks % 60) * 1000 / 60) 37 const milliseconds = Math.floor((ticks % 60) * 1000 / 60)
38 seconds = seconds % 60; 38 seconds = seconds % 60;
39 minutes = minutes % 60; 39 minutes = minutes % 60;
40 40
41 return `${hours === 0 ? "" : hours + ":"}${minutes === 0 ? "" : hours > 0 ? minutes.toString().padStart(2, '0') + ":" : (minutes + ":")}${minutes > 0 ? seconds.toString().padStart(2, '0') : seconds}.${milliseconds.toString().padStart(3, '0')}`; 41 return `${hours === 0 ? "" : hours + ":"}${minutes === 0 ? "" : hours > 0 ? minutes.toString().padStart(2, "0") + ":" : (minutes + ":")}${minutes > 0 ? seconds.toString().padStart(2, "0") : seconds}.${milliseconds.toString().padStart(3, "0")}`;
42}; \ No newline at end of file 42}; \ No newline at end of file