Skip to content

Commit

Permalink
Added API specs, formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
Forceu committed Dec 13, 2024
1 parent 6f73908 commit e0c09b0
Show file tree
Hide file tree
Showing 3 changed files with 152 additions and 57 deletions.
70 changes: 59 additions & 11 deletions internal/webserver/web/static/apidocumentation/openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
}
Expand Down Expand Up @@ -100,7 +148,7 @@
"description": "Invalid input"
},
"401": {
"description": "Invalid API key provided or not logged in as admin"
"description": "Invalid API key provided"
}
}
}
Expand Down Expand Up @@ -143,7 +191,7 @@
"description": "Invalid input"
},
"401": {
"description": "Invalid API key provided or not logged in as admin"
"description": "Invalid API key provided"
}
}
}
Expand Down Expand Up @@ -186,7 +234,7 @@
"description": "Invalid input"
},
"401": {
"description": "Invalid API key provided or not logged in as admin"
"description": "Invalid API key provided"
}
}
}
Expand Down Expand Up @@ -229,7 +277,7 @@
"description": "Invalid input"
},
"401": {
"description": "Invalid API key provided or not logged in as admin"
"description": "Invalid API key provided"
}
}
}
Expand Down Expand Up @@ -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"
}
}
}
Expand Down Expand Up @@ -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"
}
}
}
Expand Down Expand Up @@ -402,7 +450,7 @@
}
},
"401": {
"description": "Invalid API key provided or not logged in as admin"
"description": "Invalid API key provided"
}
}
}
Expand Down Expand Up @@ -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"
}
}
}
Expand Down Expand Up @@ -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"
}
}
}
Expand Down Expand Up @@ -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"
}
}
}
Expand Down
69 changes: 34 additions & 35 deletions internal/webserver/web/static/js/admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -233,16 +233,15 @@ 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;
}

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: {
Expand All @@ -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);
});
Expand Down Expand Up @@ -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;
}
Expand Down
Loading

0 comments on commit e0c09b0

Please sign in to comment.