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)
|
||||
{
|
||||
//Db.CreateFakeRelations();
|
||||
Watchdog.NotifyReady();
|
||||
Db.Init();
|
||||
var builder = WebApplication.CreateBuilder(args);
|
||||
|
||||
|
||||
string vpnServerIp = "194.182.190.208";
|
||||
//string vpnServerIp = "127.0.0.1";
|
||||
WebsocketManager.Factory = new ConnectionFactory { HostName = vpnServerIp};
|
||||
|
|
|
@ -34,9 +34,10 @@ public class Session : Relation<String, Int64>
|
|||
|
||||
private static String CreateToken()
|
||||
{
|
||||
var token = new Byte[24];
|
||||
Random.Shared.NextBytes(token);
|
||||
return Convert.ToBase64String(token).Replace("/","");
|
||||
//var token = new Byte[24];
|
||||
//Random.Shared.NextBytes(token);
|
||||
//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);
|
||||
InstallationConnections[installationId] = new InstallationInfo
|
||||
{
|
||||
Status = -2
|
||||
Status = -1
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -140,39 +140,39 @@ function App() {
|
|||
locale={language}
|
||||
defaultLocale="en"
|
||||
>
|
||||
<CssBaseline />
|
||||
<Routes>
|
||||
<Route
|
||||
path={''}
|
||||
element={<Navigate to={routes.installations}></Navigate>}
|
||||
></Route>
|
||||
<Route
|
||||
path="/"
|
||||
element={
|
||||
<WebSocketContextProvider>
|
||||
<WebSocketContextProvider>
|
||||
<CssBaseline />
|
||||
<Routes>
|
||||
<Route
|
||||
path={''}
|
||||
element={<Navigate to={routes.installations}></Navigate>}
|
||||
></Route>
|
||||
<Route
|
||||
path="/"
|
||||
element={
|
||||
<SidebarLayout
|
||||
language={language}
|
||||
onSelectLanguage={setLanguage}
|
||||
/>
|
||||
</WebSocketContextProvider>
|
||||
}
|
||||
>
|
||||
<Route
|
||||
path={routes.installations + '*'}
|
||||
element={
|
||||
<AccessContextProvider>
|
||||
<InstallationsContextProvider>
|
||||
<InstallationTabs />
|
||||
</InstallationsContextProvider>
|
||||
</AccessContextProvider>
|
||||
}
|
||||
/>
|
||||
>
|
||||
<Route
|
||||
path={routes.installations + '*'}
|
||||
element={
|
||||
<AccessContextProvider>
|
||||
<InstallationsContextProvider>
|
||||
<InstallationTabs />
|
||||
</InstallationsContextProvider>
|
||||
</AccessContextProvider>
|
||||
}
|
||||
/>
|
||||
|
||||
<Route path={routes.users + '*'} element={<Users />} />
|
||||
<Route path={routes.users + '*'} element={<Users />} />
|
||||
|
||||
<Route path="ResetPassword" element={<ResetPassword />}></Route>
|
||||
</Route>
|
||||
</Routes>
|
||||
<Route path="ResetPassword" element={<ResetPassword />}></Route>
|
||||
</Route>
|
||||
</Routes>
|
||||
</WebSocketContextProvider>
|
||||
</IntlProvider>
|
||||
</ThemeProvider>
|
||||
);
|
||||
|
|
|
@ -17,7 +17,6 @@ interface installationSearchProps {
|
|||
function InstallationSearch(props: installationSearchProps) {
|
||||
const theme = useTheme();
|
||||
const [searchTerm, setSearchTerm] = useState('');
|
||||
|
||||
const searchParams = new URLSearchParams(location.search);
|
||||
const installationId = parseInt(searchParams.get('installation'));
|
||||
|
||||
|
|
|
@ -9,6 +9,8 @@ import {
|
|||
import axiosConfig from 'src/Resources/axiosConfig';
|
||||
import { I_Folder, I_Installation } from 'src/interfaces/InstallationTypes';
|
||||
import { TokenContext } from './tokenContext';
|
||||
import routes from '../Resources/routes.json';
|
||||
import { useNavigate } from 'react-router-dom';
|
||||
|
||||
interface I_InstallationContextProviderProps {
|
||||
installations: I_Installation[];
|
||||
|
@ -59,7 +61,7 @@ const InstallationsContextProvider = ({
|
|||
const [loading, setLoading] = useState(false);
|
||||
const [error, setError] = useState(false);
|
||||
const [updated, setUpdated] = useState(false);
|
||||
|
||||
const navigate = useNavigate();
|
||||
const tokencontext = useContext(TokenContext);
|
||||
const { removeToken } = tokencontext;
|
||||
|
||||
|
@ -73,6 +75,7 @@ const InstallationsContextProvider = ({
|
|||
.catch((err: AxiosError) => {
|
||||
if (err.response && err.response.status == 401) {
|
||||
removeToken();
|
||||
navigate(routes.login);
|
||||
}
|
||||
});
|
||||
}, []);
|
||||
|
@ -86,6 +89,7 @@ const InstallationsContextProvider = ({
|
|||
.catch((err) => {
|
||||
if (err.response && err.response.status == 401) {
|
||||
removeToken();
|
||||
navigate(routes.login);
|
||||
}
|
||||
});
|
||||
}, []);
|
||||
|
@ -104,6 +108,7 @@ const InstallationsContextProvider = ({
|
|||
setError(true);
|
||||
if (error.response && error.response.status == 401) {
|
||||
removeToken();
|
||||
navigate(routes.login);
|
||||
}
|
||||
});
|
||||
},
|
||||
|
@ -134,6 +139,7 @@ const InstallationsContextProvider = ({
|
|||
setError(true);
|
||||
if (error.response && error.response.status == 401) {
|
||||
removeToken();
|
||||
navigate(routes.login);
|
||||
}
|
||||
});
|
||||
},
|
||||
|
@ -164,6 +170,7 @@ const InstallationsContextProvider = ({
|
|||
setError(true);
|
||||
if (error.response && error.response.status == 401) {
|
||||
removeToken();
|
||||
navigate(routes.login);
|
||||
}
|
||||
});
|
||||
},
|
||||
|
@ -183,6 +190,7 @@ const InstallationsContextProvider = ({
|
|||
setError(true);
|
||||
if (error.response && error.response.status == 401) {
|
||||
removeToken();
|
||||
navigate(routes.login);
|
||||
}
|
||||
});
|
||||
}, []);
|
||||
|
@ -206,6 +214,7 @@ const InstallationsContextProvider = ({
|
|||
setError(true);
|
||||
if (error.response && error.response.status == 401) {
|
||||
removeToken();
|
||||
navigate(routes.login);
|
||||
}
|
||||
});
|
||||
}, []);
|
||||
|
@ -229,6 +238,7 @@ const InstallationsContextProvider = ({
|
|||
setError(true);
|
||||
if (error.response && error.response.status == 401) {
|
||||
removeToken();
|
||||
navigate(routes.login);
|
||||
}
|
||||
});
|
||||
}, []);
|
||||
|
|
|
@ -54,7 +54,7 @@ const WebSocketContextProvider = ({ children }: { children: ReactNode }) => {
|
|||
const installation_id = message.id;
|
||||
const status = message.status;
|
||||
|
||||
//console.log('Message from server ', installation_id, status);
|
||||
console.log('Message from server ', installation_id, status);
|
||||
|
||||
setInstallationStatus((prevStatus) => {
|
||||
// Create a new object by spreading the previous state
|
||||
|
@ -90,32 +90,7 @@ const WebSocketContextProvider = ({ children }: { children: ReactNode }) => {
|
|||
if (!installationStatus.hasOwnProperty(installationId)) {
|
||||
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 {
|
||||
status = installationStatus[installationId][0];
|
||||
}
|
||||
status = installationStatus[installationId][0];
|
||||
}
|
||||
return status;
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue