« get me outta code hell

img file size cleanup - hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
author(quasar) nebula <qznebula@protonmail.com>2023-03-02 00:50:12 -0400
committer(quasar) nebula <qznebula@protonmail.com>2023-03-02 00:50:12 -0400
commit7492f62461a79e9d45df5086de0f306f8e340adc (patch)
tree41852f08b944f81cab3e99e737c199061239d720 /src
parent842248934a300e2aa961b38854b8fbde5f104576 (diff)
img file size cleanup
was attempting to fix a bug with processing image file sizes
and the issue turned out to be being on the wrong media branch
THANKS
Diffstat (limited to 'src')
-rw-r--r--src/misc-templates.js23
1 files changed, 16 insertions, 7 deletions
diff --git a/src/misc-templates.js b/src/misc-templates.js
index e8c7496c..aa21a390 100644
--- a/src/misc-templates.js
+++ b/src/misc-templates.js
@@ -654,18 +654,27 @@ function unbound_img({
   lazy = false,
   square = false,
 }) {
-  let fileSize = null;
-  const mediaRoot = to('media.root');
-  if (src.startsWith(mediaRoot)) {
-    fileSize = getSizeOfImageFile(src.slice(mediaRoot.length).replace(/^\//, ''));
-  }
-
   const willSquare = square;
   const willLink = typeof link === 'string' || link;
 
   const originalSrc = src;
   const thumbSrc = src && (thumbKey ? thumb[thumbKey](src) : src);
 
+  const href =
+    (willLink
+      ? (typeof link === 'string'
+          ? link
+          : originalSrc)
+      : null);
+
+  let fileSize = null;
+  const mediaRoot = to('media.root');
+  if (href?.startsWith(mediaRoot)) {
+    console.log(href.slice(mediaRoot.length).replace(/^\//, ''));
+    console.log(getSizeOfImageFile(href.slice(mediaRoot.length).replace(/^\//, '')));
+    fileSize = getSizeOfImageFile(href.slice(mediaRoot.length).replace(/^\//, ''));
+  }
+
   const imgAttributes = {
     id: link ? '' : id,
     class: className,
@@ -734,7 +743,7 @@ function unbound_img({
         {
           id,
           class: ['box', hide && 'js-hide', 'image-link'],
-          href: typeof link === 'string' ? link : originalSrc,
+          href,
         },
         wrapped);
     }