mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-07 20:31:06 -05:00
7c00b2d838
Revert "Add support for data urls and snip arrays to Open-in-Overleaf" GitOrigin-RevId: c1e3806686764553d8801517b913f9133642fdb2
32 lines
872 B
JavaScript
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
|