diff --git a/internal/webserver/web/static/apidocumentation/openapi.json b/internal/webserver/web/static/apidocumentation/openapi.json index 23eba0e9..b621ce3e 100644 --- a/internal/webserver/web/static/apidocumentation/openapi.json +++ b/internal/webserver/web/static/apidocumentation/openapi.json @@ -57,7 +57,55 @@ "description": "Invalid input" }, "401": { - "description": "Invalid API key provided or not logged in as admin" + "description": "Invalid API key provided" + } + } + } + }, + "/files/list/{id}": { + "get": { + "tags": [ + "files" + ], + "summary": "Get metadata by ID", + "description": "This API call lists all metadata about a file that is not expired. Returns 404 if an invalid/expired ID was passed. Requires permission VIEW", + "operationId": "listbyid", + "parameters": [ + { + "name": "id", + "in": "path", + "required": true, + "schema": { + "type": "string" + }, + "description": "ID of file to be requested" + } + ], + + "security": [ + { + "apikey": ["VIEW"] + }, + ], + "responses": { + "200": { + "description": "Operation successful", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/File" + } + } + } + }, + "400": { + "description": "Invalid input" + }, + "401": { + "description": "Invalid API key provided" + }, + "404": { + "description": "Invalid ID provided or file has expired" } } } @@ -100,7 +148,7 @@ "description": "Invalid input" }, "401": { - "description": "Invalid API key provided or not logged in as admin" + "description": "Invalid API key provided" } } } @@ -143,7 +191,7 @@ "description": "Invalid input" }, "401": { - "description": "Invalid API key provided or not logged in as admin" + "description": "Invalid API key provided" } } } @@ -186,7 +234,7 @@ "description": "Invalid input" }, "401": { - "description": "Invalid API key provided or not logged in as admin" + "description": "Invalid API key provided" } } } @@ -229,7 +277,7 @@ "description": "Invalid input" }, "401": { - "description": "Invalid API key provided or not logged in as admin" + "description": "Invalid API key provided" } } } @@ -309,7 +357,7 @@ "description": "Invalid ID supplied or incorrect data type sent" }, "401": { - "description": "Invalid API key provided or not logged in as admin" + "description": "Invalid API key provided" } } } @@ -348,7 +396,7 @@ "description": "Invalid ID supplied" }, "401": { - "description": "Invalid API key provided or not logged in as admin" + "description": "Invalid API key provided" } } } @@ -402,7 +450,7 @@ } }, "401": { - "description": "Invalid API key provided or not logged in as admin" + "description": "Invalid API key provided" } } } @@ -452,7 +500,7 @@ "description": "Invalid ID supplied" }, "401": { - "description": "Invalid API key provided or not logged in as admin" + "description": "Invalid API key provided" } } } @@ -515,7 +563,7 @@ "description": "Invalid ID supplied" }, "401": { - "description": "Invalid API key provided or not logged in as admin" + "description": "Invalid API key provided" } } } @@ -554,7 +602,7 @@ "description": "Invalid ID supplied" }, "401": { - "description": "Invalid API key provided or not logged in as admin" + "description": "Invalid API key provided" } } } diff --git a/internal/webserver/web/static/js/admin.js b/internal/webserver/web/static/js/admin.js index aa2019e1..c16bff98 100644 --- a/internal/webserver/web/static/js/admin.js +++ b/internal/webserver/web/static/js/admin.js @@ -202,21 +202,21 @@ function sendChunkComplete(file, done) { if (this.readyState == 4) { if (this.status == 200) { done(); - let progressText = document.getElementById(`us-progress-info-${file.upload.uuid}`); - if (progressText != null) - progressText.innerText = "In Queue..."; - } else { + let progressText = document.getElementById(`us-progress-info-${file.upload.uuid}`); + if (progressText != null) + progressText.innerText = "In Queue..."; + } else { dropzoneUploadError(file, getErrorMessage(xhr.responseText)); } - } + } }; xhr.send(urlencodeFormData(formData)); } function dropzoneUploadError(file, errormessage) { - file.accepted = false; - dropzoneObject._errorProcessing([file], errormessage); - showError(file, errormessage); + file.accepted = false; + dropzoneObject._errorProcessing([file], errormessage); + showError(file, errormessage); } function getErrorMessage(response) { @@ -233,7 +233,7 @@ function dropzoneGetFile(uid) { for (let i = 0; i < dropzoneObject.files.length; i++) { const currentFile = dropzoneObject.files[i]; if (currentFile.upload.uuid === uid) { - return currentFile; + return currentFile; } } return null; @@ -241,8 +241,7 @@ function dropzoneGetFile(uid) { function requestFileInfo(fileId, uid) { -//TODO add to API documentation - let apiUrl = './api/files/list/'+fileId; + let apiUrl = './api/files/list/' + fileId; const requestOptions = { method: 'GET', headers: { @@ -259,38 +258,38 @@ function requestFileInfo(fileId, uid) { throw new Error(`Request failed with status: ${response.status}`); } return response.json(); - + }) .then(data => { addRow(data); - let file = dropzoneGetFile(uid); + let file = dropzoneGetFile(uid); if (file == null) { - return; + return; } if (file.isEndToEndEncrypted === true) { - try { - let result = GokapiE2EAddFile(uid, fileId, file.name); - if (result instanceof Error) { - throw result; - } - let info = GokapiE2EInfoEncrypt(); - if (info instanceof Error) { - throw info; - } - storeE2EInfo(info); - } catch (err) { - file.accepted = false; - dropzoneObject._errorProcessing([file], err); - return; + try { + let result = GokapiE2EAddFile(uid, fileId, file.name); + if (result instanceof Error) { + throw result; } - GokapiE2EDecryptMenu(); + let info = GokapiE2EInfoEncrypt(); + if (info instanceof Error) { + throw info; + } + storeE2EInfo(info); + } catch (err) { + file.accepted = false; + dropzoneObject._errorProcessing([file], err); + return; } - removeFileStatus(uid); + GokapiE2EDecryptMenu(); + } + removeFileStatus(uid); }) .catch(error => { - let file = dropzoneGetFile(uid); + let file = dropzoneGetFile(uid); if (file != null) { - dropzoneUploadError(file, error); + dropzoneUploadError(file, error); } console.error('Error:', error); }); @@ -320,12 +319,12 @@ function parseProgressStatus(eventData) { text = "Error"; let file = dropzoneGetFile(eventData.chunk_id); if (eventData.error_message == "") - eventData.error_message = "Server Error"; + eventData.error_message = "Server Error"; if (file != null) { - dropzoneUploadError(file, eventData.error_message); + dropzoneUploadError(file, eventData.error_message); } return; - default: + default: text = "Unknown status"; break; } diff --git a/openapi.json b/openapi.json index 23eba0e9..b621ce3e 100644 --- a/openapi.json +++ b/openapi.json @@ -57,7 +57,55 @@ "description": "Invalid input" }, "401": { - "description": "Invalid API key provided or not logged in as admin" + "description": "Invalid API key provided" + } + } + } + }, + "/files/list/{id}": { + "get": { + "tags": [ + "files" + ], + "summary": "Get metadata by ID", + "description": "This API call lists all metadata about a file that is not expired. Returns 404 if an invalid/expired ID was passed. Requires permission VIEW", + "operationId": "listbyid", + "parameters": [ + { + "name": "id", + "in": "path", + "required": true, + "schema": { + "type": "string" + }, + "description": "ID of file to be requested" + } + ], + + "security": [ + { + "apikey": ["VIEW"] + }, + ], + "responses": { + "200": { + "description": "Operation successful", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/File" + } + } + } + }, + "400": { + "description": "Invalid input" + }, + "401": { + "description": "Invalid API key provided" + }, + "404": { + "description": "Invalid ID provided or file has expired" } } } @@ -100,7 +148,7 @@ "description": "Invalid input" }, "401": { - "description": "Invalid API key provided or not logged in as admin" + "description": "Invalid API key provided" } } } @@ -143,7 +191,7 @@ "description": "Invalid input" }, "401": { - "description": "Invalid API key provided or not logged in as admin" + "description": "Invalid API key provided" } } } @@ -186,7 +234,7 @@ "description": "Invalid input" }, "401": { - "description": "Invalid API key provided or not logged in as admin" + "description": "Invalid API key provided" } } } @@ -229,7 +277,7 @@ "description": "Invalid input" }, "401": { - "description": "Invalid API key provided or not logged in as admin" + "description": "Invalid API key provided" } } } @@ -309,7 +357,7 @@ "description": "Invalid ID supplied or incorrect data type sent" }, "401": { - "description": "Invalid API key provided or not logged in as admin" + "description": "Invalid API key provided" } } } @@ -348,7 +396,7 @@ "description": "Invalid ID supplied" }, "401": { - "description": "Invalid API key provided or not logged in as admin" + "description": "Invalid API key provided" } } } @@ -402,7 +450,7 @@ } }, "401": { - "description": "Invalid API key provided or not logged in as admin" + "description": "Invalid API key provided" } } } @@ -452,7 +500,7 @@ "description": "Invalid ID supplied" }, "401": { - "description": "Invalid API key provided or not logged in as admin" + "description": "Invalid API key provided" } } } @@ -515,7 +563,7 @@ "description": "Invalid ID supplied" }, "401": { - "description": "Invalid API key provided or not logged in as admin" + "description": "Invalid API key provided" } } } @@ -554,7 +602,7 @@ "description": "Invalid ID supplied" }, "401": { - "description": "Invalid API key provided or not logged in as admin" + "description": "Invalid API key provided" } } }