Initial commit
This commit is contained in:
46
src/Api/ConvertBackendCalls.tsx
Executable file
46
src/Api/ConvertBackendCalls.tsx
Executable file
@@ -0,0 +1,46 @@
|
||||
import axios, { AxiosError } from "axios";
|
||||
import type { ConvertSchema } from "Types/ApiCalls/ConvertBackendCallsTypes";
|
||||
|
||||
const openbableBackendRoot = "http://localhost:1654";
|
||||
|
||||
export async function ConvertMoleculeToStandart(
|
||||
data: ConvertSchema,
|
||||
): Promise<string | AxiosError> {
|
||||
try {
|
||||
const response = await axios.post(openbableBackendRoot + "/convert", {
|
||||
text: data.inputText,
|
||||
format: data.inputFormat,
|
||||
convert_3d: data.make_3d,
|
||||
add_hydrogen: data.add_h,
|
||||
optimize_geometry: data.optimize,
|
||||
});
|
||||
|
||||
// Response from the FastAPI JSONResponse
|
||||
return response.data.molfile;
|
||||
} catch (error) {
|
||||
//Error handling
|
||||
if (axios.isAxiosError(error)) {
|
||||
// Do something with the axios error...
|
||||
return error;
|
||||
} else {
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export async function GetInFormats(): Promise<
|
||||
{ [key: string]: string } | AxiosError
|
||||
> {
|
||||
try {
|
||||
const response = await axios.get(openbableBackendRoot + "/informats");
|
||||
return response.data;
|
||||
} catch (error) {
|
||||
//Error handling
|
||||
if (axios.isAxiosError(error)) {
|
||||
// Do something with the axios error...
|
||||
return error;
|
||||
} else {
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
}
|
||||
28
src/Api/Keycloak/Keycloak.tsx
Normal file
28
src/Api/Keycloak/Keycloak.tsx
Normal file
@@ -0,0 +1,28 @@
|
||||
import axios from "axios";
|
||||
import { keycloakURI } from "GlobalVars";
|
||||
import Keycloak from "keycloak-js";
|
||||
|
||||
const keycloak = new Keycloak({
|
||||
url: keycloakURI,
|
||||
realm: "dev-realm",
|
||||
clientId: "react-frontend",
|
||||
});
|
||||
|
||||
const api = axios.create({
|
||||
baseURL: `${keycloak.authServerUrl}/realms/${keycloak.realm}`,
|
||||
});
|
||||
|
||||
export default keycloak;
|
||||
|
||||
export async function getProfile(keycloak: Keycloak) {
|
||||
return keycloak.loadUserProfile();
|
||||
}
|
||||
|
||||
export const handleSubmit = async (profile) => {
|
||||
try {
|
||||
await api.put("/account", profile);
|
||||
alert("Profile updated!");
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user