added tons of files for component functionality; manual component adding added temporarily

This commit is contained in:
Carter 2025-02-11 16:31:03 -06:00
parent 58830d480e
commit 45ff49bcea
121 changed files with 25883 additions and 65 deletions

View 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;
};
};
}

View 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 };
}