golden hour
/home/godaofbq/hardchambers.com/wp-content/plugins/code-snippets/js/utils
⬆️ Go Up
Upload
File/Folder
Size
Actions
Linter.ts
4.44 KB
Del
OK
api
-
Del
OK
errors.ts
80 B
Del
OK
files.ts
1.01 KB
Del
OK
general.ts
433 B
Del
OK
restAPI.ts
793 B
Del
OK
shortcodes.ts
346 B
Del
OK
snippets.ts
986 B
Del
OK
text.ts
623 B
Del
OK
Edit: 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<string, AxiosResponse<unknown> | undefined> = {} export const getCached = <T, D>(endpoint: string, refresh = false, config?: AxiosRequestConfig<D>): Promise<AxiosResponse<T, D>> => !refresh && GET_CACHE[endpoint] ? Promise.resolve(<AxiosResponse<T, D>> GET_CACHE[endpoint]) : axios .get<T, AxiosResponse<T, D>, D>(getRestUrl(endpoint), config) .then(response => { GET_CACHE[endpoint] = response return response })
Save