fileControlPanel inital commit

This commit is contained in:
2021-01-07 20:47:43 +01:00
parent 61cebd4052
commit 7a603d7d90
7 changed files with 15187 additions and 0 deletions

View File

@@ -0,0 +1,41 @@
import 'babel-polyfill';
export default class API {
constructor() {
this.loggedIn = false;
this.user = { };
}
csrfToken() {
return this.loggedIn ? this.user.session.csrf_token : null;
}
async apiCall(method, params) {
params = params || { };
params.csrf_token = this.csrfToken();
let response = await fetch("/api/" + method, {
method: 'post',
headers: {'Content-Type': 'application/json'},
body: JSON.stringify(params)
});
let res = await response.json();
if (!res.success && res.msg === "You are not logged in.") {
document.location.reload();
}
return res;
}
async fetchUser() {
let response = await fetch("/api/user/info");
let data = await response.json();
this.user = data["user"];
this.loggedIn = data["loggedIn"];
return data && data.success && data.loggedIn;
}
async logout() {
return this.apiCall("user/logout");
}
};

View File

@@ -0,0 +1,24 @@
import React from 'react';
import ReactDOM from 'react-dom';
import API from "../../adminPanel/src/api";
class FileControlPanel extends React.Component {
constructor(props) {
super(props);
this.api = new API();
this.state = {
loaded: false
};
}
render() {
return <></>;
}
}
ReactDOM.render(
<FileControlPanel />,
document.getElementById('root')
);