feat: Projekt von JavaScript zu TypeScript migriert
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
function decodeToken(token) {
|
||||
function decodeToken(token: string) {
|
||||
try {
|
||||
const base64Payload = token.split(".")[1];
|
||||
const payload = JSON.parse(atob(base64Payload));
|
||||
@@ -1,7 +1,11 @@
|
||||
// utils/loadWindowVariables.js
|
||||
export async function loadWindowVariables() {
|
||||
// utils/loadWindowVariables.ts
|
||||
interface WindowVariables {
|
||||
[key: string]: any; // Allgemeiner Typ für die Dynamik, kann spezifischer angepasst werden, falls bekannt
|
||||
}
|
||||
|
||||
export async function loadWindowVariables(): Promise<WindowVariables> {
|
||||
return new Promise((resolve, reject) => {
|
||||
const requiredVars = [
|
||||
const requiredVars: string[] = [
|
||||
"win_last20Messages",
|
||||
"win_deviceName",
|
||||
"win_mac1",
|
||||
@@ -52,7 +56,7 @@ export async function loadWindowVariables() {
|
||||
"win_analogeEingaenge8",
|
||||
];
|
||||
|
||||
const loadScript = (src) => {
|
||||
const loadScript = (src: string): Promise<void> => {
|
||||
return new Promise((resolve, reject) => {
|
||||
const script = document.createElement("script");
|
||||
const environment = process.env.NEXT_PUBLIC_NODE_ENV || "production";
|
||||
@@ -61,13 +65,19 @@ export async function loadWindowVariables() {
|
||||
? `/CPL?/CPL/SERVICE/${src}`
|
||||
: `/CPLmockData/SERVICE/${src}`;
|
||||
script.async = true;
|
||||
script.onload = resolve;
|
||||
script.onerror = reject;
|
||||
script.onload = () => resolve();
|
||||
script.onerror = () => reject(new Error(`Script load error: ${src}`));
|
||||
document.head.appendChild(script);
|
||||
});
|
||||
};
|
||||
|
||||
const scripts = ["de.js", "ae.js", "kueData.js", "Start.js", "System.js"];
|
||||
const scripts: string[] = [
|
||||
"de.js",
|
||||
"ae.js",
|
||||
"kueData.js",
|
||||
"Start.js",
|
||||
"System.js",
|
||||
];
|
||||
|
||||
scripts
|
||||
.reduce(
|
||||
@@ -75,19 +85,24 @@ export async function loadWindowVariables() {
|
||||
Promise.resolve()
|
||||
)
|
||||
.then(() => {
|
||||
const variablesObj = requiredVars.reduce((acc, variable) => {
|
||||
if (window[variable] !== undefined) {
|
||||
// Wenn es sich um kueID handelt, ersetze %20 durch Leerzeichen
|
||||
if (variable === "win_kueID" && Array.isArray(window[variable])) {
|
||||
acc[variable.replace("win_", "")] = window[variable].map((id) =>
|
||||
id.replace(/%20/g, " ")
|
||||
);
|
||||
} else {
|
||||
acc[variable.replace("win_", "")] = window[variable];
|
||||
const variablesObj: WindowVariables = requiredVars.reduce(
|
||||
(acc: WindowVariables, variable: string) => {
|
||||
// Prüfe, ob die Variable auf dem window-Objekt existiert
|
||||
const winVar = (window as any)[variable];
|
||||
if (winVar !== undefined) {
|
||||
// Wenn es sich um kueID handelt, ersetze %20 durch Leerzeichen
|
||||
if (variable === "win_kueID" && Array.isArray(winVar)) {
|
||||
acc[variable.replace("win_", "")] = winVar.map((id: string) =>
|
||||
id.replace(/%20/g, " ")
|
||||
);
|
||||
} else {
|
||||
acc[variable.replace("win_", "")] = winVar;
|
||||
}
|
||||
}
|
||||
}
|
||||
return acc;
|
||||
}, {});
|
||||
return acc;
|
||||
},
|
||||
{}
|
||||
);
|
||||
resolve(variablesObj);
|
||||
})
|
||||
.catch((error) => {
|
||||
Reference in New Issue
Block a user