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 { PMTilesProtocol } from "svelte-maplibre-gl/pmtiles";
|
||||||
import HazardMarker from "./HazardMarker.svelte";
|
import HazardMarker from "./HazardMarker.svelte";
|
||||||
import { hazards } from "./hazards.svelte";
|
import { hazards } from "./hazards.svelte";
|
||||||
|
import RequiresCapability from "./RequiresCapability.svelte";
|
||||||
|
|
||||||
onMount(() => {
|
onMount(() => {
|
||||||
window.addEventListener("resize", map.updateMapPadding);
|
window.addEventListener("resize", map.updateMapPadding);
|
||||||
@ -181,12 +182,13 @@
|
|||||||
/>
|
/>
|
||||||
{/if}
|
{/if}
|
||||||
|
|
||||||
<!-- <HazardMarker hazard="bumpy-road" lat={51.347447} lon={7.4028181} /> -->
|
<RequiresCapability capability="hazards">
|
||||||
{#each hazards as hazard (hazard.latitude + "-" + hazard.longitude)}
|
{#each hazards as hazard (hazard.latitude + "-" + hazard.longitude)}
|
||||||
<HazardMarker
|
<HazardMarker
|
||||||
hazard={hazard.type}
|
hazard={hazard.type}
|
||||||
lat={hazard.latitude}
|
lat={hazard.latitude}
|
||||||
lon={hazard.longitude}
|
lon={hazard.longitude}
|
||||||
/>
|
/>
|
||||||
{/each}
|
{/each}
|
||||||
|
</RequiresCapability>
|
||||||
</MapLibre>
|
</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";
|
import { location } from "./location.svelte";
|
||||||
|
|
||||||
export const hazards: Hazard[] = $state([]);
|
export const hazards: Hazard[] = $state([]);
|
||||||
|
|
||||||
export async function fetchHazards() {
|
export async function fetchHazards() {
|
||||||
if (!location.available) return;
|
if (!location.available) return;
|
||||||
|
if (!await hasCapability("hazards")) return;
|
||||||
const newHazards = await getHazards(
|
const newHazards = await getHazards(
|
||||||
{ lat: location.lat, lon: location.lng },
|
{ lat: location.lat, lon: location.lng },
|
||||||
100,
|
100,
|
||||||
|
|||||||
@ -1,6 +1,5 @@
|
|||||||
import { LNV_SERVER } from "./hosts";
|
import { LNV_SERVER } from "./hosts";
|
||||||
import type { OIDCUser } from "./oidc";
|
import type { OIDCUser } from "./oidc";
|
||||||
import type { Store } from "./stores";
|
|
||||||
|
|
||||||
export type Capabilities = (
|
export type Capabilities = (
|
||||||
| "auth"
|
| "auth"
|
||||||
@ -9,6 +8,8 @@ export type Capabilities = (
|
|||||||
| "fuel"
|
| "fuel"
|
||||||
| "post"
|
| "post"
|
||||||
| "saved-routes"
|
| "saved-routes"
|
||||||
|
| "hazards"
|
||||||
|
| "stores"
|
||||||
)[];
|
)[];
|
||||||
export let capabilities: Capabilities = [];
|
export let capabilities: Capabilities = [];
|
||||||
export let oidcConfig: {
|
export let oidcConfig: {
|
||||||
@ -240,9 +241,9 @@ export interface Hazard {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export async function getHazards(location: WorldLocation, radius = 50) {
|
export async function getHazards(location: WorldLocation, radius = 50) {
|
||||||
// if (!(await hasCapability("hazards"))) {
|
if (!(await hasCapability("hazards"))) {
|
||||||
// throw new Error("Hazards capability is not available");
|
throw new Error("Hazards capability is not available");
|
||||||
// }
|
}
|
||||||
const res = await fetch(
|
const res = await fetch(
|
||||||
LNV_SERVER +
|
LNV_SERVER +
|
||||||
`/hazards?lat=${location.lat}&lon=${location.lon}&radius=${radius}`,
|
`/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) {
|
export async function postHazard(location: WorldLocation, type: string) {
|
||||||
// if (!(await hasCapability("hazards"))) {
|
if (!(await hasCapability("hazards"))) {
|
||||||
// throw new Error("Hazards capability is not available");
|
throw new Error("Hazards capability is not available");
|
||||||
// }
|
}
|
||||||
const res = await authFetch(LNV_SERVER + `/hazards`, {
|
const res = await authFetch(LNV_SERVER + `/hazards`, {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: {
|
headers: {
|
||||||
@ -274,32 +275,3 @@ export async function postHazard(location: WorldLocation, type: string) {
|
|||||||
}
|
}
|
||||||
return await res.json();
|
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