overleaf/services/web/app/src/Features/Helpers/UrlHelper.js
Simon Detheridge 7c00b2d838 Merge pull request #2772 from overleaf/revert-2767-spd-oio-moreurls
Revert "Add support for data urls and snip arrays to Open-in-Overleaf"

GitOrigin-RevId: c1e3806686764553d8801517b913f9133642fdb2
2020-04-25 03:19:03 +00:00

32 lines
872 B
JavaScript

const Settings = require('settings-sharelatex')
const { URL } = require('url')
function getSafeRedirectPath(value) {
const baseURL = Settings.siteUrl // base URL is required to construct URL from path
const url = new URL(value, baseURL)
let safePath = `${url.pathname}${url.search}${url.hash}`.replace(/^\/+/, '/')
if (safePath === '/') {
safePath = undefined
}
return safePath
}
const UrlHelper = {
getSafeRedirectPath,
wrapUrlWithProxy(url) {
// TODO: Consider what to do for Community and Enterprise edition?
if (!Settings.apis.linkedUrlProxy.url) {
throw new Error('no linked url proxy configured')
}
return `${Settings.apis.linkedUrlProxy.url}?url=${encodeURIComponent(url)}`
},
prependHttpIfNeeded(url) {
if (!url.match('://')) {
url = `http://${url}`
}
return url
}
}
module.exports = UrlHelper