1
0
Fork 0
mirror of https://github.com/pawelmalak/flame.git synced 2025-07-21 04:19:37 +02:00

Fetch and use custom search queries

This commit is contained in:
unknown 2021-10-06 14:15:05 +02:00
parent da928f20a2
commit 591824dd0c
9 changed files with 136 additions and 80 deletions

View file

@ -1,6 +1,6 @@
import { queries } from './searchQueries.json';
import { Query, SearchResult } from '../interfaces';
import { store } from '../store/store';
import { searchConfig } from '.';
export const searchParser = (searchQuery: string): SearchResult => {
@ -16,6 +16,8 @@ export const searchParser = (searchQuery: string): SearchResult => {
},
};
const customQueries = store.getState().config.customQueries;
// Check if url or ip was passed
const urlRegex =
/^(http:\/\/www\.|https:\/\/www\.|http:\/\/|https:\/\/)?[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,5}(:[0-9]{1,5})?(\/.*)?|^((http:\/\/www\.|https:\/\/www\.|http:\/\/|https:\/\/)?([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$/;
@ -33,7 +35,9 @@ export const searchParser = (searchQuery: string): SearchResult => {
? encodeURIComponent(splitQuery[2])
: encodeURIComponent(searchQuery);
const query = queries.find((q: Query) => q.prefix === prefix);
const query = [...queries, ...customQueries].find(
(q: Query) => q.prefix === prefix
);
// If search provider was found
if (query) {