root: move webapp to /web (#347)

* root: move webapp to /web

* root: fix static build

* root: fix static files not being served for e2e tests
This commit is contained in:
Jens L
2020-11-28 19:43:42 +01:00
committed by GitHub
parent 127ffbd456
commit 9466f91466
71 changed files with 15 additions and 26 deletions

View File

@ -0,0 +1,18 @@
import { DefaultClient } from "./client";
export class Application {
pk?: string;
name?: string;
slug?: string;
provider?: number;
meta_launch_url?: string;
meta_icon?: string;
meta_description?: string;
meta_publisher?: string;
policies?: string[];
static get(slug: string): Promise<Application> {
return DefaultClient.fetch<Application>("core", "applications", slug);
}
}

35
web/src/api/client.ts Normal file
View File

@ -0,0 +1,35 @@
import { NotFoundError, RequestError } from "./errors";
export const VERSION = "v2beta";
export class Client {
makeUrl(...url: string[]): string {
return `/api/${VERSION}/${url.join("/")}/`;
}
fetch<T>(...url: string[]): Promise<T> {
return fetch(this.makeUrl(...url))
.then((r) => {
if (r.status > 300) {
switch (r.status) {
case 404:
throw new NotFoundError(`URL ${this.makeUrl(...url)} not found`);
default:
throw new RequestError(r.statusText);
}
}
return r;
})
.then((r) => r.json())
.then((r) => <T>r);
}
}
export const DefaultClient = new Client();
export interface PBResponse {
count: number;
next: string;
previous: string;
results: Array<any>;
}

10
web/src/api/config.ts Normal file
View File

@ -0,0 +1,10 @@
import { DefaultClient } from "./client";
export class Config {
branding_logo?: string;
branding_title?: string;
static get(): Promise<Config> {
return DefaultClient.fetch<Config>("root", "config");
}
}

2
web/src/api/errors.ts Normal file
View File

@ -0,0 +1,2 @@
export class NotFoundError extends Error {}
export class RequestError extends Error {}

11
web/src/api/token.ts Normal file
View File

@ -0,0 +1,11 @@
import { DefaultClient } from "./client";
interface TokenResponse {
key: string;
}
export function tokenByIdentifier(identifier: string): Promise<string> {
return DefaultClient.fetch<TokenResponse>("core", "tokens", identifier, "view_key").then(
(r) => r.key
);
}

15
web/src/api/user.ts Normal file
View File

@ -0,0 +1,15 @@
import { Primitive } from "lit-html/lib/parts";
import { DefaultClient } from "./client";
export class User {
pk?: number;
username?: string;
name?: string;
is_superuser?: boolean;
email?: boolean;
avatar?: string;
static me(): Promise<User> {
return DefaultClient.fetch<User>("core", "users", "me");
}
}