Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 30 additions & 1 deletion serverless/cloudflare/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,35 @@ class R2Source implements Source {
}
}

export const slice = (input: {
ok: boolean;
name: string;
tile?: [number, number, number];
ext: string;
}): {
ok: boolean;
name: string;
tile?: [number, number, number];
ext: string;
} => {
// pass through inapplicable inputs unchanged
if (!input.ok || !input.tile || input.name !== "OSM_traces") return input;

const [z, x, y] = input.tile;
if (z < 7) return { ok: false, name: "", tile: [0, 0, 0], ext: "" };

const shift = z - 7;
const nameX = x >> shift;
const nameY = y >> shift;

return {
ok: true,
name: `7/${nameX}/${nameY}/${input.name}+7-${nameX}-${nameY}`,
tile: input.tile,
ext: input.ext,
};
};

export default {
async fetch(
request: Request,
Expand All @@ -97,7 +126,7 @@ export default {
return new Response(undefined, { status: 405 });

const url = new URL(request.url);
const { ok, name, tile, ext } = tile_path(url.pathname);
const { ok, name, tile, ext } = slice(tile_path(url.pathname));

const cache = caches.default;

Expand Down
Loading