implement tile_path customization for cloudflare

This commit is contained in:
Brandon Liu
2022-10-19 22:34:55 +08:00
parent da235cac22
commit 9346762aa5
2 changed files with 82 additions and 23 deletions

View File

@@ -1,17 +1,51 @@
import { test } from "zora";
import { pmtiles_path } from "./index";
import { pmtiles_path, tile_path } from "./index";
test("pmtiles path", (assertion) => {
let result = pmtiles_path(undefined, "foo");
let result = pmtiles_path("foo", undefined);
assertion.equal(result, "foo.pmtiles");
});
test("pmtiles path", (assertion) => {
let result = pmtiles_path("folder/{name}/file.pmtiles", "foo");
let result = pmtiles_path("foo","folder/{name}/file.pmtiles");
assertion.equal(result, "folder/foo/file.pmtiles");
});
test("pmtiles path with slash", (assertion) => {
let result = pmtiles_path("folder/{name}/file.pmtiles", "foo/bar");
let result = pmtiles_path("foo/bar","folder/{name}/file.pmtiles");
assertion.equal(result, "folder/foo/bar/file.pmtiles");
});
test("parse tile default", (assertion) => {
let {ok, name, tile, ext} = tile_path("abcd");
assertion.equal(ok, false);
({name, tile} = tile_path("/foo/11/22/33.pbf"));
assertion.equal(name,"foo");
assertion.equal(tile[0],11);
assertion.equal(tile[1],22);
assertion.equal(tile[2],33);
});
test("parse tile path setting", (assertion) => {
let {ok, name, tile, ext} = tile_path("/foo/11/22/33.pbf","/{name}/{z}/{y}/{x}.{ext}");
assertion.equal(tile[1],33);
assertion.equal(tile[2],22);
assertion.equal(ext,"pbf");
({ok, name, tile, ext} = tile_path("/tiles/foo/4/2/3.mvt","/tiles/{name}/{z}/{x}/{y}.{ext}"));
assertion.equal(name,"foo");
assertion.equal(tile[0],4);
assertion.equal(tile[1],2);
assertion.equal(tile[2],3);
assertion.equal(ext,"mvt");
});
test("parse tile path setting special chars", (assertion) => {
let {ok, name, tile, ext} = tile_path("/folder(new/foo/11/22/33.pbf","/folder(new/{name}/{z}/{y}/{x}.{ext}");
assertion.equal(name,"foo");
});
test("parse tile path setting slash", (assertion) => {
let {ok, name, tile, ext} = tile_path("/foo/bar/11/22/33.pbf","/{name}/{z}/{y}/{x}.{ext}");
assertion.equal(name,"foo/bar");
});