about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorbptato <nincsnevem662@gmail.com>2024-06-08 23:30:03 +0200
committerbptato <nincsnevem662@gmail.com>2024-06-08 23:30:03 +0200
commit5df9ef4c810a1f1975f6e140f4c97aa602d37724 (patch)
tree2d85634809a464d0199dc0e1ba23b106ad0b7c4c
parent8776e58beb524ff26c171e0b8765aefcfd56fcc9 (diff)
downloadchawan-5df9ef4c810a1f1975f6e140f4c97aa602d37724.tar.gz
pager: send Accept: */* for viewImage
-rw-r--r--res/config.toml9
-rw-r--r--src/local/pager.nim9
2 files changed, 15 insertions, 3 deletions
diff --git a/res/config.toml b/res/config.toml
index 48eb0e64..ea3fcff5 100644
--- a/res/config.toml
+++ b/res/config.toml
@@ -124,7 +124,14 @@ scrollUp = 'n => pager.scrollUp(n)'
 scrollLeft = 'n => pager.scrollLeft(n)'
 scrollRight = 'n => pager.scrollRight(n)'
 click = '() => pager.click()'
-viewImage = '() => pager.gotoURL(pager.hoverImage)'
+viewImage = '''
+() => {
+	if (pager.hoverImage) {
+		const headers = new Headers({Accept: "*/*"});
+		pager.gotoURL(new Request(pager.hoverImage, {headers: headers}));
+	}
+}
+'''
 toggleImages = '() => pager.toggleImages()'
 markURL = '() => pager.markURL()'
 redraw = '() => pager.redraw()'
diff --git a/src/local/pager.nim b/src/local/pager.nim
index 16cd20a0..8076020f 100644
--- a/src/local/pager.nim
+++ b/src/local/pager.nim
@@ -1302,8 +1302,13 @@ proc load(pager: Pager; s = "") {.jsfunc.} =
     pager.setLineEdit(lmLocation, s)
 
 # Go to specific URL (for JS)
-proc jsGotoURL(pager: Pager; s: string): JSResult[void] {.jsfunc: "gotoURL".} =
-  pager.gotoURL(newRequest(?newURL(s)))
+proc jsGotoURL(pager: Pager; v: JSValue): JSResult[void] {.jsfunc: "gotoURL".} =
+  let req = fromJS[JSRequest](pager.jsctx, v)
+  if req.isSome:
+    pager.gotoURL(req.get.request)
+  else:
+    let s = ?fromJS[string](pager.jsctx, v)
+    pager.gotoURL(newRequest(?newURL(s)))
   ok()
 
 # Reload the page in a new buffer, then kill the previous buffer.