mirror of
https://github.com/protomaps/PMTiles.git
synced 2026-02-04 02:41:09 +00:00
Merge pull request #202 from protomaps/cloudflare-native-decompress
Revert cloudflare decompression to own function
This commit is contained in:
4
.github/workflows/actions.yml
vendored
4
.github/workflows/actions.yml
vendored
@@ -21,8 +21,8 @@ jobs:
|
|||||||
- run: cd js && npm install && npm run build
|
- run: cd js && npm install && npm run build
|
||||||
- run: echo "VITE_GIT_SHA=$(git rev-parse --short HEAD)" >> app/.env
|
- run: echo "VITE_GIT_SHA=$(git rev-parse --short HEAD)" >> app/.env
|
||||||
- run: cd app && npm install && ./node_modules/.bin/tsc && npm run prettier-check && ./node_modules/.bin/vite build --base=/PMTiles/
|
- run: cd app && npm install && ./node_modules/.bin/tsc && npm run prettier-check && ./node_modules/.bin/vite build --base=/PMTiles/
|
||||||
- run: cd serverless/aws && npm install && npm run build && cp dist/lambda_function.zip ../../app/dist
|
- run: cd serverless/aws && npm install && npx tsc && npm run build && cp dist/lambda_function.zip ../../app/dist
|
||||||
- run: cd serverless/cloudflare && cp wrangler.toml.example wrangler.toml && npm install && npm run build && cp dist/index.js ../../app/dist
|
- run: cd serverless/cloudflare && cp wrangler.toml.example wrangler.toml && npm install && npx tsc && npm run build && cp dist/index.js ../../app/dist
|
||||||
- run: cd spec/v3 && cp *.pmtiles ../../app/dist
|
- run: cd spec/v3 && cp *.pmtiles ../../app/dist
|
||||||
- run: cd js/examples && mkdir ../../app/dist/examples && cp *.html ../../app/dist/examples/
|
- run: cd js/examples && mkdir ../../app/dist/examples && cp *.html ../../app/dist/examples/
|
||||||
- run: cd openlayers/examples && mkdir ../../app/dist/examples/openlayers && cp *.html ../../app/dist/examples/openlayers
|
- run: cd openlayers/examples && mkdir ../../app/dist/examples/openlayers && cp *.html ../../app/dist/examples/openlayers
|
||||||
|
|||||||
14
serverless/cloudflare/package-lock.json
generated
14
serverless/cloudflare/package-lock.json
generated
@@ -8,7 +8,7 @@
|
|||||||
"name": "pmtiles-cloudflare",
|
"name": "pmtiles-cloudflare",
|
||||||
"version": "0.0.0",
|
"version": "0.0.0",
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@cloudflare/workers-types": "^3.17.0",
|
"@cloudflare/workers-types": "^4.20230518.0",
|
||||||
"esbuild-runner": "^2.2.2",
|
"esbuild-runner": "^2.2.2",
|
||||||
"typescript": "^4.8.4",
|
"typescript": "^4.8.4",
|
||||||
"wrangler": "2.18.0"
|
"wrangler": "2.18.0"
|
||||||
@@ -24,9 +24,9 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/@cloudflare/workers-types": {
|
"node_modules/@cloudflare/workers-types": {
|
||||||
"version": "3.17.0",
|
"version": "4.20230518.0",
|
||||||
"resolved": "https://registry.npmjs.org/@cloudflare/workers-types/-/workers-types-3.17.0.tgz",
|
"resolved": "https://registry.npmjs.org/@cloudflare/workers-types/-/workers-types-4.20230518.0.tgz",
|
||||||
"integrity": "sha512-u0cUQ4ntWFFwn5jx0ETa2ItvwvfOMjyaKF2fX2vFVujrSgNES/PnvRzPAhdt9CMYAMidInm0MGkIjxHRsFBaeg==",
|
"integrity": "sha512-A0w1V+5SUawGaaPRlhFhSC/SCDT9oQG8TMoWOKFLA4qbqagELqEAFD4KySBIkeVOvCBLT1DZSYBMCxbXddl0kw==",
|
||||||
"dev": true
|
"dev": true
|
||||||
},
|
},
|
||||||
"node_modules/@esbuild-plugins/node-globals-polyfill": {
|
"node_modules/@esbuild-plugins/node-globals-polyfill": {
|
||||||
@@ -1620,9 +1620,9 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"@cloudflare/workers-types": {
|
"@cloudflare/workers-types": {
|
||||||
"version": "3.17.0",
|
"version": "4.20230518.0",
|
||||||
"resolved": "https://registry.npmjs.org/@cloudflare/workers-types/-/workers-types-3.17.0.tgz",
|
"resolved": "https://registry.npmjs.org/@cloudflare/workers-types/-/workers-types-4.20230518.0.tgz",
|
||||||
"integrity": "sha512-u0cUQ4ntWFFwn5jx0ETa2ItvwvfOMjyaKF2fX2vFVujrSgNES/PnvRzPAhdt9CMYAMidInm0MGkIjxHRsFBaeg==",
|
"integrity": "sha512-A0w1V+5SUawGaaPRlhFhSC/SCDT9oQG8TMoWOKFLA4qbqagELqEAFD4KySBIkeVOvCBLT1DZSYBMCxbXddl0kw==",
|
||||||
"dev": true
|
"dev": true
|
||||||
},
|
},
|
||||||
"@esbuild-plugins/node-globals-polyfill": {
|
"@esbuild-plugins/node-globals-polyfill": {
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
"name": "pmtiles-cloudflare",
|
"name": "pmtiles-cloudflare",
|
||||||
"version": "0.0.0",
|
"version": "0.0.0",
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@cloudflare/workers-types": "^3.17.0",
|
"@cloudflare/workers-types": "^4.20230518.0",
|
||||||
"esbuild-runner": "^2.2.2",
|
"esbuild-runner": "^2.2.2",
|
||||||
"typescript": "^4.8.4",
|
"typescript": "^4.8.4",
|
||||||
"wrangler": "2.18.0"
|
"wrangler": "2.18.0"
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import {
|
|||||||
RangeResponse,
|
RangeResponse,
|
||||||
ResolvedValueCache,
|
ResolvedValueCache,
|
||||||
TileType,
|
TileType,
|
||||||
|
Compression,
|
||||||
} from "../../../js/index";
|
} from "../../../js/index";
|
||||||
import { pmtiles_path, tile_path, tileJSON } from "../../shared/index";
|
import { pmtiles_path, tile_path, tileJSON } from "../../shared/index";
|
||||||
|
|
||||||
@@ -21,7 +22,22 @@ class KeyNotFoundError extends Error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const CACHE = new ResolvedValueCache(25, undefined);
|
async function nativeDecompress(
|
||||||
|
buf: ArrayBuffer,
|
||||||
|
compression: Compression
|
||||||
|
): Promise<ArrayBuffer> {
|
||||||
|
if (compression === Compression.None || compression === Compression.Unknown) {
|
||||||
|
return buf;
|
||||||
|
} else if (compression === Compression.Gzip) {
|
||||||
|
let stream = new Response(buf).body!;
|
||||||
|
let result = stream.pipeThrough(new DecompressionStream("gzip"));
|
||||||
|
return new Response(result).arrayBuffer();
|
||||||
|
} else {
|
||||||
|
throw Error("Compression method not supported");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const CACHE = new ResolvedValueCache(25, undefined, nativeDecompress);
|
||||||
|
|
||||||
class R2Source implements Source {
|
class R2Source implements Source {
|
||||||
env: Env;
|
env: Env;
|
||||||
@@ -120,7 +136,7 @@ export default {
|
|||||||
|
|
||||||
const cacheable_headers = new Headers();
|
const cacheable_headers = new Headers();
|
||||||
const source = new R2Source(env, name);
|
const source = new R2Source(env, name);
|
||||||
const p = new PMTiles(source, CACHE);
|
const p = new PMTiles(source, CACHE, nativeDecompress);
|
||||||
try {
|
try {
|
||||||
const p_header = await p.getHeader();
|
const p_header = await p.getHeader();
|
||||||
|
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ export const tile_path = (
|
|||||||
|
|
||||||
export const tileJSON = (
|
export const tileJSON = (
|
||||||
header: Header,
|
header: Header,
|
||||||
metadata: unknown,
|
metadata: any,
|
||||||
hostname: string,
|
hostname: string,
|
||||||
tileset_name: string
|
tileset_name: string
|
||||||
) => {
|
) => {
|
||||||
|
|||||||
Reference in New Issue
Block a user