Skip to content

Commit

Permalink
Split JS into multiple files for better maintenance, changed version …
Browse files Browse the repository at this point in the history
…number
  • Loading branch information
Forceu committed Dec 18, 2024
1 parent e4fe145 commit 34873b5
Show file tree
Hide file tree
Showing 9 changed files with 310 additions and 265 deletions.
2 changes: 1 addition & 1 deletion cmd/gokapi/Main.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import (

// versionGokapi is the current version in readable form.
// Other version numbers can be modified in /build/go-generate/updateVersionNumbers.go
const versionGokapi = "1.9.5"
const versionGokapi = "1.9.6"

// The following calls update the version numbers, update documentation, minify Js/CSS and build the WASM modules
//go:generate go run "../../build/go-generate/updateVersionNumbers.go"
Expand Down
27 changes: 26 additions & 1 deletion docs/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,37 @@ Changelog
Overview of all Changes
-----------------------

v1.9.6: 18 Dec 2024
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

v1.9.4: 07 Dec 2024
* Add API call and GUI option to replace content of files (can be disabled with the env variable GOKAPI_DISABLE_REPLACE)
* Display error if encrypted download fails due to invalid SSL or CORS
* Better error handling for AWS setup check
* Fixed upload defaults being deleted when resetting e2e key
* Update download count in real time #206
* Fixed race condition that could lead to crash
* Change download count atomically to prevent race condition
* Renamed "Access Restriction" to indicate that authentication is disababled
* Make upload non blocking (#224), to prevent timouts after uploading large files
* Added API call /files/list/{id}
* Better handling for E2E errors
* Other minor changes
* Breaking Changes
* API now returns 404 on invalid file IDs




v1.9.5: 08 Dec 2024
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

* Fixed a crash caused by an incorrectly upgraded database version #215

v1.9.4: 07 Dec 2024
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

* Retracted release

v1.9.3: 07 Dec 2024
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@
"files"
],
"summary": "Replaces an uploaded file",
"description": "This API replaces the content of an uploaded file with the content of a different (already uplaoded) file. Note: Replacing end-to-end ecrypted files is NOT possible and will result in an error when downloading. Requires permission REPLACE",
"description": "This API replaces the content of an uploaded file with the content of a different (already uplaoded) file. Note: Replacing end-to-end ecrypted files is NOT possible and will result in an error. Requires permission REPLACE",
"operationId": "replacefile",
"security": [
{
Expand Down
164 changes: 164 additions & 0 deletions internal/webserver/web/static/js/admin_ui_api.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,164 @@
// This file contains JS code for the API view
// All files named admin_*.js will be merged together and minimised by calling
// go generate ./...


function changeApiPermission(apiKey, permission, buttonId) {

var indicator = document.getElementById(buttonId);
if (indicator.classList.contains("apiperm-processing")) {
return;
}
var wasGranted = indicator.classList.contains("apiperm-granted");
indicator.classList.add("apiperm-processing");
indicator.classList.remove("apiperm-granted");
indicator.classList.remove("apiperm-notgranted");

var modifier = "GRANT";
if (wasGranted) {
modifier = "REVOKE";
}


apiAuthModify(apiKey, permission, modifier)
.then(data => {
if (wasGranted) {
indicator.classList.add("apiperm-notgranted");
} else {
indicator.classList.add("apiperm-granted");
}
indicator.classList.remove("apiperm-processing");
})
.catch(error => {
if (wasGranted) {
indicator.classList.add("apiperm-granted");
} else {
indicator.classList.add("apiperm-notgranted");
}
indicator.classList.remove("apiperm-processing");
alert("Unable to set permission: " + error);
console.error('Error:', error);
});
}

function deleteApiKey(apiKey) {

document.getElementById("delete-" + apiKey).disabled = true;

apiAuthDelete(apiKey)
.then(data => {
document.getElementById("row-" + apiKey).remove();
})
.catch(error => {
alert("Unable to delete API key: " + error);
console.error('Error:', error);
});
}



function newApiKey() {
document.getElementById("button-newapi").disabled = true;
apiAuthCreate()
.then(data => {
addRowApi(data.Id);
document.getElementById("button-newapi").disabled = false;
})
.catch(error => {
alert("Unable to create API key: " + error);
console.error('Error:', error);
});
}




function addFriendlyNameChange(apiKey) {
let cell = document.getElementById("friendlyname-" + apiKey);
if (cell.classList.contains("isBeingEdited"))
return;
cell.classList.add("isBeingEdited");
let currentName = cell.innerHTML;
let input = document.createElement("input");
input.size = 5;
input.value = currentName;
let allowEdit = true;

let submitEntry = function() {
if (!allowEdit)
return;
allowEdit = false;
let newName = input.value;
cell.innerHTML = newName;

cell.classList.remove("isBeingEdited");

apiAuthFriendlyName(apiKey, newName)
.catch(error => {
alert("Unable to save name: " + error);
console.error('Error:', error);
});
};

input.onblur = submitEntry;
input.addEventListener("keyup", function(event) {
// Enter
if (event.keyCode === 13) {
event.preventDefault();
submitEntry();
}
});
cell.innerHTML = "";
cell.appendChild(input);
input.focus();
}




function addRowApi(apiKey) {

let table = document.getElementById("apitable");
let row = table.insertRow(0);
row.id = "row-" + apiKey;
let cellFriendlyName = row.insertCell(0);
let cellId = row.insertCell(1);
let cellLastUsed = row.insertCell(2);
let cellPermissions = row.insertCell(3);
let cellButtons = row.insertCell(4);
let cellEmpty = row.insertCell(5);

cellFriendlyName.classList.add("newApiKey");
cellId.classList.add("newApiKey");
cellLastUsed.classList.add("newApiKey");
cellPermissions.classList.add("newApiKey");
cellButtons.classList.add("newApiKey");
cellEmpty.classList.add("newApiKey");


cellFriendlyName.innerText = "Unnamed key";
cellFriendlyName.id = "friendlyname-" + apiKey;
cellFriendlyName.onclick = function() {
addFriendlyNameChange(apiKey);
};
cellId.innerText = apiKey;
cellLastUsed.innerText = "Never";
cellButtons.innerHTML = '<button type="button" data-clipboard-text="' + apiKey + '" onclick="showToast()" title="Copy API Key" class="copyurl btn btn-outline-light btn-sm"><i class="bi bi-copy"></i></button> <button id="delete-' + apiKey + '" type="button" class="btn btn-outline-danger btn-sm" onclick="deleteApiKey(\'' + apiKey + '\')" title="Delete"><i class="bi bi-trash3"></i></button>';
cellPermissions.innerHTML = `
<i id="perm_view_` + apiKey + `" class="bi bi-eye apiperm-granted" title="List Uploads" onclick='changeApiPermission("` + apiKey + `","PERM_VIEW", "perm_view_` + apiKey + `");'></i>
<i id="perm_upload_` + apiKey + `" class="bi bi-file-earmark-arrow-up apiperm-granted" title="Upload" onclick='changeApiPermission("` + apiKey + `","PERM_UPLOAD", "perm_upload_` + apiKey + `");'></i>
<i id="perm_edit_` + apiKey + `" class="bi bi-pencil apiperm-granted" title="Edit Uploads" onclick='changeApiPermission("` + apiKey + `","PERM_EDIT", "perm_edit_` + apiKey + `");'></i>
<i id="perm_delete_` + apiKey + `" class="bi bi-trash3 apiperm-granted" title="Delete Uploads" onclick='changeApiPermission("` + apiKey + `","PERM_DELETE", "perm_delete_` + apiKey + `");'></i>
<i id="perm_replace_` + apiKey + `" class="bi bi-recycle apiperm-notgranted" title="Replace Uploads" onclick='changeApiPermission("` + apiKey + `","PERM_REPLACE", "perm_replace_` + apiKey + `");'></i>
<i id="perm_api_` + apiKey + `" class="bi bi-sliders2 apiperm-notgranted" title="Manage API Keys" onclick='changeApiPermission("` + apiKey + `","PERM_API_MOD", "perm_api_` + apiKey + `");'></i>`;

setTimeout(() => {
cellFriendlyName.classList.remove("newApiKey");
cellId.classList.remove("newApiKey");
cellLastUsed.classList.remove("newApiKey");
cellPermissions.classList.remove("newApiKey");
cellButtons.classList.remove("newApiKey");
cellEmpty.classList.remove("newApiKey");
}, 700);

}
Loading

0 comments on commit 34873b5

Please sign in to comment.