mirror of
https://github.com/pipipi-pikachu/PPTist.git
synced 2025-04-15 02:20:00 +08:00
fix: 限制粘贴图片地址来源
This commit is contained in:
parent
4d9471e582
commit
b7ad7644cc
@ -3,7 +3,7 @@ import { useKeyboardStore } from '@/store'
|
|||||||
import { pasteCustomClipboardString } from '@/utils/clipboard'
|
import { pasteCustomClipboardString } from '@/utils/clipboard'
|
||||||
import { parseText2Paragraphs } from '@/utils/textParser'
|
import { parseText2Paragraphs } from '@/utils/textParser'
|
||||||
import { getImageDataURL, isSVGString, svg2File } from '@/utils/image'
|
import { getImageDataURL, isSVGString, svg2File } from '@/utils/image'
|
||||||
import { isValidImgURL, isValidURL } from '@/utils/common'
|
import { isValidURL } from '@/utils/common'
|
||||||
import useCreateElement from '@/hooks/useCreateElement'
|
import useCreateElement from '@/hooks/useCreateElement'
|
||||||
import useAddSlidesOrElements from '@/hooks/useAddSlidesOrElements'
|
import useAddSlidesOrElements from '@/hooks/useAddSlidesOrElements'
|
||||||
|
|
||||||
@ -12,6 +12,16 @@ interface PasteTextClipboardDataOptions {
|
|||||||
onlyElements?: boolean
|
onlyElements?: boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 判断图片URL字符串
|
||||||
|
*
|
||||||
|
* !!!注意,你需要判断允许哪些来源的图片地址被匹配,然后自行编写正则表达式
|
||||||
|
* !!!必须确保图片来源都是合法、可靠、可控、无访问限制的
|
||||||
|
*/
|
||||||
|
const isValidImgURL = (url: string) => {
|
||||||
|
return /^https:\/\/pptist.cn(\/[\w-./?%&=]*)?\.(jpg|jpeg|png|svg|webp)(\?.*)?$/i.test(url)
|
||||||
|
}
|
||||||
|
|
||||||
export default () => {
|
export default () => {
|
||||||
const { shiftKeyState } = storeToRefs(useKeyboardStore())
|
const { shiftKeyState } = storeToRefs(useKeyboardStore())
|
||||||
|
|
||||||
|
@ -22,10 +22,3 @@ export const isPC = () => {
|
|||||||
export const isValidURL = (url: string) => {
|
export const isValidURL = (url: string) => {
|
||||||
return /^(https?:\/\/)([\w-]+\.)+[\w-]{2,}(\/[\w-./?%&=]*)?$/i.test(url)
|
return /^(https?:\/\/)([\w-]+\.)+[\w-]{2,}(\/[\w-./?%&=]*)?$/i.test(url)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 判断图片URL字符串
|
|
||||||
*/
|
|
||||||
export const isValidImgURL = (url: string) => {
|
|
||||||
return /^(https?:\/\/)([\w-]+\.)+[\w-]{2,}(\/[\w-./?%&=]*)?\.(jpg|jpeg|png|svg|webp)(\?.*)?$/i.test(url)
|
|
||||||
}
|
|
Loading…
x
Reference in New Issue
Block a user