mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2025-05-14 07:04:45 -04:00
24 lines
733 B
TypeScript
24 lines
733 B
TypeScript
/*
|
|
* SPDX-FileCopyrightText: 2021 The HedgeDoc developers (see AUTHORS file)
|
|
*
|
|
* SPDX-License-Identifier: AGPL-3.0-only
|
|
*/
|
|
|
|
import { Cache } from '../../components/common/cache/cache'
|
|
import { defaultFetchConfig, expectResponseCode, getApiUrl } from '../utils'
|
|
import { UserResponse } from './types'
|
|
|
|
const cache = new Cache<string, UserResponse>(600)
|
|
|
|
export const getUserById = async (userid: string): Promise<UserResponse> => {
|
|
if (cache.has(userid)) {
|
|
return cache.get(userid)
|
|
}
|
|
const response = await fetch(`${getApiUrl()}/users/${userid}`, {
|
|
...defaultFetchConfig
|
|
})
|
|
expectResponseCode(response)
|
|
const userData = (await response.json()) as UserResponse
|
|
cache.put(userid, userData)
|
|
return userData
|
|
}
|