cabana/src/index.js

104 lines
3.2 KiB
JavaScript
Raw Normal View History

2017-12-12 19:24:01 -07:00
import Sentry from "./logging/Sentry";
import React from "react";
import ReactDOM from "react-dom";
2019-06-14 15:39:49 -06:00
import CommaAuth from "@commaai/my-comma-auth";
import { request as Request } from "@commaai/comma-api";
2017-12-12 19:24:01 -07:00
import CanExplorer from "./CanExplorer";
import AcuraDbc from "./acura-dbc";
import { getUrlParameter, modifyQueryParameters } from "./utils/url";
import { GITHUB_AUTH_TOKEN_KEY } from "./config";
import {
fetchPersistedDbc,
fetchPersistedGithubAuthToken,
persistGithubAuthToken
} from "./api/localstorage";
import "./index.css";
2017-06-28 15:28:45 -06:00
2017-12-12 19:24:01 -07:00
Sentry.init();
2017-12-12 19:24:01 -07:00
const routeFullName = getUrlParameter("route");
let isDemo = !routeFullName;
let props = { autoplay: true, isDemo };
2017-08-03 15:41:52 -06:00
let persistedDbc = null;
if (routeFullName) {
2017-12-12 19:24:01 -07:00
const [dongleId, route] = routeFullName.split("|");
props.dongleId = dongleId;
props.name = route;
2017-12-12 19:24:01 -07:00
persistedDbc = fetchPersistedDbc(routeFullName);
2017-12-12 19:24:01 -07:00
let max = getUrlParameter("max"),
url = getUrlParameter("url");
2019-06-14 15:39:49 -06:00
if (max) {
2017-12-12 19:24:01 -07:00
props.max = max;
2019-06-14 15:39:49 -06:00
}
if (url) {
2017-12-12 19:24:01 -07:00
props.url = url;
}
2019-06-14 15:39:49 -06:00
props.isShare = max && url;
2017-12-12 19:24:01 -07:00
} else if (getUrlParameter("demo")) {
2017-11-06 18:52:43 -07:00
props.max = 12;
2017-12-12 19:24:01 -07:00
props.url =
2019-06-18 13:33:50 -06:00
"https://chffrprivate.blob.core.windows.net/chffrprivate3-permanent/v2/cb38263377b873ee/78392b99580c5920227cc5b43dff8a70_2017-06-12--18-51-47";
2018-05-10 11:24:31 -06:00
props.name = "2017-06-12--18-51-47";
2017-12-12 19:24:01 -07:00
props.dongleId = "cb38263377b873ee";
props.dbc = AcuraDbc;
2018-05-09 12:06:52 -06:00
props.isDemo = true;
2017-12-12 19:24:01 -07:00
props.dbcFilename = "acura_ilx_2016_can.dbc";
// lots of 404s on this one
// props.max = 752;
// props.url = 'https://chffrprivate.blob.core.windows.net/chffrprivate3/v2/07e243287e48432a/d97fcc321a58e660a14de72b749269ba_2017-09-09--22-00-00';
// props.name = '2017-09-09--22-00-00';
// props.dongleId = '07e243287e48432a';
// props.dbc = AcuraDbc;
// props.dbcFilename = 'acura_ilx_2016_can.dbc';
// really long one with real content
// props.max = 597;
// props.url = 'https://chffrprivate.blob.core.windows.net/chffrprivate3/v2/0c249898b339e978/957935e6a75bc2bf6f626fcbe6db93ba_2017-08-11--04-47-54';
// props.name = '2017-08-11--04-47-54';
// props.dongleId = '0c249898b339e978';
// props.dbc = AcuraDbc;
// props.dbcFilename = 'acura_ilx_2016_can.dbc';
2017-06-27 17:56:24 -06:00
}
if (persistedDbc) {
2017-12-12 19:24:01 -07:00
const { dbcFilename, dbc } = persistedDbc;
2017-08-03 15:41:52 -06:00
props.dbc = dbc;
props.dbcFilename = dbcFilename;
}
const authTokenQueryParam = getUrlParameter(GITHUB_AUTH_TOKEN_KEY);
if (authTokenQueryParam !== null) {
props.githubAuthToken = authTokenQueryParam;
persistGithubAuthToken(authTokenQueryParam);
2017-12-12 19:24:01 -07:00
const urlNoAuthToken = modifyQueryParameters({
remove: [GITHUB_AUTH_TOKEN_KEY]
});
window.location.href = urlNoAuthToken;
} else {
props.githubAuthToken = fetchPersistedGithubAuthToken();
}
2019-06-14 15:39:49 -06:00
async function init() {
const token = await CommaAuth.init();
if (token) {
Request.configure(token);
}
2017-12-12 19:24:01 -07:00
ReactDOM.render(<CanExplorer {...props} />, document.getElementById("root"));
2019-06-14 15:39:49 -06:00
}
if (routeFullName || isDemo) {
init();
2017-07-02 20:15:43 -06:00
} else {
2017-12-12 19:24:01 -07:00
const img = document.createElement("img");
img.src = process.env.PUBLIC_URL + "/img/cabana.jpg";
img.style.width = "100%";
const comment = document.createComment("7/6/17");
2017-07-02 20:15:43 -06:00
2017-12-12 19:24:01 -07:00
document.getElementById("root").appendChild(img);
document.getElementById("root").appendChild(comment);
2017-08-03 15:41:52 -06:00
}