mirror of
https://github.com/filebrowser/filebrowser.git
synced 2025-06-16 22:32:59 +00:00

--------- Co-authored-by: Joep <jcbuhre@gmail.com> Co-authored-by: Omar Hussein <omarmohammad1951@gmail.com> Co-authored-by: Oleg Lobanov <oleg@lobanov.me>
28 lines
567 B
TypeScript
28 lines
567 B
TypeScript
import { fetchURL, removePrefix } from "./utils";
|
|
import url from "../utils/url";
|
|
|
|
export default async function search(base: string, query: string) {
|
|
base = removePrefix(base);
|
|
query = encodeURIComponent(query);
|
|
|
|
if (!base.endsWith("/")) {
|
|
base += "/";
|
|
}
|
|
|
|
const res = await fetchURL(`/api/search${base}?query=${query}`, {});
|
|
|
|
let data = await res.json();
|
|
|
|
data = data.map((item: UploadItem) => {
|
|
item.url = `/files${base}` + url.encodePath(item.path);
|
|
|
|
if (item.dir) {
|
|
item.url += "/";
|
|
}
|
|
|
|
return item;
|
|
});
|
|
|
|
return data;
|
|
}
|