diff --git a/packages/geojson-inspector/bun.lockb b/packages/geojson-inspector/bun.lockb new file mode 100755 index 00000000..51014d80 Binary files /dev/null and b/packages/geojson-inspector/bun.lockb differ diff --git a/packages/geojson-inspector/package.json b/packages/geojson-inspector/package.json index be562de9..628c8dff 100644 --- a/packages/geojson-inspector/package.json +++ b/packages/geojson-inspector/package.json @@ -11,5 +11,8 @@ "@cloudflare/workers-types": "^4.20240208.0", "typescript": "^5.0.4", "wrangler": "^3.0.0" + }, + "dependencies": { + "@turf/bbox": "^6.5.0" } } diff --git a/packages/geojson-inspector/src/index.ts b/packages/geojson-inspector/src/index.ts index 19155666..dd948de1 100644 --- a/packages/geojson-inspector/src/index.ts +++ b/packages/geojson-inspector/src/index.ts @@ -9,6 +9,7 @@ */ import { FailedInspectorResponse, InspectorResponse } from './types'; +import calcBBox from '@turf/bbox'; export interface Env { // Example binding to KV. Learn more at https://developers.cloudflare.com/workers/runtime-apis/kv/ @@ -51,7 +52,6 @@ export default { }); const endT = performance.now(); let failedResponse: FailedInspectorResponse; - console.log(response.headers); // if the fetch fails return an error if (!response.ok) { if (response.status === 404) { @@ -84,11 +84,8 @@ export default { } else { let contentLength = parseInt(response.headers.get('content-length') || '0'); if (contentLength === 0) { - console.log(response.headers); - // @ts-ignore - console.log(response.body.byteLength); - // @ts-ignore - contentLength = response.body ? response.body.byteLength : 0; + const blob = await response.clone().blob(); + contentLength = blob.size; } const contentType = response.headers.get('content-type'); const cacheControl = response.headers.get('cache-control'); @@ -125,13 +122,14 @@ export default { return new Response( JSON.stringify({ location, - contentLength: contentLength ? parseInt(contentLength) : 0, + contentLength, contentType: contentType || '', cacheControl: cacheControl || '', latency: endT - startT, rootType, featureCount: rootType === 'FeatureCollection' ? geojson.features.length : 1, geometryType: rootType === 'FeatureCollection' ? geojson.features[0]?.geometry?.type || 'Unknown' : geojson.geometry.type, + bbox: calcBBox(geojson), } as InspectorResponse), { status: 200, diff --git a/packages/geojson-inspector/src/types.ts b/packages/geojson-inspector/src/types.ts index accd898d..6cefe2d2 100644 --- a/packages/geojson-inspector/src/types.ts +++ b/packages/geojson-inspector/src/types.ts @@ -15,6 +15,7 @@ export interface SuccessfulInspectorResponse extends BaseInspectorResponse { featureCount: number; geometryType: 'Point' | 'MultiPoint' | 'LineString' | 'MultiLineString' | 'Polygon' | 'MultiPolygon'; rootType: 'FeatureCollection' | 'Feature'; + bbox: number[]; } export type InspectorResponse = FailedInspectorResponse | SuccessfulInspectorResponse;