aboutsummaryrefslogtreecommitdiff
path: root/frontend/src/utils
diff options
context:
space:
mode:
Diffstat (limited to 'frontend/src/utils')
-rw-r--r--frontend/src/utils/Jwt.ts20
-rw-r--r--frontend/src/utils/Time.ts26
2 files changed, 23 insertions, 23 deletions
diff --git a/frontend/src/utils/Jwt.ts b/frontend/src/utils/Jwt.ts
index affcd36..dc6ec92 100644
--- a/frontend/src/utils/Jwt.ts
+++ b/frontend/src/utils/Jwt.ts
@@ -5,20 +5,20 @@ export function get_user_id_from_token(
5 if (!token) { 5 if (!token) {
6 return undefined; 6 return undefined;
7 } 7 }
8 const parts = token.split('.'); 8 const parts = token.split(".");
9 if (parts.length !== 3) { 9 if (parts.length !== 3) {
10 return undefined; 10 return undefined;
11 } 11 }
12 const base64Url = parts[1]; 12 const base64Url = parts[1];
13 const base64 = base64Url.replace(/-/g, '+').replace(/_/g, '/'); 13 const base64 = base64Url.replace(/-/g, "+").replace(/_/g, "/");
14 14
15 const jsonPayload = decodeURIComponent( 15 const jsonPayload = decodeURIComponent(
16 atob(base64) 16 atob(base64)
17 .split('') 17 .split("")
18 .map(function (c) { 18 .map(function (c) {
19 return '%' + ('00' + c.charCodeAt(0).toString(16)).slice(-2); 19 return "%" + ("00" + c.charCodeAt(0).toString(16)).slice(-2);
20 }) 20 })
21 .join('') 21 .join("")
22 ); 22 );
23 return JSON.parse(jsonPayload).sub; 23 return JSON.parse(jsonPayload).sub;
24} 24}
@@ -29,20 +29,20 @@ export function get_user_mod_from_token(
29 if (!token) { 29 if (!token) {
30 return undefined; 30 return undefined;
31 } 31 }
32 const parts = token.split('.'); 32 const parts = token.split(".");
33 if (parts.length !== 3) { 33 if (parts.length !== 3) {
34 return undefined; 34 return undefined;
35 } 35 }
36 const base64Url = parts[1]; 36 const base64Url = parts[1];
37 const base64 = base64Url.replace(/-/g, '+').replace(/_/g, '/'); 37 const base64 = base64Url.replace(/-/g, "+").replace(/_/g, "/");
38 38
39 const jsonPayload = decodeURIComponent( 39 const jsonPayload = decodeURIComponent(
40 atob(base64) 40 atob(base64)
41 .split('') 41 .split("")
42 .map(function (c) { 42 .map(function (c) {
43 return '%' + ('00' + c.charCodeAt(0).toString(16)).slice(-2); 43 return "%" + ("00" + c.charCodeAt(0).toString(16)).slice(-2);
44 }) 44 })
45 .join('') 45 .join("")
46 ); 46 );
47 return JSON.parse(jsonPayload).mod; 47 return JSON.parse(jsonPayload).mod;
48} 48}
diff --git a/frontend/src/utils/Time.ts b/frontend/src/utils/Time.ts
index 34830b0..8f2c03c 100644
--- a/frontend/src/utils/Time.ts
+++ b/frontend/src/utils/Time.ts
@@ -6,47 +6,47 @@ export function time_ago(date: any) {
6 6
7 let interval = Math.floor(seconds / 31536000); 7 let interval = Math.floor(seconds / 31536000);
8 if (interval === 1) { 8 if (interval === 1) {
9 return interval + ' year ago'; 9 return interval + " year ago";
10 } 10 }
11 if (interval > 1) { 11 if (interval > 1) {
12 return interval + ' years ago'; 12 return interval + " years ago";
13 } 13 }
14 14
15 interval = Math.floor(seconds / 2592000); 15 interval = Math.floor(seconds / 2592000);
16 if (interval === 1) { 16 if (interval === 1) {
17 return interval + ' month ago'; 17 return interval + " month ago";
18 } 18 }
19 if (interval > 1) { 19 if (interval > 1) {
20 return interval + ' months ago'; 20 return interval + " months ago";
21 } 21 }
22 22
23 interval = Math.floor(seconds / 86400); 23 interval = Math.floor(seconds / 86400);
24 if (interval === 1) { 24 if (interval === 1) {
25 return interval + ' day ago'; 25 return interval + " day ago";
26 } 26 }
27 if (interval > 1) { 27 if (interval > 1) {
28 return interval + ' days ago'; 28 return interval + " days ago";
29 } 29 }
30 30
31 interval = Math.floor(seconds / 3600); 31 interval = Math.floor(seconds / 3600);
32 if (interval === 1) { 32 if (interval === 1) {
33 return interval + ' hour ago'; 33 return interval + " hour ago";
34 } 34 }
35 if (interval > 1) { 35 if (interval > 1) {
36 return interval + ' hours ago'; 36 return interval + " hours ago";
37 } 37 }
38 38
39 interval = Math.floor(seconds / 60); 39 interval = Math.floor(seconds / 60);
40 if (interval === 1) { 40 if (interval === 1) {
41 return interval + ' minute ago'; 41 return interval + " minute ago";
42 } 42 }
43 if (interval > 1) { 43 if (interval > 1) {
44 return interval + ' minutes ago'; 44 return interval + " minutes ago";
45 } 45 }
46 46
47 if (seconds < 10) return 'just now'; 47 if (seconds < 10) return "just now";
48 48
49 return Math.floor(seconds) + ' seconds ago'; 49 return Math.floor(seconds) + " seconds ago";
50} 50}
51 51
52export function ticks_to_time(ticks: number) { 52export function ticks_to_time(ticks: number) {
@@ -58,5 +58,5 @@ export function ticks_to_time(ticks: number) {
58 seconds = seconds % 60; 58 seconds = seconds % 60;
59 minutes = minutes % 60; 59 minutes = minutes % 60;
60 60
61 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')}`; 61 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")}`;
62} 62}