@ludo.ninja/components 2.3.67 → 2.3.68
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { GetServerSideProps } from 'next';
|
|
2
|
+
export declare const hashString: (str: string) => number;
|
|
2
3
|
export type TimestampProps = {
|
|
3
4
|
isoTimestamp: string;
|
|
4
5
|
displayTimestamp: string;
|
|
5
6
|
checksum: number;
|
|
7
|
+
currentUrl: string;
|
|
6
8
|
};
|
|
7
|
-
export declare
|
|
8
|
-
export declare function withTimestampSSR(): GetServerSideProps<TimestampProps>;
|
|
9
|
+
export declare const withTimestampSSR: <P extends Record<string, any>>(getServerSideProps?: GetServerSideProps<P>) => GetServerSideProps<P & TimestampProps> | GetServerSideProps<TimestampProps>;
|
|
@@ -1,20 +1,21 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.withTimestampSSR =
|
|
3
|
+
exports.withTimestampSSR = exports.hashString = void 0;
|
|
4
4
|
let lastTimestamp = 0;
|
|
5
|
-
|
|
5
|
+
const hashString = (str) => {
|
|
6
6
|
let hash = 0;
|
|
7
7
|
for (let i = 0; i < str.length; i++) {
|
|
8
8
|
hash = (hash << 5) - hash + str.charCodeAt(i);
|
|
9
9
|
hash |= 0;
|
|
10
10
|
}
|
|
11
11
|
return Math.abs(hash);
|
|
12
|
-
}
|
|
13
|
-
|
|
12
|
+
};
|
|
13
|
+
exports.hashString = hashString;
|
|
14
|
+
const withTimestampSSR = (getServerSideProps) => {
|
|
14
15
|
return async (context) => {
|
|
15
16
|
const now = Date.now();
|
|
16
|
-
const
|
|
17
|
-
const hash = hashString(
|
|
17
|
+
const currentUrl = context.resolvedUrl || '/';
|
|
18
|
+
const hash = (0, exports.hashString)(currentUrl);
|
|
18
19
|
const secondsAgo = (hash % 59) + 2;
|
|
19
20
|
let proposedTimestamp = now - secondsAgo * 1000;
|
|
20
21
|
if (proposedTimestamp <= lastTimestamp) {
|
|
@@ -31,7 +32,7 @@ function withTimestampSSR(getServerSideProps) {
|
|
|
31
32
|
minute: '2-digit',
|
|
32
33
|
second: '2-digit',
|
|
33
34
|
});
|
|
34
|
-
const checksum = hashString(
|
|
35
|
+
const checksum = (0, exports.hashString)(currentUrl + isoTimestamp);
|
|
35
36
|
if (getServerSideProps) {
|
|
36
37
|
const result = await getServerSideProps(context);
|
|
37
38
|
if ('props' in result) {
|
|
@@ -41,6 +42,7 @@ function withTimestampSSR(getServerSideProps) {
|
|
|
41
42
|
isoTimestamp,
|
|
42
43
|
displayTimestamp,
|
|
43
44
|
checksum,
|
|
45
|
+
currentUrl,
|
|
44
46
|
},
|
|
45
47
|
};
|
|
46
48
|
}
|
|
@@ -51,7 +53,9 @@ function withTimestampSSR(getServerSideProps) {
|
|
|
51
53
|
isoTimestamp,
|
|
52
54
|
displayTimestamp,
|
|
53
55
|
checksum,
|
|
56
|
+
currentUrl,
|
|
54
57
|
},
|
|
55
58
|
};
|
|
56
59
|
};
|
|
57
|
-
}
|
|
60
|
+
};
|
|
61
|
+
exports.withTimestampSSR = withTimestampSSR;
|