mirror of
				https://github.com/mealie-recipes/mealie.git
				synced 2025-10-31 02:03:35 -04:00 
			
		
		
		
	* feat: server side search API (#2112) * refactor repository_recipes filter building * add food filter to recipe repository page_all * fix query type annotations * working search * add tests and make sure title matches are ordered correctly * remove instruction matching again * fix formatting and small issues * fix another linting error * make search test no rely on actual words * fix failing postgres compiled query * revise incorrectly ordered migration * automatically extract latest migration version * test migration orderes * run type generators * new search function * wip: new search page * sortable field options * fix virtual scroll issue * fix search casing bug * finalize search filters/sorts * remove old composable * fix type errors --------- Co-authored-by: Sören <fleshgolem@gmx.net>
		
			
				
	
	
		
			39 lines
		
	
	
		
			1.3 KiB
		
	
	
	
		
			TypeScript
		
	
	
	
	
	
			
		
		
	
	
			39 lines
		
	
	
		
			1.3 KiB
		
	
	
	
		
			TypeScript
		
	
	
	
	
	
| const parts = {
 | |
|   host: "http://localhost.com",
 | |
|   prefix: "",
 | |
| };
 | |
| 
 | |
| export function overrideParts(host: string, prefix: string) {
 | |
|   parts.host = host;
 | |
|   parts.prefix = prefix;
 | |
| }
 | |
| 
 | |
| export type QueryValue = string | string[] | number | number[] | boolean | null | undefined;
 | |
| 
 | |
| /**
 | |
|  * route is a the main URL builder for the API. It will use a predefined host and prefix (global)
 | |
|  * in the urls.ts file and then append the passed in path parameter uring the `URL` class from the
 | |
|  * browser. It will also append any query parameters passed in as the second parameter.
 | |
|  *
 | |
|  * The default host `http://localhost.com` is removed from the path if it is present. This allows us
 | |
|  * to bootstrap the API with different hosts as needed (like for testing) but still allows us to use
 | |
|  * relative URLs in production because the API and client bundle are served from the same server/host.
 | |
|  */
 | |
| export function route(rest: string, params: Record<string, QueryValue> | null = null): string {
 | |
|   const url = new URL(parts.prefix + rest, parts.host);
 | |
| 
 | |
|   if (params) {
 | |
|     for (const [key, value] of Object.entries(params)) {
 | |
|       if (Array.isArray(value)) {
 | |
|         for (const item of value) {
 | |
|           url.searchParams.append(key, String(item));
 | |
|         }
 | |
|       } else {
 | |
|         url.searchParams.append(key, String(value));
 | |
|       }
 | |
|     }
 | |
|   }
 | |
| 
 | |
|   return url.toString().replace("http://localhost.com", "");
 | |
| }
 |