UNPKG

mt-flowbite-react

Version:

Official React components built for Flowbite and Tailwind CSS

64 lines (63 loc) 2.38 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.oauth2Login = exports.mtmApiPost = exports.mtmApiCall = void 0; const lodash_es_1 = require("lodash-es"); // import type { Account } from 'next-auth'; const session_1 = require("../store/session"); // const baseApiUrl = 'https://dev18383.yuepa8.com'; const baseApiUrl = ''; // const baseApiUrl = 'https://dev18383.yuepa8.com'; const apiBasePath = ''; // const apiBasePath = '/api/v3'; const mtmApiCall = async (resName, action, searchParams, payload) => { const sessionData = session_1.useSessionStore.getState().sessionData; const resName2 = (0, lodash_es_1.camelCase)(resName); let url = `${baseApiUrl}${apiBasePath}/${resName2}/${action}`; if (searchParams) { url = `${url}?${new URLSearchParams(searchParams).toString()}`; } const res = await fetch(url, { method: payload ? 'POST' : 'GET', headers: { Authorization: `Bearer ${sessionData?.user?.accessToken}`, ...(payload && { 'Content-Type': 'application/json', }), }, body: JSON.stringify(payload), }); const contentType = res.headers.get('Content-Type'); if (contentType && contentType.includes('application/json')) { return await res.json(); } else { throw new Error(`响应不是 ${url} , JSON 格式:, ${await res.text()}`); } }; exports.mtmApiCall = mtmApiCall; const mtmApiPost = async (apiPath, payload) => { // const sessionData = useSessionStore.getState().sessionData const url = `${apiPath}`; const res = await fetch(url, { method: 'POST', headers: { // "Authorization": `Bearer ${sessionData?.user?.accessToken}`, ...(payload && { 'Content-Type': 'application/json', }), }, body: JSON.stringify(payload), }); const contentType = res.headers.get('Content-Type'); if (contentType && contentType.includes('application/json')) { return await res.json(); } else { throw new Error(`响应不是 ${url} , JSON 格式:, ${await res.text()}`); } }; exports.mtmApiPost = mtmApiPost; const oauth2Login = (account) => { return (0, exports.mtmApiPost)(baseApiUrl + '/auth/oauth2Login', account); }; exports.oauth2Login = oauth2Login;