Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(tiler): Support fonts array to fallback to next font if not fond. #2633

Merged
merged 2 commits into from
Jan 4, 2023
Merged
Show file tree
Hide file tree
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
10 changes: 10 additions & 0 deletions packages/lambda-tiler/src/routes/__tests__/fonts.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,16 @@ o.spec('/v1/fonts', () => {
o(res404.status).equals(404);
});

o('should fallback to the next font in array', async () => {
await fsa.write('memory://fonts/Roboto Thin/0-255.pbf', Buffer.from(''));
const res255 = await handler.router.handle(mockRequest('/v1/fonts/Roboto,Roboto Bold,Roboto Thin/0-255.pbf'));
o(res255.status).equals(200);
o(res255.header('content-type')).equals('application/x-protobuf');
o(res255.header('content-encoding')).equals(undefined);
o(res255.header('etag')).notEquals(undefined);
o(res255.header('cache-control')).equals('public, max-age=604800, stale-while-revalidate=86400');
});

o('should get the correct utf8 font', async () => {
await fsa.write('memory://fonts/🦄 🌈/0-255.pbf', Buffer.from(''));
const res255 = await handler.router.handle(mockRequest('/v1/fonts/🦄 🌈/0-255.pbf'));
Expand Down
10 changes: 8 additions & 2 deletions packages/lambda-tiler/src/routes/fonts.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,20 @@
import { LambdaHttpRequest, LambdaHttpResponse } from '@linzjs/lambda';
import path from 'path';
import { assetProvider } from '../util/assets.provider.js';
import { NotFound } from '../util/response.js';

interface FontGet {
Params: { fontStack: string; range: string };
}

export async function fontGet(req: LambdaHttpRequest<FontGet>): Promise<LambdaHttpResponse> {
const targetFile = path.join('fonts', req.params.fontStack, req.params.range) + '.pbf';
return assetProvider.serve(req, targetFile, 'application/x-protobuf');
const targetFonts = req.params.fontStack.split(',');
for (const font of targetFonts) {
const targetFile = path.join('fonts', font, req.params.range) + '.pbf';
const response = await assetProvider.serve(req, targetFile, 'application/x-protobuf');
if (response.status !== 404) return response;
}
return NotFound();
}

export async function fontList(req: LambdaHttpRequest): Promise<LambdaHttpResponse> {
Expand Down