mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2025-02-20 06:01:04 +00:00
MediaService: Add MediaBackendError
This get's thrown when the backend can't perform the required action. Signed-off-by: Philip Molares <philip.molares@udo.edu>
This commit is contained in:
parent
4ab6db0031
commit
bee2333f77
3 changed files with 11 additions and 0 deletions
|
@ -31,3 +31,7 @@ export class TooManyTokensError extends Error {
|
|||
export class PermissionsUpdateInconsistentError extends Error {
|
||||
name = 'PermissionsUpdateInconsistentError';
|
||||
}
|
||||
|
||||
export class MediaBackendError extends Error {
|
||||
name = 'MediaBackendError';
|
||||
}
|
||||
|
|
|
@ -11,6 +11,7 @@ export interface MediaBackend {
|
|||
* Saves a file according to backend internals.
|
||||
* @param buffer File data
|
||||
* @param fileName Name of the file to save. Can include a file extension.
|
||||
* @throws {MediaBackendError} - there was an error saving the file
|
||||
* @return Tuple of file URL and internal backend data, which should be saved.
|
||||
*/
|
||||
saveFile(buffer: Buffer, fileName: string): Promise<[string, BackendData]>;
|
||||
|
@ -19,6 +20,7 @@ export interface MediaBackend {
|
|||
* Retrieve the URL of a previously saved file.
|
||||
* @param fileName String to identify the file
|
||||
* @param backendData Internal backend data
|
||||
* @throws {MediaBackendError} - there was an error deleting the file
|
||||
*/
|
||||
getFileURL(fileName: string, backendData: BackendData): Promise<string>;
|
||||
|
||||
|
@ -26,6 +28,7 @@ export interface MediaBackend {
|
|||
* Delete a file from the backend
|
||||
* @param fileName String to identify the file
|
||||
* @param backendData Internal backend data
|
||||
* @throws {MediaBackendError} - there was an error retrieving the url
|
||||
*/
|
||||
deleteFile(fileName: string, backendData: BackendData): Promise<void>;
|
||||
}
|
||||
|
|
|
@ -67,6 +67,8 @@ export class MediaService {
|
|||
* @param {string} noteId - the id or alias of the note which will be associated with the new file.
|
||||
* @return {string} the url of the saved file
|
||||
* @throws {ClientError} the MIME type of the file is not supported.
|
||||
* @throws {NotInDBError} - the note or user is not in the database
|
||||
* @throws {MediaBackendError} - there was an error saving the file
|
||||
*/
|
||||
async saveFile(
|
||||
fileBuffer: Buffer,
|
||||
|
@ -110,6 +112,7 @@ export class MediaService {
|
|||
* @return {string} the url of the saved file
|
||||
* @throws {PermissionError} the user is not permitted to delete this file.
|
||||
* @throws {NotInDBError} - the file entry specified is not in the database
|
||||
* @throws {MediaBackendError} - there was an error deleting the file
|
||||
*/
|
||||
async deleteFile(filename: string, username: string): Promise<void> {
|
||||
this.logger.debug(
|
||||
|
@ -136,6 +139,7 @@ export class MediaService {
|
|||
* @param {string} filename - the name of the file entry to find
|
||||
* @return {MediaUpload} the file entry, that was searched for
|
||||
* @throws {NotInDBError} - the file entry specified is not in the database
|
||||
* @throws {MediaBackendError} - there was an error retrieving the url
|
||||
*/
|
||||
async findUploadByFilename(filename: string): Promise<MediaUpload> {
|
||||
const mediaUpload = await this.mediaUploadRepository.findOne(filename, {
|
||||
|
|
Loading…
Reference in a new issue