Skip to content

Commit

Permalink
add cron, final touches
Browse files Browse the repository at this point in the history
  • Loading branch information
zbycz committed Feb 3, 2025
1 parent 3d6f145 commit 2f68a53
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 14 deletions.
3 changes: 3 additions & 0 deletions .env
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,6 @@ NEXT_PUBLIC_API_KEY_GRAPHHOPPER=f189b841-6529-46c6-8a91-51f17477dcda
# Umami anylytics is used to track server load only. We don't want to track clicks in browser.
# optional, fill blank to disable
UMAMI_WEBSITE_ID=5e4d4917-9031-42f1-a26a-e71d7ab8e3fe

# Use climbingTiles loaded from openclimbing.org (instead of Overpass version)
#NEXT_PUBLIC_ENABLE_CLIMBING_TILES=true
4 changes: 4 additions & 0 deletions pages/api/climbing-tiles/refresh.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ import { refreshClimbingTiles } from '../../../src/server/climbing-tiles/refresh

export default async (req: NextApiRequest, res: NextApiResponse) => {
try {
if (!process.env.XATA_PASSWORD) {
throw new Error('XATA_PASSWORD must be set');
}

const log = await refreshClimbingTiles();

res.status(200).send(log);
Expand Down
4 changes: 4 additions & 0 deletions pages/api/climbing-tiles/tile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ import { Tile } from '../../../src/types';

export default async (req: NextApiRequest, res: NextApiResponse) => {
try {
if (!process.env.XATA_PASSWORD) {
throw new Error('XATA_PASSWORD must be set');
}

const tileNumber: Tile = {
z: Number(req.query.z),
x: Number(req.query.x),
Expand Down
10 changes: 5 additions & 5 deletions src/components/Map/behaviour/useUpdateStyle.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ import { osmappLayers } from '../../LayerSwitcher/osmappLayers';
import { getRasterStyle } from '../styles/rasterStyle';
import { DEFAULT_MAP } from '../../../config.mjs';
import { makinaAfricaStyle } from '../styles/makinaAfricaStyle';
import {
CLIMBING_SPRITE,
climbingLayers,
} from '../styles/layers/climbingLayers';
import { EMPTY_GEOJSON_SOURCE, OSMAPP_SPRITE } from '../consts';
import { fetchCrags } from '../../../services/fetchCrags';
import { intl } from '../../../services/intl';
Expand All @@ -19,10 +23,6 @@ import { layersWithOsmId } from '../helpers';
import { Theme } from '../../../helpers/theme';
import { addIndoorEqual, removeIndoorEqual } from './indoor';
import { addClimbingTilesSource } from '../climbingTiles/climbingTilesSource';
import {
CLIMBING_SPRITE,
climbingLayers,
} from '../styles/layers/climbingLayers';

const ofrBasicStyle = {
...basicStyle,
Expand Down Expand Up @@ -71,7 +71,7 @@ const addClimbingOverlay = (style: StyleSpecification, map: Map) => {

fetchCrags().then(
(geojson) => {
const geojsonSource = map.getSource<GeoJSONSource>('climbing');
const geojsonSource = map.getSource('climbing') as GeoJSONSource;
geojsonSource?.setData(geojson); // TODO can be undefined at first map render
},
(error) => {
Expand Down
7 changes: 6 additions & 1 deletion src/components/Map/climbingTiles/climbingTilesSource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,13 @@ import type { StyleSpecification } from '@maplibre/maplibre-gl-style-spec';
import { Tile } from '../../../types';
import { computeTiles } from './computeTiles';

const HOST = process.env.NEXT_PUBLIC_ENABLE_CLIMBING_TILES_LOCAL
? '/'
: 'https://openclimbing.org/';

const getTileJson = async ({ z, x, y }: Tile) => {
const data = await fetchJson(`/api/climbing-tiles/tile?z=${z}&x=${x}&y=${y}`);
const url = `${HOST}/api/climbing-tiles/tile?z=${z}&x=${x}&y=${y}`;
const data = await fetchJson(url);
return data.features || [];
};

Expand Down
7 changes: 0 additions & 7 deletions src/components/Map/consts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,6 @@ export const OSMAPP_SOURCES: Record<string, SourceSpecification> = {
type: 'vector' as const,
},
overpass: EMPTY_GEOJSON_SOURCE,
climbingTiles: {
type: 'vector' as const,
tiles: [
`${window.location.protocol}//${window.location.host}/api/climbing-tiles/tile?z={z}&x={x}&y={y}`,
],
maxzoom: 10,
},
};

export const BACKGROUND = [
Expand Down
8 changes: 7 additions & 1 deletion vercel.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,11 @@
"memory": 1200,
"maxDuration": 200
}
}
},
"crons": [
{
"path": "/api/climbing-tiles/refresh",
"schedule": "0 2 * * *"
}
]
}

0 comments on commit 2f68a53

Please sign in to comment.