mirror of
https://github.com/labring/FastGPT.git
synced 2025-07-23 05:12:39 +00:00
Optimize the file storage structure of the knowledge base (#386)
This commit is contained in:
23
packages/common/tools/file.ts
Normal file
23
packages/common/tools/file.ts
Normal file
@@ -0,0 +1,23 @@
|
||||
import { strIsLink } from './str';
|
||||
|
||||
export const fileImgs = [
|
||||
{ suffix: 'pdf', src: '/imgs/files/pdf.svg' },
|
||||
{ suffix: 'csv', src: '/imgs/files/csv.svg' },
|
||||
{ suffix: '(doc|docs)', src: '/imgs/files/doc.svg' },
|
||||
{ suffix: 'txt', src: '/imgs/files/txt.svg' },
|
||||
{ suffix: 'md', src: '/imgs/files/markdown.svg' },
|
||||
{ suffix: '.', src: '/imgs/files/file.svg' }
|
||||
];
|
||||
|
||||
export function getFileIcon(name = '') {
|
||||
return fileImgs.find((item) => new RegExp(item.suffix, 'gi').test(name))?.src;
|
||||
}
|
||||
export function getSpecialFileIcon(name = '') {
|
||||
if (name === 'manual') {
|
||||
return '/imgs/files/manual.svg';
|
||||
} else if (name === 'mark') {
|
||||
return '/imgs/files/mark.svg';
|
||||
} else if (strIsLink(name)) {
|
||||
return '/imgs/files/link.svg';
|
||||
}
|
||||
}
|
5
packages/common/tools/str.ts
Normal file
5
packages/common/tools/str.ts
Normal file
@@ -0,0 +1,5 @@
|
||||
export function strIsLink(str?: string) {
|
||||
if (!str) return false;
|
||||
if (/^((http|https)?:\/\/|www\.|\/)[^\s/$.?#].[^\s]*$/i.test(str)) return true;
|
||||
return false;
|
||||
}
|
Reference in New Issue
Block a user