added tons of files for component functionality; manual component adding added temporarily
This commit is contained in:
parent
58830d480e
commit
45ff49bcea
121 changed files with 25883 additions and 65 deletions
61
src/services/cache.js
Normal file
61
src/services/cache.js
Normal file
|
|
@ -0,0 +1,61 @@
|
|||
import {
|
||||
defaultOptions,
|
||||
get as apiGet,
|
||||
put as apiPut,
|
||||
post as apiPost,
|
||||
del as apiDel
|
||||
} from "./restAPI.js";
|
||||
|
||||
var cache = sessionStorage;
|
||||
|
||||
function key(url, data = {}) {
|
||||
return JSON.stringify({ url: url, data: data });
|
||||
}
|
||||
|
||||
export function get(url, options = defaultOptions) {
|
||||
let k = key(url);
|
||||
let cached = cache.getItem(k);
|
||||
if (cached !== null) {
|
||||
return Promise.resolve(JSON.parse(cached));
|
||||
}
|
||||
return apiGet(url, options).then(result => {
|
||||
cache.setItem(k, JSON.stringify(result));
|
||||
return result;
|
||||
});
|
||||
}
|
||||
|
||||
export function put(url, data, options = defaultOptions) {
|
||||
let k = key(url, data);
|
||||
let cached = cache.getItem(k);
|
||||
if (cached !== null) {
|
||||
return Promise.resolve(JSON.parse(cached));
|
||||
}
|
||||
return apiPut(url, data, options).then(result => {
|
||||
cache.setItem(k, JSON.stringify(result));
|
||||
return result;
|
||||
});
|
||||
}
|
||||
|
||||
export function post(url, data, options = defaultOptions) {
|
||||
let k = key(url, data);
|
||||
let cached = cache.getItem(k);
|
||||
if (cached !== null) {
|
||||
return Promise.resolve(JSON.parse(cached));
|
||||
}
|
||||
return apiPost(url, data, options).then(result => {
|
||||
cache.setItem(k, JSON.stringify(result));
|
||||
return result;
|
||||
});
|
||||
}
|
||||
|
||||
export function del(url, options = defaultOptions) {
|
||||
let k = key(url);
|
||||
let cached = cache.getItem(k);
|
||||
if (cached !== null) {
|
||||
return Promise.resolve(JSON.parse(cached));
|
||||
}
|
||||
return apiDel(url, options).then(result => {
|
||||
cache.setItem(k, JSON.stringify(result));
|
||||
return result;
|
||||
});
|
||||
}
|
||||
13
src/services/feature/service.ts
Normal file
13
src/services/feature/service.ts
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
import { pond } from "protobuf-ts/pond";
|
||||
|
||||
const restrictions = new Map<pond.UpgradeChannel, string[]>([
|
||||
[pond.UpgradeChannel.UPGRADE_CHANNEL_DEVELOPMENT, ["better-controls", "wifi-creds"]],
|
||||
[pond.UpgradeChannel.UPGRADE_CHANNEL_ALPHA, ["better-controls", "wifi-creds"]],
|
||||
[pond.UpgradeChannel.UPGRADE_CHANNEL_BETA, ["better-controls", "wifi-creds"]],
|
||||
[pond.UpgradeChannel.UPGRADE_CHANNEL_STABLE, ["better-controls", "wifi-creds"]]
|
||||
]);
|
||||
|
||||
export function hasDeviceFeature(channel: pond.UpgradeChannel, feature: string) {
|
||||
const features = restrictions.get(channel);
|
||||
return features ? features.includes(feature) : false;
|
||||
}
|
||||
44
src/services/google/googleAPI.ts
Normal file
44
src/services/google/googleAPI.ts
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
// @ts-ignore
|
||||
import { get, post } from "services/cache";
|
||||
|
||||
function url(api: string): string {
|
||||
return "https://www.googleapis.com/" + api + "?key=" + process.env.REACT_APP_GOOGLE_API_KEY;
|
||||
}
|
||||
|
||||
export function geolocate(data: unknown) {
|
||||
return post(url("geolocation/v1/geolocate"), data);
|
||||
}
|
||||
|
||||
//gets a YouTube playlist
|
||||
export function getPlaylist(playlistID: string) {
|
||||
return get(
|
||||
url("youtube/v3/playlistItems") + "&part=snippet&playlistId=" + playlistID + "&maxResults=50"
|
||||
);
|
||||
}
|
||||
|
||||
interface Thumbnail {
|
||||
url: string;
|
||||
width: number;
|
||||
height: number;
|
||||
}
|
||||
|
||||
export interface YouTubePlaylistItem {
|
||||
snippet: {
|
||||
title: string;
|
||||
description: string;
|
||||
resourceId: {
|
||||
kind: string;
|
||||
videoId: string;
|
||||
};
|
||||
channelTitle: string;
|
||||
publishedAt: string;
|
||||
position: number;
|
||||
thumbnails: {
|
||||
default: Thumbnail;
|
||||
medium: Thumbnail;
|
||||
high: Thumbnail;
|
||||
standard: Thumbnail;
|
||||
maxres: Thumbnail;
|
||||
};
|
||||
};
|
||||
}
|
||||
38
src/services/google/mapHelpers.ts
Normal file
38
src/services/google/mapHelpers.ts
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
import { or } from "utils/types";
|
||||
|
||||
function decode(encoded: string) {
|
||||
let bytes = atob(encoded);
|
||||
let res = "";
|
||||
for (let i = 0; i < bytes.length; i++) {
|
||||
var val = bytes.charCodeAt(i).toString(16);
|
||||
res += val.length === 2 ? val : "0" + val;
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
export function parseGPS(gps: { location: any; latitude: number; longitude: number; uncertainty: number; wifiAccessPoints: any[]; cellTower: any; }) {
|
||||
gps = or(gps, {});
|
||||
let lat = 0;
|
||||
let lng = 0;
|
||||
let accuracy = 0;
|
||||
let request: { wifiAccessPoints?: any; cellTowers?: any; } | undefined = undefined;
|
||||
if (gps.location) {
|
||||
lat = gps.latitude;
|
||||
lng = gps.longitude;
|
||||
accuracy = gps.uncertainty;
|
||||
} else if (gps.wifiAccessPoints) {
|
||||
request = { wifiAccessPoints: [] };
|
||||
gps.wifiAccessPoints.forEach(function(ap) {
|
||||
request?.wifiAccessPoints.push({
|
||||
macAddress: decode(ap.mac),
|
||||
signalStrength: ap.signalStrength,
|
||||
channel: ap.channel
|
||||
});
|
||||
});
|
||||
} else if (gps.cellTower) {
|
||||
request = { cellTowers: [] };
|
||||
request.cellTowers.push(gps.cellTower);
|
||||
}
|
||||
|
||||
return { request, lat, lng, accuracy };
|
||||
}
|
||||
23
src/services/restAPI.js
Normal file
23
src/services/restAPI.js
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
import * as axios from "axios";
|
||||
|
||||
export var defaultOptions = {
|
||||
headers: {
|
||||
"Content-Type": "application/json"
|
||||
}
|
||||
};
|
||||
|
||||
export function get(url, options = defaultOptions) {
|
||||
return axios.get(url, options);
|
||||
}
|
||||
|
||||
export function put(url, data, options = defaultOptions) {
|
||||
return axios.put(url, data, options);
|
||||
}
|
||||
|
||||
export function post(url, data, options = defaultOptions) {
|
||||
return axios.post(url, data, options);
|
||||
}
|
||||
|
||||
export function del(url, options = defaultOptions) {
|
||||
return axios.delete(url, options);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue