A rewrite of Poly+, my quality-of-life browser extension for Polytoria. Built entirely fresh using the WXT extension framework, Typescript, and with added better overall code quality.
extension

minor: restructure API utility functions

Index b80e7949 d5f042b6

Changed files
+5 -27
entrypoints
utils
+3 -3
entrypoints/home.content.ts
···
import { preferences, _favoritedPlaces, _bestFriends } from "@/utils/storage";
import { placeApiSchema, userApiSchema } from "@/utils/types";
import { pullCache } from "@/utils/utilities";
-
import api from "@/utils/api";
+
import * as api from "@/utils/api";
export default defineContentScript({
matches: ['https://polytoria.com/', 'https://polytoria.com/home'],
···
const placeData: Array<placeApiSchema> = await pullCache(
'favoritedPlaces',
-
async () => await api.places.batch!(places as string[]),
+
async () => await api.batch('/places/', places),
300000,
false
);
···
.then(async (friends) => {
const userData = await pullCache(
'bestFriends',
-
async () => await api.users.batch!(friends as string[]),
+
async () => await api.batch('/users/', friends),
300000,
false
);
+2 -24
utils/api.ts
···
import config from "./config.json";
import { userApiSchema, placeApiSchema } from "./types";
-
const users: {
-
batch?: (ids: string[]) => Promise<Record<string, userApiSchema>>
-
} = {};
-
-
const places: {
-
batch?: (ids: string[]) => Promise<Record<string, placeApiSchema>>
-
} = {};
-
-
users.batch = async (ids: string[]): Promise<Record<string, userApiSchema>> => {
+
export async function batch(path: string, ids: string[]): Promise<any> {
const res: Record<string, userApiSchema> = {};
for (let id of ids) {
-
const info = await (await fetch(config.api.url + '/users/' + id)).json();
-
res[id] = info;
-
}
-
return res;
-
};
-
-
places.batch = async (ids: string[]): Promise<Record<string, placeApiSchema>> => {
-
const res: Record<string, placeApiSchema> = {};
-
for (let id of ids) {
-
const info = await (await fetch(config.api.url + '/places/' + id)).json();
+
const info = await (await fetch(config.api.url + path + id)).json();
res[id] = info;
}
return res;
-
};
-
-
export default {
-
users: users,
-
places: places
};