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.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/4590`;
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 from object store API (plain GET with Authorization header).
411
- * API returns the image directly; response is converted to a blob URL for use in img src.
416
+ * Fetch profile picture: (1) GET path API for JSON with filePath/s3Uri, (2) GET download API with key; download returns JSON with base64 fileContent.
417
+ * Path API: { statusResponse, filePath, s3Uri, errors }. Download API: { statusResponse, fileName, contentType, fileContent (base64), errors }.
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,8 +544,8 @@ function getAccessTokenForRequest() {
538
544
  }
539
545
  const fetchProfilePictureAsBlobUrl = async (baseUrl = "http://objectstore.impact0mics.local:9012", accessTokenOverride) => {
540
546
  try {
541
- const profilePictureUrl = getProfilePictureUrl(baseUrl);
542
- if (!profilePictureUrl)
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
@@ -551,17 +557,64 @@ const fetchProfilePictureAsBlobUrl = async (baseUrl = "http://objectstore.impact
551
557
  if (accessToken) {
552
558
  headers["Authorization"] = `Bearer ${accessToken}`;
553
559
  }
554
- const response = await fetch(profilePictureUrl, { method: "GET", headers });
555
- if (!response.ok) {
556
- console.warn(`Failed to fetch profile picture: ${response.status} ${response.statusText}`);
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 → JSON with fileContent (base64) and contentType
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}`);
594
+ return null;
595
+ }
596
+ const downloadData = (await imageResponse.json());
597
+ const downloadStatus = downloadData?.statusResponse?.status;
598
+ if (downloadStatus !== "SUCCESS") {
599
+ console.warn("Profile picture download API did not return SUCCESS:", downloadStatus, downloadData?.errors);
600
+ return null;
601
+ }
602
+ const fileContent = downloadData?.fileContent;
603
+ const contentType = (downloadData?.contentType || "").trim() || "image/png";
604
+ if (!fileContent || typeof fileContent !== "string") {
605
+ console.warn("Profile picture download response has no fileContent");
557
606
  return null;
558
607
  }
559
- const contentType = response.headers.get("content-type");
560
- if (!contentType || !contentType.startsWith("image/")) {
561
- console.warn(`Profile picture response is not an image: ${contentType}`);
608
+ if (!contentType.startsWith("image/")) {
609
+ console.warn(`Profile picture download contentType is not an image: ${contentType}`);
562
610
  return null;
563
611
  }
564
- const blob = await response.blob();
612
+ // Decode base64 fileContent → Blob → object URL
613
+ const binary = atob(fileContent);
614
+ const bytes = new Uint8Array(binary.length);
615
+ for (let i = 0; i < binary.length; i++)
616
+ bytes[i] = binary.charCodeAt(i);
617
+ const blob = new Blob([bytes], { type: contentType });
565
618
  return URL.createObjectURL(blob);
566
619
  }
567
620
  catch (err) {