mirror of
https://github.com/mealie-recipes/mealie.git
synced 2025-07-24 07:39:41 +02:00
feat: Migrate to Nuxt 3 framework (#5184)
Co-authored-by: Michael Genson <71845777+michael-genson@users.noreply.github.com> Co-authored-by: Kuchenpirat <24235032+Kuchenpirat@users.noreply.github.com>
This commit is contained in:
parent
89ab7fac25
commit
c24d532608
403 changed files with 23959 additions and 19557 deletions
|
@ -1,7 +1,5 @@
|
|||
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 type { AxiosInstance, AxiosResponse } from "axios";
|
||||
import type { ApiRequestInstance, RequestResponse } from "~/lib/api/types/non-generated";
|
||||
import { AdminAPI, PublicApi, UserApi } from "~/lib/api";
|
||||
import { PublicExploreApi } from "~/lib/api/client-public";
|
||||
|
||||
|
@ -9,7 +7,7 @@ const request = {
|
|||
async safe<T, U>(
|
||||
funcCall: (url: string, data: U) => Promise<AxiosResponse<T>>,
|
||||
url: string,
|
||||
data: U
|
||||
data: U,
|
||||
): Promise<RequestResponse<T>> {
|
||||
let error = null;
|
||||
const response = await funcCall(url, data).catch(function (e) {
|
||||
|
@ -22,7 +20,7 @@ const request = {
|
|||
},
|
||||
};
|
||||
|
||||
function getRequests(axiosInstance: NuxtAxiosInstance): ApiRequestInstance {
|
||||
function getRequests(axiosInstance: AxiosInstance): ApiRequestInstance {
|
||||
return {
|
||||
async get<T>(url: string, params = {}): Promise<RequestResponse<T>> {
|
||||
let error = null;
|
||||
|
@ -36,31 +34,28 @@ function getRequests(axiosInstance: NuxtAxiosInstance): ApiRequestInstance {
|
|||
},
|
||||
|
||||
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 useRequests = function (): ApiRequestInstance {
|
||||
const { $axios, i18n } = useContext();
|
||||
const i18n = useI18n();
|
||||
const { $axios } = useNuxtApp();
|
||||
|
||||
$axios.setHeader("Accept-Language", i18n.locale);
|
||||
$axios.defaults.headers.common["Accept-Language"] = i18n.locale.value;
|
||||
|
||||
return getRequests($axios);
|
||||
};
|
||||
|
@ -83,4 +78,4 @@ export const usePublicApi = function (): PublicApi {
|
|||
export const usePublicExploreApi = function (groupSlug: string): PublicExploreApi {
|
||||
const requests = useRequests();
|
||||
return new PublicExploreApi(requests, groupSlug);
|
||||
}
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue