chore: remove dead api routes and require hazards capability
This commit is contained in:
@ -19,6 +19,7 @@
|
||||
import { PMTilesProtocol } from "svelte-maplibre-gl/pmtiles";
|
||||
import HazardMarker from "./HazardMarker.svelte";
|
||||
import { hazards } from "./hazards.svelte";
|
||||
import RequiresCapability from "./RequiresCapability.svelte";
|
||||
|
||||
onMount(() => {
|
||||
window.addEventListener("resize", map.updateMapPadding);
|
||||
@ -181,7 +182,7 @@
|
||||
/>
|
||||
{/if}
|
||||
|
||||
<!-- <HazardMarker hazard="bumpy-road" lat={51.347447} lon={7.4028181} /> -->
|
||||
<RequiresCapability capability="hazards">
|
||||
{#each hazards as hazard (hazard.latitude + "-" + hazard.longitude)}
|
||||
<HazardMarker
|
||||
hazard={hazard.type}
|
||||
@ -189,4 +190,5 @@
|
||||
lon={hazard.longitude}
|
||||
/>
|
||||
{/each}
|
||||
</RequiresCapability>
|
||||
</MapLibre>
|
||||
|
||||
@ -1,10 +1,11 @@
|
||||
import { getHazards, type Hazard } from "$lib/services/lnv";
|
||||
import { getHazards, hasCapability, type Hazard } from "$lib/services/lnv";
|
||||
import { location } from "./location.svelte";
|
||||
|
||||
export const hazards: Hazard[] = $state([]);
|
||||
|
||||
export async function fetchHazards() {
|
||||
if (!location.available) return;
|
||||
if (!await hasCapability("hazards")) return;
|
||||
const newHazards = await getHazards(
|
||||
{ lat: location.lat, lon: location.lng },
|
||||
100,
|
||||
|
||||
@ -1,6 +1,5 @@
|
||||
import { LNV_SERVER } from "./hosts";
|
||||
import type { OIDCUser } from "./oidc";
|
||||
import type { Store } from "./stores";
|
||||
|
||||
export type Capabilities = (
|
||||
| "auth"
|
||||
@ -9,6 +8,8 @@ export type Capabilities = (
|
||||
| "fuel"
|
||||
| "post"
|
||||
| "saved-routes"
|
||||
| "hazards"
|
||||
| "stores"
|
||||
)[];
|
||||
export let capabilities: Capabilities = [];
|
||||
export let oidcConfig: {
|
||||
@ -240,9 +241,9 @@ export interface Hazard {
|
||||
}
|
||||
|
||||
export async function getHazards(location: WorldLocation, radius = 50) {
|
||||
// if (!(await hasCapability("hazards"))) {
|
||||
// throw new Error("Hazards capability is not available");
|
||||
// }
|
||||
if (!(await hasCapability("hazards"))) {
|
||||
throw new Error("Hazards capability is not available");
|
||||
}
|
||||
const res = await fetch(
|
||||
LNV_SERVER +
|
||||
`/hazards?lat=${location.lat}&lon=${location.lon}&radius=${radius}`,
|
||||
@ -255,9 +256,9 @@ export async function getHazards(location: WorldLocation, radius = 50) {
|
||||
}
|
||||
|
||||
export async function postHazard(location: WorldLocation, type: string) {
|
||||
// if (!(await hasCapability("hazards"))) {
|
||||
// throw new Error("Hazards capability is not available");
|
||||
// }
|
||||
if (!(await hasCapability("hazards"))) {
|
||||
throw new Error("Hazards capability is not available");
|
||||
}
|
||||
const res = await authFetch(LNV_SERVER + `/hazards`, {
|
||||
method: "POST",
|
||||
headers: {
|
||||
@ -274,32 +275,3 @@ export async function postHazard(location: WorldLocation, type: string) {
|
||||
}
|
||||
return await res.json();
|
||||
}
|
||||
|
||||
export function getStores(): Promise<Store[]> {
|
||||
return authFetch(LNV_SERVER + "/stores").then((res) => res.json());
|
||||
}
|
||||
|
||||
export function getStore(name: string): Promise<Store | null> {
|
||||
return authFetch(LNV_SERVER + "/store/" + name).then((res) => res.json());
|
||||
}
|
||||
|
||||
export function putStore(name: string, data: object, type: string, privacy: string) {
|
||||
return authFetch(LNV_SERVER + "/store", {
|
||||
method: "PUT",
|
||||
body: JSON.stringify({
|
||||
name,
|
||||
data: JSON.stringify(data),
|
||||
type,
|
||||
privacy,
|
||||
}),
|
||||
});
|
||||
}
|
||||
|
||||
export function deleteStore(name: string) {
|
||||
return authFetch(LNV_SERVER + "/store", {
|
||||
method: "DELETE",
|
||||
body: JSON.stringify({
|
||||
name,
|
||||
}),
|
||||
}).then((res) => res.text());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user