nosdav / pastebin

NosDAV pastebin
https://nosdav.github.io/pastebin/
MIT License
8 stars 1 forks source link

Support absolute URLs for slug parameter in NosDAV Pastebin #5

Closed melvincarvalho closed 1 year ago

melvincarvalho commented 1 year ago

Description:

Currently, the NosDAV Pastebin does not handle absolute URLs as the slug parameter correctly. This change adds the functionality to support absolute URLs in the slug parameter by updating the getPath function.

 function getPath(serverUrl, userPublicKey, filename, mode) {
+  if (isAbsoluteUrl(filename)) {
+    return filename;
+  }
+
   if (mode !== 'm') {
     return `${serverUrl}/${filename}`;
   } else {
     return `${serverUrl}/${userPublicKey}/${filename}`;
   }
 }

+function isAbsoluteUrl(url) {
+  try {
+    new URL(url);
+    return true;
+  } catch (e) {
+    return false;
+  }
+}

This update will enable users to load and save files using absolute URLs, which will increase the flexibility of the application. Please consider merging this change into the main codebase.