varminer-app-header 2.2.6 → 2.2.8
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/index.d.ts +0 -5
- package/dist/index.esm.js +53 -13
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +53 -13
- package/dist/index.js.map +1 -1
- package/dist/utils/localStorage.d.ts +0 -5
- package/dist/utils/localStorage.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -393,22 +393,28 @@ const getAllDataFromStorage = () => {
|
|
|
393
393
|
* @param baseUrl - Base URL for the object store API (default: http://objectstore.impact0mics.local:9012)
|
|
394
394
|
* @returns Profile picture URL or null if user_id is not available
|
|
395
395
|
*/
|
|
396
|
+
const VERIFICATION_USER_ID = 4590; // set to null to use only storage userId
|
|
396
397
|
const getProfilePictureUrl = (baseUrl = "http://objectstore.impact0mics.local:9012") => {
|
|
397
398
|
try {
|
|
398
399
|
const allData = getAllDataFromStorage();
|
|
399
|
-
const userId = allData.decodedToken?.user_id ?? allData.auth?.user_id ?? getStoredUserDetails()?.userId ?? null;
|
|
400
|
+
const userId = allData.decodedToken?.user_id ?? allData.auth?.user_id ?? getStoredUserDetails()?.userId ?? VERIFICATION_USER_ID ?? null;
|
|
400
401
|
if (userId == null)
|
|
401
402
|
return null;
|
|
402
|
-
return `${baseUrl.replace(/\/$/, "")}/v1/objectStore/profilePicture/path
|
|
403
|
+
return `${baseUrl.replace(/\/$/, "")}/v1/objectStore/profilePicture/path/${userId}`;
|
|
403
404
|
}
|
|
404
405
|
catch (err) {
|
|
405
406
|
console.error("Error getting profile picture URL:", err);
|
|
406
407
|
return null;
|
|
407
408
|
}
|
|
408
409
|
};
|
|
410
|
+
/** Extract S3 object key from s3Uri (e.g. s3://bucket/key → key). */
|
|
411
|
+
function getKeyFromS3Uri(s3Uri) {
|
|
412
|
+
const match = /^s3:\/\/[^/]+\/(.+)$/.exec(s3Uri.trim());
|
|
413
|
+
return match ? match[1] : null;
|
|
414
|
+
}
|
|
409
415
|
/**
|
|
410
|
-
* Fetch profile picture
|
|
411
|
-
* API returns
|
|
416
|
+
* Fetch profile picture: (1) GET path API for JSON with filePath/s3Uri, (2) GET download API with key to get image, return blob URL.
|
|
417
|
+
* Path API returns JSON: { statusResponse, filePath, s3Uri, errors }. Download API: GET /v1/objectStore/download?key=<key>.
|
|
412
418
|
* @param baseUrl - Base URL for the object store API (default: http://objectstore.impact0mics.local:9012)
|
|
413
419
|
* @returns Promise that resolves to blob URL string or null if fetch fails
|
|
414
420
|
*/
|
|
@@ -538,27 +544,61 @@ function getAccessTokenForRequest() {
|
|
|
538
544
|
}
|
|
539
545
|
const fetchProfilePictureAsBlobUrl = async (baseUrl = "http://objectstore.impact0mics.local:9012", accessTokenOverride) => {
|
|
540
546
|
try {
|
|
541
|
-
const
|
|
542
|
-
if (!
|
|
547
|
+
const profilePicturePathUrl = getProfilePictureUrl(baseUrl);
|
|
548
|
+
if (!profilePicturePathUrl)
|
|
543
549
|
return null;
|
|
544
550
|
const accessToken = (typeof accessTokenOverride === "string" && accessTokenOverride.length > 0
|
|
545
551
|
? accessTokenOverride
|
|
546
552
|
: null) ?? getAccessTokenForRequest();
|
|
547
|
-
const headers = {
|
|
553
|
+
const headers = {
|
|
554
|
+
"X-Message-Id": `msg-${Date.now()}-${Math.random().toString(36).slice(2, 11)}`,
|
|
555
|
+
"X-Correlation-Id": `corr-${Date.now()}-${Math.random().toString(36).slice(2, 11)}`,
|
|
556
|
+
};
|
|
548
557
|
if (accessToken) {
|
|
549
558
|
headers["Authorization"] = `Bearer ${accessToken}`;
|
|
550
559
|
}
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
560
|
+
// Step 1: GET path API → JSON with filePath, s3Uri
|
|
561
|
+
const pathResponse = await fetch(profilePicturePathUrl, { method: "GET", headers });
|
|
562
|
+
if (!pathResponse.ok) {
|
|
563
|
+
console.warn(`Failed to fetch profile picture path: ${pathResponse.status} ${pathResponse.statusText}`);
|
|
564
|
+
return null;
|
|
565
|
+
}
|
|
566
|
+
const pathData = (await pathResponse.json());
|
|
567
|
+
const status = pathData?.statusResponse?.status;
|
|
568
|
+
if (status !== "SUCCESS") {
|
|
569
|
+
console.warn("Profile picture path API did not return SUCCESS:", status, pathData?.errors);
|
|
570
|
+
return null;
|
|
571
|
+
}
|
|
572
|
+
// Key for download API: from s3Uri (s3://bucket/key) or response.key
|
|
573
|
+
let downloadKey = pathData.key ??
|
|
574
|
+
(pathData.s3Uri ? getKeyFromS3Uri(pathData.s3Uri) : null);
|
|
575
|
+
if (!downloadKey && pathData.filePath) {
|
|
576
|
+
try {
|
|
577
|
+
const u = new URL(pathData.filePath);
|
|
578
|
+
downloadKey = u.pathname.replace(/^\//, ""); // path without leading slash as key
|
|
579
|
+
}
|
|
580
|
+
catch {
|
|
581
|
+
// ignore
|
|
582
|
+
}
|
|
583
|
+
}
|
|
584
|
+
if (!downloadKey) {
|
|
585
|
+
console.warn("Profile picture response has no key/s3Uri/filePath for download");
|
|
586
|
+
return null;
|
|
587
|
+
}
|
|
588
|
+
// Step 2: GET download API → image bytes
|
|
589
|
+
const cleanBase = baseUrl.replace(/\/$/, "");
|
|
590
|
+
const downloadUrl = `${cleanBase}/v1/objectStore/download?key=${encodeURIComponent(downloadKey)}`;
|
|
591
|
+
const imageResponse = await fetch(downloadUrl, { method: "GET", headers });
|
|
592
|
+
if (!imageResponse.ok) {
|
|
593
|
+
console.warn(`Failed to fetch profile picture image: ${imageResponse.status} ${imageResponse.statusText}`);
|
|
554
594
|
return null;
|
|
555
595
|
}
|
|
556
|
-
const contentType =
|
|
596
|
+
const contentType = imageResponse.headers.get("content-type");
|
|
557
597
|
if (!contentType || !contentType.startsWith("image/")) {
|
|
558
|
-
console.warn(`Profile picture
|
|
598
|
+
console.warn(`Profile picture download is not an image: ${contentType}`);
|
|
559
599
|
return null;
|
|
560
600
|
}
|
|
561
|
-
const blob = await
|
|
601
|
+
const blob = await imageResponse.blob();
|
|
562
602
|
return URL.createObjectURL(blob);
|
|
563
603
|
}
|
|
564
604
|
catch (err) {
|