mirror of
https://github.com/Qortal/Qortal-Hub.git
synced 2025-04-23 19:37:52 +00:00
Add ADMIN_ACTION types to manage peers and minting accounts
This commit is contained in:
parent
6ca1c6a578
commit
5144a8341a
@ -3169,6 +3169,20 @@ export const adminAction = async (data, isFromExtension) => {
|
|||||||
missingFields.push(field);
|
missingFields.push(field);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
// For actions that require a value, check for 'value' field
|
||||||
|
const actionsRequiringValue = [
|
||||||
|
"addpeer",
|
||||||
|
"removepeer",
|
||||||
|
"forcesync",
|
||||||
|
"addmintingaccount",
|
||||||
|
"removemintingaccount",
|
||||||
|
];
|
||||||
|
if (
|
||||||
|
actionsRequiringValue.includes(data.type.toLowerCase()) &&
|
||||||
|
!data.value
|
||||||
|
) {
|
||||||
|
missingFields.push("value");
|
||||||
|
}
|
||||||
if (missingFields.length > 0) {
|
if (missingFields.length > 0) {
|
||||||
const missingFieldsString = missingFields.join(", ");
|
const missingFieldsString = missingFields.join(", ");
|
||||||
const errorMsg = `Missing fields: ${missingFieldsString}`;
|
const errorMsg = `Missing fields: ${missingFieldsString}`;
|
||||||
@ -3180,6 +3194,8 @@ export const adminAction = async (data, isFromExtension) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let apiEndpoint = "";
|
let apiEndpoint = "";
|
||||||
|
let method = "GET"; // Default method
|
||||||
|
let includeValueInBody = false;
|
||||||
switch (data.type.toLowerCase()) {
|
switch (data.type.toLowerCase()) {
|
||||||
case "stop":
|
case "stop":
|
||||||
apiEndpoint = await createEndpoint("/admin/stop");
|
apiEndpoint = await createEndpoint("/admin/stop");
|
||||||
@ -3190,19 +3206,58 @@ export const adminAction = async (data, isFromExtension) => {
|
|||||||
case "bootstrap":
|
case "bootstrap":
|
||||||
apiEndpoint = await createEndpoint("/admin/bootstrap");
|
apiEndpoint = await createEndpoint("/admin/bootstrap");
|
||||||
break;
|
break;
|
||||||
|
case "addmintingaccount":
|
||||||
|
apiEndpoint = await createEndpoint("/admin/mintingaccounts");
|
||||||
|
method = "POST";
|
||||||
|
includeValueInBody = true;
|
||||||
|
break;
|
||||||
|
case "removemintingaccount":
|
||||||
|
apiEndpoint = await createEndpoint("/admin/mintingaccounts");
|
||||||
|
method = "DELETE";
|
||||||
|
includeValueInBody = true;
|
||||||
|
break;
|
||||||
|
case "forcesync":
|
||||||
|
apiEndpoint = await createEndpoint("/admin/forcesync");
|
||||||
|
method = "POST";
|
||||||
|
includeValueInBody = true;
|
||||||
|
break;
|
||||||
|
case "addpeer":
|
||||||
|
apiEndpoint = await createEndpoint("/peers");
|
||||||
|
method = "POST";
|
||||||
|
includeValueInBody = true;
|
||||||
|
break;
|
||||||
|
case "removepeer":
|
||||||
|
apiEndpoint = await createEndpoint("/peers");
|
||||||
|
method = "DELETE";
|
||||||
|
includeValueInBody = true;
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
throw new Error(`Unknown admin action type: ${data.type}`);
|
throw new Error(`Unknown admin action type: ${data.type}`);
|
||||||
}
|
}
|
||||||
|
// Prepare the permission prompt text
|
||||||
|
let permissionText = `Do you give this application permission to perform the admin action: ${data.type}`;
|
||||||
|
if (data.value) {
|
||||||
|
permissionText += ` with value: ${data.value}`;
|
||||||
|
}
|
||||||
|
|
||||||
const resPermission = await getUserPermission(
|
const resPermission = await getUserPermission(
|
||||||
{
|
{
|
||||||
text1: `Do you give this application permission to perform a node ${data.type}?`,
|
text1: permissionText,
|
||||||
},
|
},
|
||||||
isFromExtension
|
isFromExtension
|
||||||
);
|
);
|
||||||
const { accepted } = resPermission;
|
const { accepted } = resPermission;
|
||||||
if (accepted) {
|
if (accepted) {
|
||||||
const response = await fetch(apiEndpoint);
|
// Set up options for the API call
|
||||||
|
const options: RequestInit = {
|
||||||
|
method: method,
|
||||||
|
headers: {},
|
||||||
|
};
|
||||||
|
if (includeValueInBody) {
|
||||||
|
options.headers["Content-Type"] = "text/plain";
|
||||||
|
options.body = data.value;
|
||||||
|
}
|
||||||
|
const response = await fetch(apiEndpoint, options);
|
||||||
if (!response.ok) throw new Error("Failed to perform request");
|
if (!response.ok) throw new Error("Failed to perform request");
|
||||||
|
|
||||||
let res;
|
let res;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user