mirror of
https://github.com/darksaid98/new-phone-who-dis.git
synced 2026-12-04 14:38:45 +00:00
tweak(phone/utils): Moved isImageValid util to common dir
This commit is contained in:
1 parent
18c1676c01
commit
41b50d6429
3 files changed
+18
-18
No files matched your search
@@ -4,7 +4,8 @@ import { v4 as uuidv4 } from 'uuid';
|
|||||||
|
|
||||||
import Nui from '../../../os/nui-events/utils/Nui';
|
import Nui from '../../../os/nui-events/utils/Nui';
|
||||||
import Modal from '../../../ui/components/Modal';
|
import Modal from '../../../ui/components/Modal';
|
||||||
import { IMAGE_DELIMITER, isImageValid } from '../utils/images';
|
import { IMAGE_DELIMITER } from '../utils/images';
|
||||||
|
import { isImageValid } from '../../../common/utils/isImageValid';
|
||||||
import { useModal } from '../hooks/useModal';
|
import { useModal } from '../hooks/useModal';
|
||||||
import EmojiSelect from './EmojiSelect';
|
import EmojiSelect from './EmojiSelect';
|
||||||
import ImageDisplay from './images/ImageDisplay';
|
import ImageDisplay from './images/ImageDisplay';
|
||||||
|
|||||||
@@ -4,20 +4,3 @@
|
|||||||
// within specification). To get around this we have our own delimiter
|
// within specification). To get around this we have our own delimiter
|
||||||
// here we'll use to join and split these strings
|
// here we'll use to join and split these strings
|
||||||
export const IMAGE_DELIMITER = '||!||';
|
export const IMAGE_DELIMITER = '||!||';
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns a Promise that validates that the URL successfully
|
|
||||||
* loads in the browser. If the URL doesn't load the promise is
|
|
||||||
* rejected.
|
|
||||||
* @param {string} link - a URL we are trying to validate
|
|
||||||
* @returns {Promise<string>} link - Will resolve the promise with the link string
|
|
||||||
* if valid. Will reject if failed.
|
|
||||||
*/
|
|
||||||
export function isImageValid(link: string): Promise<string> {
|
|
||||||
return new Promise((res, rej) => {
|
|
||||||
const image = new Image();
|
|
||||||
image.src = link;
|
|
||||||
image.onerror = () => rej(`Invalid image, ${link}`);
|
|
||||||
image.onload = () => res(link);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
/**
|
||||||
|
* Returns a Promise that validates that the URL successfully
|
||||||
|
* loads in the browser. If the URL doesn't load the promise is
|
||||||
|
* rejected.
|
||||||
|
* @param {string} link - a URL we are trying to validate
|
||||||
|
* @returns {Promise<string>} link - Will resolve the promise with the link string
|
||||||
|
* if valid. Will reject if failed.
|
||||||
|
*/
|
||||||
|
export function isImageValid(link: string): Promise<string> {
|
||||||
|
return new Promise((res, rej) => {
|
||||||
|
const image = new Image();
|
||||||
|
image.src = link;
|
||||||
|
image.onerror = () => rej(`Invalid image, ${link}`);
|
||||||
|
image.onload = () => res(link);
|
||||||
|
});
|
||||||
|
}
|
||||||
Reference in new issue
Block a user