@tekkare/romulus 0.1.306 → 0.1.307
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.
package/dist/module.json
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { getRequestHeader, type H3Event } from "h3";
|
|
2
2
|
import { getOipAccessToken } from "./oipAuth";
|
|
3
3
|
import { oipAppUrls } from "./oipGuards";
|
|
4
4
|
|
|
@@ -7,10 +7,12 @@ import { oipAppUrls } from "./oipGuards";
|
|
|
7
7
|
// valeurs des champs keyword des index lus, et nomme dans son mail les apps
|
|
8
8
|
// touchees : un champ passe en nested vide les filtres sans aucune erreur.
|
|
9
9
|
// A appeler depuis tout proxy ES d'app, avec les noms physiques interroges.
|
|
10
|
+
// La page appelante (Referer) dit si l'index sert l'app elle-meme ou les pages
|
|
11
|
+
// projets du layer (/projects), qui affichent les ressources de toutes les apps.
|
|
10
12
|
|
|
11
13
|
const DAY_MS = 24 * 60 * 60 * 1000;
|
|
12
14
|
|
|
13
|
-
/** Derniere declaration par index : une par jour et par instance suffit. */
|
|
15
|
+
/** Derniere declaration par contexte et index : une par jour et par instance suffit. */
|
|
14
16
|
const reported = new Map<string, number>();
|
|
15
17
|
|
|
16
18
|
/**
|
|
@@ -19,6 +21,7 @@ const reported = new Map<string, number>();
|
|
|
19
21
|
* (NUXT_OIP_APP_URL) ni jeton, rien ne part.
|
|
20
22
|
*/
|
|
21
23
|
export function oipReportIndexUsage(event: H3Event, physicalIndexes: string[]) {
|
|
24
|
+
const context = usageContext(event);
|
|
22
25
|
const apiUrl = (useRuntimeConfig().oipVirtualLabApiUrl as string) || process.env.VIRTUAL_LAB_API_URL;
|
|
23
26
|
let app = "";
|
|
24
27
|
try {
|
|
@@ -30,9 +33,9 @@ export function oipReportIndexUsage(event: H3Event, physicalIndexes: string[]) {
|
|
|
30
33
|
if (!apiUrl || !app) return;
|
|
31
34
|
|
|
32
35
|
const now = Date.now();
|
|
33
|
-
const due = physicalIndexes.filter((index) => now - (reported.get(index) ?? 0) > DAY_MS);
|
|
36
|
+
const due = physicalIndexes.filter((index) => now - (reported.get(`${context} ${index}`) ?? 0) > DAY_MS);
|
|
34
37
|
if (!due.length) return;
|
|
35
|
-
for (const index of due) reported.set(index
|
|
38
|
+
for (const index of due) reported.set(`${context} ${index}`, now);
|
|
36
39
|
|
|
37
40
|
void (async () => {
|
|
38
41
|
const token = await getOipAccessToken(event);
|
|
@@ -40,11 +43,21 @@ export function oipReportIndexUsage(event: H3Event, physicalIndexes: string[]) {
|
|
|
40
43
|
await $fetch(`${apiUrl}/index-health/usage`, {
|
|
41
44
|
method: "POST",
|
|
42
45
|
headers: { Authorization: `Bearer ${token}` },
|
|
43
|
-
body: { app, indexes: due },
|
|
46
|
+
body: { app, indexes: due, context },
|
|
44
47
|
});
|
|
45
48
|
})().catch((err: any) => {
|
|
46
49
|
// Reessaie a la prochaine requete plutot que dans un jour.
|
|
47
|
-
for (const index of due) reported.delete(index);
|
|
50
|
+
for (const index of due) reported.delete(`${context} ${index}`);
|
|
48
51
|
console.warn(`[oip/index-usage] report failed: ${err?.message ?? err}`);
|
|
49
52
|
});
|
|
50
53
|
}
|
|
54
|
+
|
|
55
|
+
/** `project` quand la requete part d'une page projet, sinon `app`. */
|
|
56
|
+
function usageContext(event: H3Event): "app" | "project" {
|
|
57
|
+
try {
|
|
58
|
+
const { pathname } = new URL(getRequestHeader(event, "referer") ?? "");
|
|
59
|
+
return /\/projects(\/|$)/.test(pathname) ? "project" : "app";
|
|
60
|
+
} catch {
|
|
61
|
+
return "app";
|
|
62
|
+
}
|
|
63
|
+
}
|