|
|
@@ -29,8 +29,8 @@ import { LogseqContext, LogseqContextValue } from '../lib/logseq-context'
|
|
|
|
|
|
const isValidURL = (url: string) => {
|
|
|
try {
|
|
|
- new URL(url)
|
|
|
- return true
|
|
|
+ const parsedUrl = new URL(url)
|
|
|
+ return parsedUrl.host && ['http:', 'https:'].includes(parsedUrl.protocol)
|
|
|
} catch {
|
|
|
return false
|
|
|
}
|
|
|
@@ -105,17 +105,17 @@ const handleCreatingShapes = async (
|
|
|
const existingAsset = Object.values(app.assets).find(asset => asset.src === url)
|
|
|
if (existingAsset) {
|
|
|
return existingAsset as VideoImageAsset
|
|
|
- } else {
|
|
|
- // Create a new asset for this image
|
|
|
- const asset: VideoImageAsset = {
|
|
|
- id: uniqueId(),
|
|
|
- type: isVideo ? 'video' : 'image',
|
|
|
- src: url,
|
|
|
- size: await getSizeFromSrc(handlers.makeAssetUrl(url), isVideo),
|
|
|
- }
|
|
|
- return asset
|
|
|
}
|
|
|
- }
|
|
|
+
|
|
|
+ // Create a new asset for this image
|
|
|
+ const asset: VideoImageAsset = {
|
|
|
+ id: uniqueId(),
|
|
|
+ type: isVideo ? 'video' : 'image',
|
|
|
+ src: url,
|
|
|
+ size: await getSizeFromSrc(handlers.makeAssetUrl(url), isVideo),
|
|
|
+ }
|
|
|
+ return asset
|
|
|
+}
|
|
|
|
|
|
async function createAssetsFromFiles(files: File[]) {
|
|
|
const tasks = files
|
|
|
@@ -272,7 +272,7 @@ const handleCreatingShapes = async (
|
|
|
}
|
|
|
|
|
|
async function tryCreateShapeFromURL(rawText: string) {
|
|
|
- if (isValidURL(rawText) && !(shiftKey || fromDrop)) {
|
|
|
+ if (isValidURL(rawText) && !shiftKey) {
|
|
|
if (YOUTUBE_REGEX.test(rawText)) {
|
|
|
return [
|
|
|
{
|
|
|
@@ -415,7 +415,7 @@ const handleCreatingShapes = async (
|
|
|
}
|
|
|
app.currentPage.updateBindings(Object.fromEntries(bindingsToCreate.map(b => [b.id, b])))
|
|
|
|
|
|
- if (app.selectedShapesArray.length === 1 && allShapesToAdd.length === 1 && !fromDrop) {
|
|
|
+ if (app.selectedShapesArray.length === 1 && allShapesToAdd.length === 1 && fromDrop) {
|
|
|
const source = app.selectedShapesArray[0]
|
|
|
const target = app.getShapeById(allShapesToAdd[0].id!)!
|
|
|
app.createNewLineBinding(source, target)
|