fix: better null domain fallback logic

This commit is contained in:
Bobby Wibowo 2022-06-22 11:22:35 +07:00
parent 4488f9ae8a
commit 954df13aa2
No known key found for this signature in database
GPG Key ID: 51C3A1E1E22D26CF
3 changed files with 9 additions and 5 deletions

View File

@ -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

View File

@ -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)

View File

@ -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')