Portfolio/src/composables/useAPI.ts
Matthew L McPeak cb287c0e51
All checks were successful
ci / build (push) Successful in 30s
ci / publish (push) Successful in 18s
Inital Commit
2026-07-16 12:38:41 -04:00

28 lines
758 B
TypeScript

import { useUtils } from './useUtils'
import type { PortfolioData } from '@/data/portfolio'
export const useAPI = (baseURL = API_URL, key = API_KEY) => {
const { url } = useUtils()
const normalizedURL = url.normalizePath(baseURL.trim())
const generateURL = (path: string) => {
return normalizedURL + path
}
const getPortfolioData = async () =>
fetch(generateURL('/keyvalue?key=portfolio'), {
headers: {
authorization: `Bearer ` + key.trim(),
},
})
.then((resp) => resp.json())
.then((data: { key: string; value: string }[]) =>
data.length > 0 && data[0] ? (JSON.parse(data[0].value) as PortfolioData) : undefined,
)
.catch(() => undefined)
return {
getPortfolioData,
}
}