Move URL building into one function.

This commit is contained in:
Nils Asmussen 2016-08-21 15:12:32 +02:00
parent 95c99948d7
commit 3c4b1911fd
3 changed files with 26 additions and 27 deletions

View File

@ -627,18 +627,12 @@ album.share = function(service) {
album.getArchive = function(albumIDs) {
let link = ''
let url = `${ api.path }?function=Album::getArchive&albumIDs=${ albumIDs.join(',') }`
let path = `${ api.path }?function=Album::getArchive&albumIDs=${ albumIDs.join(',') }`
let url = lychee.getURL(path)
var pos = location.href.indexOf('#')
link = pos!=-1 ? location.href.substring(0, pos) : location.href
if (lychee.publicMode===true) url += `&password=${ encodeURIComponent(password.value) }`
if (location.href.indexOf('index.html')>0) link = link.replace('index.html', url)
else link += url
if (lychee.publicMode===true) link += `&password=${ encodeURIComponent(password.value) }`
location.href = link
location.href = url
}

View File

@ -417,6 +417,18 @@ lychee.html = function(literalSections, ...substs) {
}
lychee.getURL = function(path) {
let pos = location.href.indexOf('#')
let url = pos!=-1 ? location.href.substring(0, pos) : location.href
if (location.href.indexOf('index.html')>0) url = url.replace('index.html', path)
else url += path
return url
}
lychee.error = function(errorThrown, params, data) {
console.error({

View File

@ -635,29 +635,23 @@ photo.share = function(photoID, service) {
photo.getPhoto = function(photoID) {
let link
let url = `${ api.path }?function=Photo::getPhoto&photoID=${ photoID }`
let path = `${ api.path }?function=Photo::getPhoto&photoID=${ photoID }`
let url = lychee.getURL(path)
if (location.href.indexOf('index.html')>0) link = location.href.replace(location.hash, '').replace('index.html', url)
else link = location.href.replace(location.hash, '') + url
if (lychee.publicMode===true) url += `&password=${ encodeURIComponent(password.value) }`
if (lychee.publicMode===true) link += `&password=${ encodeURIComponent(password.value) }`
location.href = link
location.href = url
}
photo.getArchive = function(photoIDs) {
let link
let url = `${ api.path }?function=Photo::getArchive&photoIDs=${ photoIDs.join(',') }`
let path = `${ api.path }?function=Photo::getArchive&photoIDs=${ photoIDs.join(',') }`
let url = lychee.getURL(path)
if (location.href.indexOf('index.html')>0) link = location.href.replace(location.hash, '').replace('index.html', url)
else link = location.href.replace(location.hash, '') + url
if (lychee.publicMode===true) url += `&password=${ encodeURIComponent(password.value) }`
if (lychee.publicMode===true) link += `&password=${ encodeURIComponent(password.value) }`
location.href = link
location.href = url
}
@ -673,9 +667,8 @@ photo.getDirectLink = function() {
photo.getViewLink = function(photoID) {
let url = 'view.php?p=' + photoID
let path = 'view.php?p=' + photoID
if (location.href.indexOf('index.html')>0) return location.href.replace('index.html' + location.hash, url)
else return location.href.replace(location.hash, url)
return lychee.getURL(path)
}