diff --git a/backend/classes/emby-api.js b/backend/classes/emby-api.js
index 98836df..a56df89 100644
--- a/backend/classes/emby-api.js
+++ b/backend/classes/emby-api.js
@@ -104,8 +104,8 @@ class EmbyAPI {
//Functions
- async getUsers() {
- if (!this.configReady) {
+ async getUsers(refreshConfig = false) {
+ if (!this.configReady || refreshConfig) {
const success = await this.#fetchConfig();
if (!success) {
return [];
@@ -133,9 +133,9 @@ class EmbyAPI {
}
}
- async getAdmins() {
+ async getAdmins(refreshConfig = false) {
try {
- const users = await this.getUsers();
+ const users = await this.getUsers(refreshConfig);
return users?.filter((user) => user.Policy.IsAdministrator) || [];
} catch (error) {
this.#errorHandler(error);
diff --git a/backend/classes/jellyfin-api.js b/backend/classes/jellyfin-api.js
index cf52917..81e244b 100644
--- a/backend/classes/jellyfin-api.js
+++ b/backend/classes/jellyfin-api.js
@@ -105,8 +105,8 @@ class JellyfinAPI {
//Functions
- async getUsers() {
- if (!this.configReady) {
+ async getUsers(refreshConfig = false) {
+ if (!this.configReady || refreshConfig) {
const success = await this.#fetchConfig();
if (!success) {
return [];
@@ -133,9 +133,9 @@ class JellyfinAPI {
}
}
- async getAdmins() {
+ async getAdmins(refreshConfig = false) {
try {
- const users = await this.getUsers();
+ const users = await this.getUsers(refreshConfig);
return users?.filter((user) => user.Policy.IsAdministrator) || [];
} catch (error) {
this.#errorHandler(error);
diff --git a/backend/routes/api.js b/backend/routes/api.js
index 4c1862b..7cbe0f5 100644
--- a/backend/routes/api.js
+++ b/backend/routes/api.js
@@ -463,7 +463,24 @@ router.post("/setconfig", async (req, res) => {
settings.ServerID = systemInfo?.Id || null;
- let query = 'UPDATE app_config SET settings=$1 where "ID"=1';
+ const query = 'UPDATE app_config SET settings=$1 where "ID"=1';
+
+ await db.query(query, [settings]);
+ }
+ }
+
+ const admins = await API.getAdmins(true);
+ const preferredAdmin = await new configClass().getPreferedAdmin();
+ if (admins && admins.length > 0 && preferredAdmin && !admins.map((item) => item.Id).includes(preferredAdmin)) {
+ const newAdmin = admins[0];
+ const settingsjson = await db.query('SELECT settings FROM app_config where "ID"=1').then((res) => res.rows);
+
+ if (settingsjson.length > 0) {
+ const settings = settingsjson[0].settings || {};
+
+ settings.preferred_admin = { userid: newAdmin.Id, username: newAdmin.Name };
+
+ const query = 'UPDATE app_config SET settings=$1 where "ID"=1';
await db.query(query, [settings]);
}
diff --git a/backend/routes/proxy.js b/backend/routes/proxy.js
index 18fdf1f..61a4c28 100644
--- a/backend/routes/proxy.js
+++ b/backend/routes/proxy.js
@@ -148,7 +148,7 @@ router.get("/getSessions", async (req, res) => {
router.get("/getAdminUsers", async (req, res) => {
try {
- const adminUser = await API.getAdmins();
+ const adminUser = await API.getAdmins(true);
res.send(adminUser);
} catch (error) {
res.status(503);
diff --git a/src/pages/components/settings/settingsConfig.jsx b/src/pages/components/settings/settingsConfig.jsx
index fe6dce5..6fe7a71 100644
--- a/src/pages/components/settings/settingsConfig.jsx
+++ b/src/pages/components/settings/settingsConfig.jsx
@@ -44,6 +44,20 @@ export default function SettingsConfig() {
set12hr(Boolean(storage_12hr));
}
+ const fetchAdmins = async () => {
+ try {
+ const adminData = await axios.get(`/proxy/getAdminUsers`, {
+ headers: {
+ Authorization: `Bearer ${token}`,
+ "Content-Type": "application/json",
+ },
+ });
+ setAdmins(adminData.data);
+ } catch (error) {
+ console.log(error);
+ }
+ };
+
useEffect(() => {
Config.getConfig()
.then((config) => {
@@ -59,20 +73,6 @@ export default function SettingsConfig() {
setsubmissionMessage("Error Retrieving Configuration. Unable to contact Backend Server");
});
- const fetchAdmins = async () => {
- try {
- const adminData = await axios.get(`/proxy/getAdminUsers`, {
- headers: {
- Authorization: `Bearer ${token}`,
- "Content-Type": "application/json",
- },
- });
- setAdmins(adminData.data);
- } catch (error) {
- console.log(error);
- }
- };
-
fetchAdmins();
}, [token]);
@@ -91,6 +91,8 @@ export default function SettingsConfig() {
console.log("Config updated successfully:", response.data);
setisSubmitted("Success");
setsubmissionMessage("Successfully updated configuration");
+ Config.setConfig();
+ fetchAdmins();
})
.catch((error) => {
let errorMessage = error.response.data.errorMessage;
@@ -98,7 +100,6 @@ export default function SettingsConfig() {
setisSubmitted("Failed");
setsubmissionMessage(`Error Updating Configuration: ${errorMessage}`);
});
- Config.setConfig();
}
async function handleFormSubmitExternal(event) {
@@ -233,9 +234,13 @@ export default function SettingsConfig() {
{isSubmitted !== "" ? (
isSubmitted === "Failed" ? (
- {submissionMessage}
+
+ {submissionMessage}
+
) : (
- {submissionMessage}
+
+ {submissionMessage}
+
)
) : (
<>>
@@ -265,9 +270,13 @@ export default function SettingsConfig() {
{isSubmittedExternal !== "" ? (
isSubmittedExternal === "Failed" ? (
- {submissionMessageExternal}
+
+ {submissionMessageExternal}
+
) : (
- {submissionMessageExternal}
+
+ {submissionMessageExternal}
+
)
) : (
<>>