mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2025-05-18 17:25:16 -04: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
df1ae4d512
commit
8515d824b7
3 changed files with 11 additions and 0 deletions
|
@ -31,3 +31,7 @@ export class TooManyTokensError extends Error {
|
||||||
export class PermissionsUpdateInconsistentError extends Error {
|
export class PermissionsUpdateInconsistentError extends Error {
|
||||||
name = 'PermissionsUpdateInconsistentError';
|
name = 'PermissionsUpdateInconsistentError';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export class MediaBackendError extends Error {
|
||||||
|
name = 'MediaBackendError';
|
||||||
|
}
|
||||||
|
|
|
@ -11,6 +11,7 @@ export interface MediaBackend {
|
||||||
* Saves a file according to backend internals.
|
* Saves a file according to backend internals.
|
||||||
* @param buffer File data
|
* @param buffer File data
|
||||||
* @param fileName Name of the file to save. Can include a file extension.
|
* @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.
|
* @return Tuple of file URL and internal backend data, which should be saved.
|
||||||
*/
|
*/
|
||||||
saveFile(buffer: Buffer, fileName: string): Promise<[string, BackendData]>;
|
saveFile(buffer: Buffer, fileName: string): Promise<[string, BackendData]>;
|
||||||
|
@ -19,6 +20,7 @@ export interface MediaBackend {
|
||||||
* Retrieve the URL of a previously saved file.
|
* Retrieve the URL of a previously saved file.
|
||||||
* @param fileName String to identify the file
|
* @param fileName String to identify the file
|
||||||
* @param backendData Internal backend data
|
* @param backendData Internal backend data
|
||||||
|
* @throws {MediaBackendError} - there was an error deleting the file
|
||||||
*/
|
*/
|
||||||
getFileURL(fileName: string, backendData: BackendData): Promise<string>;
|
getFileURL(fileName: string, backendData: BackendData): Promise<string>;
|
||||||
|
|
||||||
|
@ -26,6 +28,7 @@ export interface MediaBackend {
|
||||||
* Delete a file from the backend
|
* Delete a file from the backend
|
||||||
* @param fileName String to identify the file
|
* @param fileName String to identify the file
|
||||||
* @param backendData Internal backend data
|
* @param backendData Internal backend data
|
||||||
|
* @throws {MediaBackendError} - there was an error retrieving the url
|
||||||
*/
|
*/
|
||||||
deleteFile(fileName: string, backendData: BackendData): Promise<void>;
|
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.
|
* @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
|
* @return {string} the url of the saved file
|
||||||
* @throws {ClientError} the MIME type of the file is not supported.
|
* @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(
|
async saveFile(
|
||||||
fileBuffer: Buffer,
|
fileBuffer: Buffer,
|
||||||
|
@ -110,6 +112,7 @@ export class MediaService {
|
||||||
* @return {string} the url of the saved file
|
* @return {string} the url of the saved file
|
||||||
* @throws {PermissionError} the user is not permitted to delete this file.
|
* @throws {PermissionError} the user is not permitted to delete this file.
|
||||||
* @throws {NotInDBError} - the file entry specified is not in the database
|
* @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> {
|
async deleteFile(filename: string, username: string): Promise<void> {
|
||||||
this.logger.debug(
|
this.logger.debug(
|
||||||
|
@ -136,6 +139,7 @@ export class MediaService {
|
||||||
* @param {string} filename - the name of the file entry to find
|
* @param {string} filename - the name of the file entry to find
|
||||||
* @return {MediaUpload} the file entry, that was searched for
|
* @return {MediaUpload} the file entry, that was searched for
|
||||||
* @throws {NotInDBError} - the file entry specified is not in the database
|
* @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> {
|
async findUploadByFilename(filename: string): Promise<MediaUpload> {
|
||||||
const mediaUpload = await this.mediaUploadRepository.findOne(filename, {
|
const mediaUpload = await this.mediaUploadRepository.findOne(filename, {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue