From 954df13aa2893530782bf5c29d4d832097122589 Mon Sep 17 00:00:00 2001 From: Bobby Wibowo Date: Wed, 22 Jun 2022 11:22:35 +0700 Subject: [PATCH] fix: better null domain fallback logic --- controllers/uploadController.js | 2 +- src/js/dashboard.js | 6 +++--- src/js/home.js | 6 +++++- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/controllers/uploadController.js b/controllers/uploadController.js index 1799f22..978b968 100644 --- a/controllers/uploadController.js +++ b/controllers/uploadController.js @@ -938,7 +938,7 @@ self.sendUploadResponse = async (req, res, user, result) => { files: result.map(file => { const map = { name: file.name, - url: `${config.domain}/${file.name}` + url: `${config.domain ? `${config.domain}/` : ''}${file.name}` } // If a temporary upload, add expiry date diff --git a/src/js/dashboard.js b/src/js/dashboard.js index d03130a..22b2deb 100644 --- a/src/js/dashboard.js +++ b/src/js/dashboard.js @@ -678,9 +678,9 @@ page.getUploads = (params = {}) => { for (let i = 0; i < files.length; i++) { // Build full URLs - files[i].file = `${basedomain}/${files[i].name}` + files[i].file = `${basedomain || window.location.origin}/${files[i].name}` if (files[i].thumb) { - files[i].thumb = `${basedomain}/${files[i].thumb}` + files[i].thumb = `${basedomain ? `${basedomain}/` : ''}${files[i].thumb}` } // Determine types @@ -1621,7 +1621,7 @@ page.getAlbums = (params = {}) => { page.cache = {} const users = response.data.users - const homeDomain = response.data.homeDomain + const homeDomain = response.data.homeDomain || window.location.origin if (params.pageNum < 0) params.pageNum = Math.max(0, pages + params.pageNum) const pagination = page.paginate(response.data.count, 25, params.pageNum) diff --git a/src/js/home.js b/src/js/home.js index 359b00c..50a63a4 100644 --- a/src/js/home.js +++ b/src/js/home.js @@ -692,7 +692,11 @@ page.updateTemplate = (file, response) => { const link = file.previewElement.querySelector('.link') const a = link.querySelector('a') const clipboard = file.previewElement.querySelector('.clipboard-mobile > .clipboard-js') - a.href = a.innerHTML = clipboard.dataset.clipboardText = response.url + let url = response.url + if (!/^https?:\/\//i.test(url)) { + url = `${window.location.origin}/${url}` + } + a.href = a.innerHTML = clipboard.dataset.clipboardText = url link.classList.remove('is-hidden') clipboard.parentElement.classList.remove('is-hidden')