mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2025-05-20 10:15:17 -04:00
fix: Move content into to frontend directory
Doing this BEFORE the merge prevents a lot of merge conflicts. Signed-off-by: Tilman Vatteroth <git@tilmanvatteroth.de>
This commit is contained in:
parent
4e18ce38f3
commit
762a0a850e
1051 changed files with 0 additions and 35 deletions
48
frontend/src/api/tokens/index.ts
Normal file
48
frontend/src/api/tokens/index.ts
Normal file
|
@ -0,0 +1,48 @@
|
|||
/*
|
||||
* SPDX-FileCopyrightText: 2022 The HedgeDoc developers (see AUTHORS file)
|
||||
*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
*/
|
||||
import type { AccessToken, AccessTokenWithSecret, CreateAccessTokenDto } from './types'
|
||||
import { GetApiRequestBuilder } from '../common/api-request-builder/get-api-request-builder'
|
||||
import { PostApiRequestBuilder } from '../common/api-request-builder/post-api-request-builder'
|
||||
import { DeleteApiRequestBuilder } from '../common/api-request-builder/delete-api-request-builder'
|
||||
|
||||
/**
|
||||
* Retrieves the access tokens for the current user.
|
||||
*
|
||||
* @return List of access token metadata.
|
||||
* @throws {Error} when the api request wasn't successful.
|
||||
*/
|
||||
export const getAccessTokenList = async (): Promise<AccessToken[]> => {
|
||||
const response = await new GetApiRequestBuilder<AccessToken[]>('tokens').sendRequest()
|
||||
return response.asParsedJsonObject()
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new access token for the current user.
|
||||
*
|
||||
* @param label The user-defined label for the new access token.
|
||||
* @param validUntil The user-defined expiry date of the new access token in milliseconds of unix time.
|
||||
* @return The new access token metadata along with its secret.
|
||||
* @throws {Error} when the api request wasn't successful.
|
||||
*/
|
||||
export const postNewAccessToken = async (label: string, validUntil: number): Promise<AccessTokenWithSecret> => {
|
||||
const response = await new PostApiRequestBuilder<AccessTokenWithSecret, CreateAccessTokenDto>('tokens')
|
||||
.withJsonBody({
|
||||
label,
|
||||
validUntil
|
||||
})
|
||||
.sendRequest()
|
||||
return response.asParsedJsonObject()
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes an access token from the current user account.
|
||||
*
|
||||
* @param keyId The key id of the access token to delete.
|
||||
* @throws {Error} when the api request wasn't successful.
|
||||
*/
|
||||
export const deleteAccessToken = async (keyId: string): Promise<void> => {
|
||||
await new DeleteApiRequestBuilder('tokens/' + keyId).sendRequest()
|
||||
}
|
22
frontend/src/api/tokens/types.ts
Normal file
22
frontend/src/api/tokens/types.ts
Normal file
|
@ -0,0 +1,22 @@
|
|||
/*
|
||||
* SPDX-FileCopyrightText: 2022 The HedgeDoc developers (see AUTHORS file)
|
||||
*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
*/
|
||||
|
||||
export interface AccessToken {
|
||||
label: string
|
||||
validUntil: string
|
||||
keyId: string
|
||||
createdAt: string
|
||||
lastUsedAt: string | null
|
||||
}
|
||||
|
||||
export interface AccessTokenWithSecret extends AccessToken {
|
||||
secret: string
|
||||
}
|
||||
|
||||
export interface CreateAccessTokenDto {
|
||||
label: string
|
||||
validUntil: number
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue