mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2025-05-15 07:34:42 -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
53
frontend/src/api/media/index.ts
Normal file
53
frontend/src/api/media/index.ts
Normal file
|
@ -0,0 +1,53 @@
|
|||
/*
|
||||
* SPDX-FileCopyrightText: 2022 The HedgeDoc developers (see AUTHORS file)
|
||||
*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
*/
|
||||
import type { ImageProxyRequestDto, ImageProxyResponse, MediaUpload } from './types'
|
||||
import { PostApiRequestBuilder } from '../common/api-request-builder/post-api-request-builder'
|
||||
import { DeleteApiRequestBuilder } from '../common/api-request-builder/delete-api-request-builder'
|
||||
|
||||
/**
|
||||
* Requests an image-proxy URL from the backend for a given image URL.
|
||||
*
|
||||
* @param imageUrl The image URL which should be proxied.
|
||||
* @return The proxy URL for the image.
|
||||
* @throws {Error} when the api request wasn't successful.
|
||||
*/
|
||||
export const getProxiedUrl = async (imageUrl: string): Promise<ImageProxyResponse> => {
|
||||
const response = await new PostApiRequestBuilder<ImageProxyResponse, ImageProxyRequestDto>('media/proxy')
|
||||
.withJsonBody({
|
||||
url: imageUrl
|
||||
})
|
||||
.sendRequest()
|
||||
return response.asParsedJsonObject()
|
||||
}
|
||||
|
||||
/**
|
||||
* Uploads a media file to the backend.
|
||||
*
|
||||
* @param noteIdOrAlias The id or alias of the note from which the media is uploaded.
|
||||
* @param media The binary media content.
|
||||
* @return The URL of the uploaded media object.
|
||||
* @throws {Error} when the api request wasn't successful.
|
||||
*/
|
||||
export const uploadFile = async (noteIdOrAlias: string, media: Blob): Promise<MediaUpload> => {
|
||||
const postData = new FormData()
|
||||
postData.append('file', media)
|
||||
const response = await new PostApiRequestBuilder<MediaUpload, void>('media')
|
||||
.withHeader('Content-Type', 'multipart/form-data')
|
||||
.withHeader('HedgeDoc-Note', noteIdOrAlias)
|
||||
.withBody(postData)
|
||||
.sendRequest()
|
||||
return response.asParsedJsonObject()
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes some uploaded media object.
|
||||
*
|
||||
* @param mediaId The identifier of the media object to delete.
|
||||
* @throws {Error} when the api request wasn't successful.
|
||||
*/
|
||||
export const deleteUploadedMedia = async (mediaId: string): Promise<void> => {
|
||||
await new DeleteApiRequestBuilder('media/' + mediaId).sendRequest()
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue