mirror of
				https://github.com/mealie-recipes/mealie.git
				synced 2025-10-31 10:38:18 -04:00 
			
		
		
		
	* fixed incorrect var ref * added public recipe pagination route * refactored frontend public/explore API * fixed broken public cards * hid context menu from cards when public * fixed public app header * fixed random recipe * added public food, category, tag, and tool routes * not sure why I thought that would work * added public organizer/foods stores * disabled clicking on tags/categories * added public link to profile page * linting * force a 404 if the group slug is missing or invalid * oops * refactored to fit sidebar into explore * fixed invalid logic for app header * removed most sidebar options from public * added backend routes for public cookbooks * added explore cookbook pages/apis * codegen * added backend tests * lint * fixes v-for keys * I do not understand but sure why not --------- Co-authored-by: Hayden <64056131+hay-kot@users.noreply.github.com>
		
			
				
	
	
		
			92 lines
		
	
	
		
			2.9 KiB
		
	
	
	
		
			TypeScript
		
	
	
	
	
	
			
		
		
	
	
			92 lines
		
	
	
		
			2.9 KiB
		
	
	
	
		
			TypeScript
		
	
	
	
	
	
| import { AxiosResponse } from "axios";
 | |
| import { useContext } from "@nuxtjs/composition-api";
 | |
| import type { NuxtAxiosInstance } from "@nuxtjs/axios";
 | |
| import { ApiRequestInstance, RequestResponse } from "~/lib/api/types/non-generated";
 | |
| import { AdminAPI, PublicApi, UserApi } from "~/lib/api";
 | |
| import { PublicExploreApi } from "~/lib/api/client-public";
 | |
| 
 | |
| const request = {
 | |
|   async safe<T, U>(
 | |
|     funcCall: (url: string, data: U) => Promise<AxiosResponse<T>>,
 | |
|     url: string,
 | |
|     data: U
 | |
|   ): Promise<RequestResponse<T>> {
 | |
|     let error = null;
 | |
|     const response = await funcCall(url, data).catch(function (e) {
 | |
|       console.log(e);
 | |
|       // Insert Generic Error Handling Here
 | |
|       error = e;
 | |
|       return null;
 | |
|     });
 | |
|     return { response, error, data: response?.data ?? null };
 | |
|   },
 | |
| };
 | |
| 
 | |
| function getRequests(axiosInstance: NuxtAxiosInstance): ApiRequestInstance {
 | |
|   return {
 | |
|     async get<T>(url: string, params = {}): Promise<RequestResponse<T>> {
 | |
|       let error = null;
 | |
|       const response = await axiosInstance.get<T>(url, params).catch((e) => {
 | |
|         error = e;
 | |
|       });
 | |
|       if (response != null) {
 | |
|         return { response, error, data: response?.data };
 | |
|       }
 | |
|       return { response: null, error, data: null };
 | |
|     },
 | |
| 
 | |
|     async post<T, U>(url: string, data: U) {
 | |
|       // eslint-disable-next-line @typescript-eslint/unbound-method
 | |
|       return await request.safe<T, U>(axiosInstance.post, url, data);
 | |
|     },
 | |
| 
 | |
|     async put<T, U = T>(url: string, data: U) {
 | |
|       // eslint-disable-next-line @typescript-eslint/unbound-method
 | |
|       return await request.safe<T, U>(axiosInstance.put, url, data);
 | |
|     },
 | |
| 
 | |
|     async patch<T, U = Partial<T>>(url: string, data: U) {
 | |
|       // eslint-disable-next-line @typescript-eslint/unbound-method
 | |
|       return await request.safe<T, U>(axiosInstance.patch, url, data);
 | |
|     },
 | |
| 
 | |
|     async delete<T>(url: string) {
 | |
|       // eslint-disable-next-line @typescript-eslint/unbound-method
 | |
|       return await request.safe<T, undefined>(axiosInstance.delete, url, undefined);
 | |
|     },
 | |
|   };
 | |
| }
 | |
| 
 | |
| export const useAdminApi = function (): AdminAPI {
 | |
|   const { $axios, i18n } = useContext();
 | |
| 
 | |
|   $axios.setHeader("Accept-Language", i18n.locale);
 | |
| 
 | |
|   const requests = getRequests($axios);
 | |
|   return new AdminAPI(requests);
 | |
| };
 | |
| 
 | |
| export const useUserApi = function (): UserApi {
 | |
|   const { $axios, i18n } = useContext();
 | |
|   $axios.setHeader("Accept-Language", i18n.locale);
 | |
| 
 | |
|   const requests = getRequests($axios);
 | |
|   return new UserApi(requests);
 | |
| };
 | |
| 
 | |
| export const usePublicApi = function (): PublicApi {
 | |
|   const { $axios, i18n } = useContext();
 | |
|   $axios.setHeader("Accept-Language", i18n.locale);
 | |
| 
 | |
|   const requests = getRequests($axios);
 | |
|   return new PublicApi(requests);
 | |
| };
 | |
| 
 | |
| export const usePublicExploreApi = function (groupSlug: string): PublicExploreApi {
 | |
|   const { $axios, i18n } = useContext();
 | |
|   $axios.setHeader("Accept-Language", i18n.locale);
 | |
| 
 | |
|   const requests = getRequests($axios);
 | |
|   return new PublicExploreApi(requests, groupSlug);
 | |
| }
 |