mirror of https://github.com/status-im/codimd.git
fix: unwrap the geo div and throw error when input
location search not found also fix the CSP rule that the img with data src might be violated Signed-off-by: Yukai Huang <yukaihuangtw@gmail.com> Co-authored-by: Max Wu <jackymaxj@gmail.com>
This commit is contained in:
parent
8a05276339
commit
1a000226b0
|
@ -7,7 +7,7 @@ var defaultDirectives = {
|
||||||
defaultSrc: ['\'self\''],
|
defaultSrc: ['\'self\''],
|
||||||
scriptSrc: ['\'self\'', 'vimeo.com', 'https://gist.github.com', 'www.slideshare.net', 'https://query.yahooapis.com', '\'unsafe-eval\''],
|
scriptSrc: ['\'self\'', 'vimeo.com', 'https://gist.github.com', 'www.slideshare.net', 'https://query.yahooapis.com', '\'unsafe-eval\''],
|
||||||
// ^ TODO: Remove unsafe-eval - webpack script-loader issues https://github.com/hackmdio/codimd/issues/594
|
// ^ TODO: Remove unsafe-eval - webpack script-loader issues https://github.com/hackmdio/codimd/issues/594
|
||||||
imgSrc: ['*'],
|
imgSrc: ['*', 'data:'],
|
||||||
styleSrc: ['\'self\'', '\'unsafe-inline\'', 'https://github.githubassets.com'], // unsafe-inline is required for some libs, plus used in views
|
styleSrc: ['\'self\'', '\'unsafe-inline\'', 'https://github.githubassets.com'], // unsafe-inline is required for some libs, plus used in views
|
||||||
fontSrc: ['\'self\'', 'data:', 'https://public.slidesharecdn.com'],
|
fontSrc: ['\'self\'', 'data:', 'https://public.slidesharecdn.com'],
|
||||||
objectSrc: ['*'], // Chrome PDF viewer treats PDFs as objects :/
|
objectSrc: ['*'], // Chrome PDF viewer treats PDFs as objects :/
|
||||||
|
|
|
@ -453,10 +453,13 @@ export function finishView (view) {
|
||||||
console.warn(err)
|
console.warn(err)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
// geo map
|
||||||
view.find('div.geo.raw').removeClass('raw').each(async function (key, value) {
|
view.find('div.geo.raw').removeClass('raw').each(async function (key, value) {
|
||||||
const $elem = $(value).parent().parent()
|
const $elem = $(value).parent().parent()
|
||||||
const $value = $(value)
|
const $value = $(value)
|
||||||
const content = $value.text()
|
const content = $value.text()
|
||||||
|
$value.unwrap()
|
||||||
|
|
||||||
try {
|
try {
|
||||||
let position, zoom
|
let position, zoom
|
||||||
if (content.match(/^[\d.,\s]+$/)) {
|
if (content.match(/^[\d.,\s]+$/)) {
|
||||||
|
@ -466,6 +469,9 @@ export function finishView (view) {
|
||||||
} else {
|
} else {
|
||||||
// parse value as address
|
// parse value as address
|
||||||
const data = await fetch(`https://nominatim.openstreetmap.org/search?q=${encodeURIComponent(content)}&format=json`).then(r => r.json())
|
const data = await fetch(`https://nominatim.openstreetmap.org/search?q=${encodeURIComponent(content)}&format=json`).then(r => r.json())
|
||||||
|
if (!data || !data.length) {
|
||||||
|
throw new Error('Location not found')
|
||||||
|
}
|
||||||
const { lat, lon } = data[0]
|
const { lat, lon } = data[0]
|
||||||
position = [lat, lon]
|
position = [lat, lon]
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue