Skip to content

Commit ebac7d7

Browse files
committed
chore: lint
1 parent b86c3a2 commit ebac7d7

File tree

3 files changed

+50
-66
lines changed

3 files changed

+50
-66
lines changed

package-lock.json

+23-33
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

plugin/src/templates/edge/ipx.ts

+25-30
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
1-
import { Accepts } from "https://deno.land/x/[email protected]/mod.ts";
2-
import type { Context } from "netlify:edge";
1+
import { Accepts } from 'https://deno.land/x/[email protected]/mod.ts'
2+
import type { Context } from 'netlify:edge'
33
// Available at build time
4-
import imageconfig from "./imageconfig.json" assert {
5-
type: "json",
6-
};
4+
import imageconfig from './imageconfig.json' assert { type: 'json' }
75

8-
const defaultFormat = "webp"
6+
const defaultFormat = 'webp'
97

108
interface ImageConfig extends Record<string, unknown> {
11-
formats?: string[];
9+
formats?: string[]
1210
}
1311

1412
/**
@@ -17,41 +15,38 @@ interface ImageConfig extends Record<string, unknown> {
1715

1816
// deno-lint-ignore require-await
1917
const handler = async (req: Request, context: Context) => {
20-
const { searchParams } = new URL(req.url);
21-
const accept = new Accepts(req.headers);
22-
const { formats = [defaultFormat] } = imageconfig as ImageConfig;
18+
const { searchParams } = new URL(req.url)
19+
const accept = new Accepts(req.headers)
20+
const { formats = [defaultFormat] } = imageconfig as ImageConfig
2321
if (formats.length === 0) {
24-
formats.push(defaultFormat);
22+
formats.push(defaultFormat)
2523
}
26-
let type = accept.types(formats) || defaultFormat;
27-
if(Array.isArray(type)) {
28-
type = type[0];
24+
let type = accept.types(formats) || defaultFormat
25+
if (Array.isArray(type)) {
26+
type = type[0]
2927
}
3028

31-
32-
const source = searchParams.get("url");
33-
const width = searchParams.get("w");
34-
const quality = searchParams.get("q") ?? 75;
29+
const source = searchParams.get('url')
30+
const width = searchParams.get('w')
31+
const quality = searchParams.get('q') ?? 75
3532

3633
if (!source || !width) {
37-
return new Response("Invalid request", {
34+
return new Response('Invalid request', {
3835
status: 400,
39-
});
36+
})
4037
}
4138

42-
const modifiers = [`w_${width}`, `q_${quality}`];
39+
const modifiers = [`w_${width}`, `q_${quality}`]
4340

4441
if (type) {
45-
if(type.includes('/')) {
42+
if (type.includes('/')) {
4643
// If this is a mimetype, strip "image/"
47-
type = type.split('/')[1];
44+
type = type.split('/')[1]
4845
}
49-
modifiers.push(`f_${type}`);
46+
modifiers.push(`f_${type}`)
5047
}
51-
const target = `/_ipx/${modifiers.join(",")}/${encodeURIComponent(source)}`;
52-
return context.rewrite(
53-
target,
54-
);
55-
};
48+
const target = `/_ipx/${modifiers.join(',')}/${encodeURIComponent(source)}`
49+
return context.rewrite(target)
50+
}
5651

57-
export default handler;
52+
export default handler

plugin/src/templates/edge/utils.ts

+2-3
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ export interface FetchEventResult {
88
/**
99
* This is how Next handles rewritten URLs.
1010
*/
11-
export function relativizeURL(url: string | string, base: string | URL) {
11+
export function relativizeURL(url: string | string, base: string | URL) {
1212
const baseURL = typeof base === 'string' ? new URL(base) : base
1313
const relative = new URL(url, base)
1414
const origin = `${baseURL.protocol}//${baseURL.host}`
@@ -17,7 +17,6 @@ export interface FetchEventResult {
1717
: relative.toString()
1818
}
1919

20-
2120
export const addMiddlewareHeaders = async (
2221
originResponse: Promise<Response> | Response,
2322
middlewareResponse: Response,
@@ -49,7 +48,7 @@ export const buildResponse = ({
4948
if (rewrite) {
5049
const rewriteUrl = new URL(rewrite, request.url)
5150
const baseUrl = new URL(request.url)
52-
if(rewriteUrl.hostname !== baseUrl.hostname) {
51+
if (rewriteUrl.hostname !== baseUrl.hostname) {
5352
// Netlify Edge Functions don't support proxying to external domains, but Next middleware does
5453
const proxied = fetch(new Request(rewriteUrl.toString(), request))
5554
return addMiddlewareHeaders(proxied, res)

0 commit comments

Comments
 (0)