varminer-app-header 2.2.7 → 2.2.9
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 +66 -13
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +66 -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.d.ts
CHANGED
|
@@ -115,11 +115,6 @@ declare const setI18nLocaleToStorage: (locale: string) => void;
|
|
|
115
115
|
* @returns Object with auth, decodedToken, and other keys (user/userDetails/profile null when using header key)
|
|
116
116
|
*/
|
|
117
117
|
declare const getAllDataFromStorage: () => any;
|
|
118
|
-
/**
|
|
119
|
-
* Get profile picture URL from object store API using user_id.
|
|
120
|
-
* @param baseUrl - Base URL for the object store API (default: http://objectstore.impact0mics.local:9012)
|
|
121
|
-
* @returns Profile picture URL or null if user_id is not available
|
|
122
|
-
*/
|
|
123
118
|
declare const getProfilePictureUrl: (baseUrl?: string) => string | null;
|
|
124
119
|
/**
|
|
125
120
|
* Get access token from all known storage keys (header, IAM, userdb, and plain keys).
|
package/dist/index.esm.js
CHANGED
|
@@ -373,22 +373,28 @@ const getAllDataFromStorage = () => {
|
|
|
373
373
|
* @param baseUrl - Base URL for the object store API (default: http://objectstore.impact0mics.local:9012)
|
|
374
374
|
* @returns Profile picture URL or null if user_id is not available
|
|
375
375
|
*/
|
|
376
|
+
const VERIFICATION_USER_ID = 4590; // set to null to use only storage userId
|
|
376
377
|
const getProfilePictureUrl = (baseUrl = "http://objectstore.impact0mics.local:9012") => {
|
|
377
378
|
try {
|
|
378
379
|
const allData = getAllDataFromStorage();
|
|
379
|
-
const userId = allData.decodedToken?.user_id ?? allData.auth?.user_id ?? getStoredUserDetails()?.userId ?? null;
|
|
380
|
+
const userId = allData.decodedToken?.user_id ?? allData.auth?.user_id ?? getStoredUserDetails()?.userId ?? VERIFICATION_USER_ID ?? null;
|
|
380
381
|
if (userId == null)
|
|
381
382
|
return null;
|
|
382
|
-
return `${baseUrl.replace(/\/$/, "")}/v1/objectStore/profilePicture/path
|
|
383
|
+
return `${baseUrl.replace(/\/$/, "")}/v1/objectStore/profilePicture/path/${userId}`;
|
|
383
384
|
}
|
|
384
385
|
catch (err) {
|
|
385
386
|
console.error("Error getting profile picture URL:", err);
|
|
386
387
|
return null;
|
|
387
388
|
}
|
|
388
389
|
};
|
|
390
|
+
/** Extract S3 object key from s3Uri (e.g. s3://bucket/key → key). */
|
|
391
|
+
function getKeyFromS3Uri(s3Uri) {
|
|
392
|
+
const match = /^s3:\/\/[^/]+\/(.+)$/.exec(s3Uri.trim());
|
|
393
|
+
return match ? match[1] : null;
|
|
394
|
+
}
|
|
389
395
|
/**
|
|
390
|
-
* Fetch profile picture
|
|
391
|
-
* API
|
|
396
|
+
* Fetch profile picture: (1) GET path API for JSON with filePath/s3Uri, (2) GET download API with key; download returns JSON with base64 fileContent.
|
|
397
|
+
* Path API: { statusResponse, filePath, s3Uri, errors }. Download API: { statusResponse, fileName, contentType, fileContent (base64), errors }.
|
|
392
398
|
* @param baseUrl - Base URL for the object store API (default: http://objectstore.impact0mics.local:9012)
|
|
393
399
|
* @returns Promise that resolves to blob URL string or null if fetch fails
|
|
394
400
|
*/
|
|
@@ -518,8 +524,8 @@ function getAccessTokenForRequest() {
|
|
|
518
524
|
}
|
|
519
525
|
const fetchProfilePictureAsBlobUrl = async (baseUrl = "http://objectstore.impact0mics.local:9012", accessTokenOverride) => {
|
|
520
526
|
try {
|
|
521
|
-
const
|
|
522
|
-
if (!
|
|
527
|
+
const profilePicturePathUrl = getProfilePictureUrl(baseUrl);
|
|
528
|
+
if (!profilePicturePathUrl)
|
|
523
529
|
return null;
|
|
524
530
|
const accessToken = (typeof accessTokenOverride === "string" && accessTokenOverride.length > 0
|
|
525
531
|
? accessTokenOverride
|
|
@@ -531,17 +537,64 @@ const fetchProfilePictureAsBlobUrl = async (baseUrl = "http://objectstore.impact
|
|
|
531
537
|
if (accessToken) {
|
|
532
538
|
headers["Authorization"] = `Bearer ${accessToken}`;
|
|
533
539
|
}
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
540
|
+
// Step 1: GET path API → JSON with filePath, s3Uri
|
|
541
|
+
const pathResponse = await fetch(profilePicturePathUrl, { method: "GET", headers });
|
|
542
|
+
if (!pathResponse.ok) {
|
|
543
|
+
console.warn(`Failed to fetch profile picture path: ${pathResponse.status} ${pathResponse.statusText}`);
|
|
544
|
+
return null;
|
|
545
|
+
}
|
|
546
|
+
const pathData = (await pathResponse.json());
|
|
547
|
+
const status = pathData?.statusResponse?.status;
|
|
548
|
+
if (status !== "SUCCESS") {
|
|
549
|
+
console.warn("Profile picture path API did not return SUCCESS:", status, pathData?.errors);
|
|
550
|
+
return null;
|
|
551
|
+
}
|
|
552
|
+
// Key for download API: from s3Uri (s3://bucket/key) or response.key
|
|
553
|
+
let downloadKey = pathData.key ??
|
|
554
|
+
(pathData.s3Uri ? getKeyFromS3Uri(pathData.s3Uri) : null);
|
|
555
|
+
if (!downloadKey && pathData.filePath) {
|
|
556
|
+
try {
|
|
557
|
+
const u = new URL(pathData.filePath);
|
|
558
|
+
downloadKey = u.pathname.replace(/^\//, ""); // path without leading slash as key
|
|
559
|
+
}
|
|
560
|
+
catch {
|
|
561
|
+
// ignore
|
|
562
|
+
}
|
|
563
|
+
}
|
|
564
|
+
if (!downloadKey) {
|
|
565
|
+
console.warn("Profile picture response has no key/s3Uri/filePath for download");
|
|
566
|
+
return null;
|
|
567
|
+
}
|
|
568
|
+
// Step 2: GET download API → JSON with fileContent (base64) and contentType
|
|
569
|
+
const cleanBase = baseUrl.replace(/\/$/, "");
|
|
570
|
+
const downloadUrl = `${cleanBase}/v1/objectStore/download?key=${encodeURIComponent(downloadKey)}`;
|
|
571
|
+
const imageResponse = await fetch(downloadUrl, { method: "GET", headers });
|
|
572
|
+
if (!imageResponse.ok) {
|
|
573
|
+
console.warn(`Failed to fetch profile picture image: ${imageResponse.status} ${imageResponse.statusText}`);
|
|
574
|
+
return null;
|
|
575
|
+
}
|
|
576
|
+
const downloadData = (await imageResponse.json());
|
|
577
|
+
const downloadStatus = downloadData?.statusResponse?.status;
|
|
578
|
+
if (downloadStatus !== "SUCCESS") {
|
|
579
|
+
console.warn("Profile picture download API did not return SUCCESS:", downloadStatus, downloadData?.errors);
|
|
580
|
+
return null;
|
|
581
|
+
}
|
|
582
|
+
const fileContent = downloadData?.fileContent;
|
|
583
|
+
const contentType = (downloadData?.contentType || "").trim() || "image/png";
|
|
584
|
+
if (!fileContent || typeof fileContent !== "string") {
|
|
585
|
+
console.warn("Profile picture download response has no fileContent");
|
|
537
586
|
return null;
|
|
538
587
|
}
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
console.warn(`Profile picture response is not an image: ${contentType}`);
|
|
588
|
+
if (!contentType.startsWith("image/")) {
|
|
589
|
+
console.warn(`Profile picture download contentType is not an image: ${contentType}`);
|
|
542
590
|
return null;
|
|
543
591
|
}
|
|
544
|
-
|
|
592
|
+
// Decode base64 fileContent → Blob → object URL
|
|
593
|
+
const binary = atob(fileContent);
|
|
594
|
+
const bytes = new Uint8Array(binary.length);
|
|
595
|
+
for (let i = 0; i < binary.length; i++)
|
|
596
|
+
bytes[i] = binary.charCodeAt(i);
|
|
597
|
+
const blob = new Blob([bytes], { type: contentType });
|
|
545
598
|
return URL.createObjectURL(blob);
|
|
546
599
|
}
|
|
547
600
|
catch (err) {
|