Skip to content

Commit d29740e

Browse files
committed
Fix missing utility functions import after blossomUpload.ts removal
- Move isValidUrl and isImageUrl functions from deleted blossomUpload.ts to utils.ts - Update IconUpload component to import from utils instead of blossomUpload - Resolves compile error about missing blossomUpload module
1 parent 971240e commit d29740e

2 files changed

Lines changed: 25 additions & 1 deletion

File tree

src/components/common/IconUpload.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React, { useState, useRef, useEffect } from 'react';
22
import { Input, Upload, Button, message, Tabs, Avatar } from 'antd';
33
import { UploadOutlined, LinkOutlined, LoadingOutlined } from '@ant-design/icons';
4-
import { isValidUrl, isImageUrl } from '@app/utils/blossomUpload';
4+
import { isValidUrl, isImageUrl } from '@app/utils/utils';
55
import { readToken } from '@app/services/localStorage.service';
66
import config from '@app/config/config';
77
import type { RcFile } from 'antd/es/upload/interface';

src/utils/utils.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,3 +214,27 @@ export const mapBadgeStatus = (status: BaseBadgeProps['status']): Severity => {
214214

215215
return status;
216216
};
217+
218+
/**
219+
* Validate if a string is a valid URL
220+
*/
221+
export const isValidUrl = (urlString: string): boolean => {
222+
try {
223+
new URL(urlString);
224+
return true;
225+
} catch {
226+
return false;
227+
}
228+
};
229+
230+
/**
231+
* Validate if a URL points to an image
232+
*/
233+
export const isImageUrl = (url: string): boolean => {
234+
if (!isValidUrl(url)) return false;
235+
236+
const imageExtensions = ['.jpg', '.jpeg', '.png', '.gif', '.webp', '.svg'];
237+
const urlPath = new URL(url).pathname.toLowerCase();
238+
239+
return imageExtensions.some(ext => urlPath.endsWith(ext));
240+
};

0 commit comments

Comments
 (0)