Update backend and frontend with middleware functionality
This commit is contained in:
parent
dd19222728
commit
62b0efb67f
|
@ -18,9 +18,11 @@ public static class Program
|
||||||
public static void Main(String[] args)
|
public static void Main(String[] args)
|
||||||
{
|
{
|
||||||
//Db.CreateFakeRelations();
|
//Db.CreateFakeRelations();
|
||||||
|
Watchdog.NotifyReady();
|
||||||
Db.Init();
|
Db.Init();
|
||||||
var builder = WebApplication.CreateBuilder(args);
|
var builder = WebApplication.CreateBuilder(args);
|
||||||
|
|
||||||
|
|
||||||
string vpnServerIp = "194.182.190.208";
|
string vpnServerIp = "194.182.190.208";
|
||||||
//string vpnServerIp = "127.0.0.1";
|
//string vpnServerIp = "127.0.0.1";
|
||||||
WebsocketManager.Factory = new ConnectionFactory { HostName = vpnServerIp};
|
WebsocketManager.Factory = new ConnectionFactory { HostName = vpnServerIp};
|
||||||
|
|
|
@ -34,9 +34,10 @@ public class Session : Relation<String, Int64>
|
||||||
|
|
||||||
private static String CreateToken()
|
private static String CreateToken()
|
||||||
{
|
{
|
||||||
var token = new Byte[24];
|
//var token = new Byte[24];
|
||||||
Random.Shared.NextBytes(token);
|
//Random.Shared.NextBytes(token);
|
||||||
return Convert.ToBase64String(token).Replace("/","");
|
//return Convert.ToBase64String(token).Replace("/","");
|
||||||
|
return Guid.NewGuid().ToString("N");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -190,7 +190,7 @@ public static class WebsocketManager
|
||||||
Console.WriteLine("Create new empty list for installation id " + installationId);
|
Console.WriteLine("Create new empty list for installation id " + installationId);
|
||||||
InstallationConnections[installationId] = new InstallationInfo
|
InstallationConnections[installationId] = new InstallationInfo
|
||||||
{
|
{
|
||||||
Status = -2
|
Status = -1
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -140,6 +140,7 @@ function App() {
|
||||||
locale={language}
|
locale={language}
|
||||||
defaultLocale="en"
|
defaultLocale="en"
|
||||||
>
|
>
|
||||||
|
<WebSocketContextProvider>
|
||||||
<CssBaseline />
|
<CssBaseline />
|
||||||
<Routes>
|
<Routes>
|
||||||
<Route
|
<Route
|
||||||
|
@ -149,12 +150,10 @@ function App() {
|
||||||
<Route
|
<Route
|
||||||
path="/"
|
path="/"
|
||||||
element={
|
element={
|
||||||
<WebSocketContextProvider>
|
|
||||||
<SidebarLayout
|
<SidebarLayout
|
||||||
language={language}
|
language={language}
|
||||||
onSelectLanguage={setLanguage}
|
onSelectLanguage={setLanguage}
|
||||||
/>
|
/>
|
||||||
</WebSocketContextProvider>
|
|
||||||
}
|
}
|
||||||
>
|
>
|
||||||
<Route
|
<Route
|
||||||
|
@ -173,6 +172,7 @@ function App() {
|
||||||
<Route path="ResetPassword" element={<ResetPassword />}></Route>
|
<Route path="ResetPassword" element={<ResetPassword />}></Route>
|
||||||
</Route>
|
</Route>
|
||||||
</Routes>
|
</Routes>
|
||||||
|
</WebSocketContextProvider>
|
||||||
</IntlProvider>
|
</IntlProvider>
|
||||||
</ThemeProvider>
|
</ThemeProvider>
|
||||||
);
|
);
|
||||||
|
|
|
@ -17,7 +17,6 @@ interface installationSearchProps {
|
||||||
function InstallationSearch(props: installationSearchProps) {
|
function InstallationSearch(props: installationSearchProps) {
|
||||||
const theme = useTheme();
|
const theme = useTheme();
|
||||||
const [searchTerm, setSearchTerm] = useState('');
|
const [searchTerm, setSearchTerm] = useState('');
|
||||||
|
|
||||||
const searchParams = new URLSearchParams(location.search);
|
const searchParams = new URLSearchParams(location.search);
|
||||||
const installationId = parseInt(searchParams.get('installation'));
|
const installationId = parseInt(searchParams.get('installation'));
|
||||||
|
|
||||||
|
|
|
@ -9,6 +9,8 @@ import {
|
||||||
import axiosConfig from 'src/Resources/axiosConfig';
|
import axiosConfig from 'src/Resources/axiosConfig';
|
||||||
import { I_Folder, I_Installation } from 'src/interfaces/InstallationTypes';
|
import { I_Folder, I_Installation } from 'src/interfaces/InstallationTypes';
|
||||||
import { TokenContext } from './tokenContext';
|
import { TokenContext } from './tokenContext';
|
||||||
|
import routes from '../Resources/routes.json';
|
||||||
|
import { useNavigate } from 'react-router-dom';
|
||||||
|
|
||||||
interface I_InstallationContextProviderProps {
|
interface I_InstallationContextProviderProps {
|
||||||
installations: I_Installation[];
|
installations: I_Installation[];
|
||||||
|
@ -59,7 +61,7 @@ const InstallationsContextProvider = ({
|
||||||
const [loading, setLoading] = useState(false);
|
const [loading, setLoading] = useState(false);
|
||||||
const [error, setError] = useState(false);
|
const [error, setError] = useState(false);
|
||||||
const [updated, setUpdated] = useState(false);
|
const [updated, setUpdated] = useState(false);
|
||||||
|
const navigate = useNavigate();
|
||||||
const tokencontext = useContext(TokenContext);
|
const tokencontext = useContext(TokenContext);
|
||||||
const { removeToken } = tokencontext;
|
const { removeToken } = tokencontext;
|
||||||
|
|
||||||
|
@ -73,6 +75,7 @@ const InstallationsContextProvider = ({
|
||||||
.catch((err: AxiosError) => {
|
.catch((err: AxiosError) => {
|
||||||
if (err.response && err.response.status == 401) {
|
if (err.response && err.response.status == 401) {
|
||||||
removeToken();
|
removeToken();
|
||||||
|
navigate(routes.login);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}, []);
|
}, []);
|
||||||
|
@ -86,6 +89,7 @@ const InstallationsContextProvider = ({
|
||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
if (err.response && err.response.status == 401) {
|
if (err.response && err.response.status == 401) {
|
||||||
removeToken();
|
removeToken();
|
||||||
|
navigate(routes.login);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}, []);
|
}, []);
|
||||||
|
@ -104,6 +108,7 @@ const InstallationsContextProvider = ({
|
||||||
setError(true);
|
setError(true);
|
||||||
if (error.response && error.response.status == 401) {
|
if (error.response && error.response.status == 401) {
|
||||||
removeToken();
|
removeToken();
|
||||||
|
navigate(routes.login);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
@ -134,6 +139,7 @@ const InstallationsContextProvider = ({
|
||||||
setError(true);
|
setError(true);
|
||||||
if (error.response && error.response.status == 401) {
|
if (error.response && error.response.status == 401) {
|
||||||
removeToken();
|
removeToken();
|
||||||
|
navigate(routes.login);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
@ -164,6 +170,7 @@ const InstallationsContextProvider = ({
|
||||||
setError(true);
|
setError(true);
|
||||||
if (error.response && error.response.status == 401) {
|
if (error.response && error.response.status == 401) {
|
||||||
removeToken();
|
removeToken();
|
||||||
|
navigate(routes.login);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
@ -183,6 +190,7 @@ const InstallationsContextProvider = ({
|
||||||
setError(true);
|
setError(true);
|
||||||
if (error.response && error.response.status == 401) {
|
if (error.response && error.response.status == 401) {
|
||||||
removeToken();
|
removeToken();
|
||||||
|
navigate(routes.login);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}, []);
|
}, []);
|
||||||
|
@ -206,6 +214,7 @@ const InstallationsContextProvider = ({
|
||||||
setError(true);
|
setError(true);
|
||||||
if (error.response && error.response.status == 401) {
|
if (error.response && error.response.status == 401) {
|
||||||
removeToken();
|
removeToken();
|
||||||
|
navigate(routes.login);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}, []);
|
}, []);
|
||||||
|
@ -229,6 +238,7 @@ const InstallationsContextProvider = ({
|
||||||
setError(true);
|
setError(true);
|
||||||
if (error.response && error.response.status == 401) {
|
if (error.response && error.response.status == 401) {
|
||||||
removeToken();
|
removeToken();
|
||||||
|
navigate(routes.login);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}, []);
|
}, []);
|
||||||
|
|
|
@ -54,7 +54,7 @@ const WebSocketContextProvider = ({ children }: { children: ReactNode }) => {
|
||||||
const installation_id = message.id;
|
const installation_id = message.id;
|
||||||
const status = message.status;
|
const status = message.status;
|
||||||
|
|
||||||
//console.log('Message from server ', installation_id, status);
|
console.log('Message from server ', installation_id, status);
|
||||||
|
|
||||||
setInstallationStatus((prevStatus) => {
|
setInstallationStatus((prevStatus) => {
|
||||||
// Create a new object by spreading the previous state
|
// Create a new object by spreading the previous state
|
||||||
|
@ -89,34 +89,9 @@ const WebSocketContextProvider = ({ children }: { children: ReactNode }) => {
|
||||||
let status;
|
let status;
|
||||||
if (!installationStatus.hasOwnProperty(installationId)) {
|
if (!installationStatus.hasOwnProperty(installationId)) {
|
||||||
status = -2;
|
status = -2;
|
||||||
} else {
|
|
||||||
let i = 0;
|
|
||||||
//If at least one status value shows an error, then show error
|
|
||||||
for (i; i < installationStatus[installationId].length; i++) {
|
|
||||||
if (installationStatus[installationId][i] === 2) {
|
|
||||||
status = 2;
|
|
||||||
return status;
|
|
||||||
}
|
|
||||||
if (installationStatus[installationId][i] === 1) {
|
|
||||||
status = 1;
|
|
||||||
return status;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (installationStatus[installationId][0] == -1) {
|
|
||||||
let i = 0;
|
|
||||||
for (i; i < installationStatus[installationId].length; i++) {
|
|
||||||
if (installationStatus[installationId][i] != -1) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (i === installationStatus[installationId].length) {
|
|
||||||
status = -1;
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
status = installationStatus[installationId][0];
|
status = installationStatus[installationId][0];
|
||||||
}
|
}
|
||||||
}
|
|
||||||
return status;
|
return status;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue