芝麻web文件管理V1.00
编辑当前文件:/home/freeclou/optimyar/wp-content/plugins/code-snippets/js/utils/restAPI.ts
import axios from 'axios' import { trimLeadingChar, trimTrailingChar } from './text' import type { AxiosRequestConfig, AxiosResponse } from 'axios' const REST_BASE = window.CODE_SNIPPETS?.restAPI.base ?? '' const getRestUrl = (endpoint: string): string => `${trimTrailingChar(REST_BASE, '/')}/${trimLeadingChar(endpoint, '/')}` const GET_CACHE: Record
| undefined> = {} export const getCached =
(endpoint: string, refresh = false, config?: AxiosRequestConfig
): Promise
> => !refresh && GET_CACHE[endpoint] ? Promise.resolve(
> GET_CACHE[endpoint]) : axios .get
, D>(getRestUrl(endpoint), config) .then(response => { GET_CACHE[endpoint] = response return response })