Skip to content

Commit

Permalink
[misc] make linter happy
Browse files Browse the repository at this point in the history
  • Loading branch information
mrhyde committed Sep 12, 2024
1 parent 869c32e commit 2686849
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 16 deletions.
10 changes: 5 additions & 5 deletions source/routes/problems/slowImage.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import type { FastifyPluginAsync } from 'fastify';
import { performance } from 'node:perf_hooks';
import { slowImageGeneration } from '~/simulate/load.ts';
import type { FastifyPluginAsync } from 'fastify'
import { performance } from 'node:perf_hooks'
import { slowImageGeneration } from '~/simulate/load.ts'

// eslint-disable-next-line jsdoc/require-jsdoc
export const slowImage: FastifyPluginAsync = async (fastify) => {
fastify.get<{ Querystring: { complexity: string, name: string } }>('/problems/slow-image', async (request, reply) => {
const complexity = parseInt(request.query.complexity || '1', 10)
fastify.get<{ Querystring: { complexity: string; name: string } }>('/problems/slow-image', async (request, reply) => {
const complexity = Number.parseInt(request.query.complexity || '1', 10)
const name = request.query.name || 'default'

const startTime = performance.now()
Expand Down
21 changes: 15 additions & 6 deletions source/routes/problems/slowImageGallery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,20 @@ import type { FastifyPluginAsync } from 'fastify'
// eslint-disable-next-line jsdoc/require-jsdoc
export const imageGalleryRoute: FastifyPluginAsync = async (fastify) => {
fastify.get('/problems/slow-image-gallery', async (_, reply) => {
const imageContainer = (i: number): string => {
return `
<div class="image-container">
<div class="loading">Loading...</div>
<img src="/problems/slow-image?complexity=${i}" alt="Slow image ${i}" loading="lazy" onload="this.previousElementSibling.style.display='none';">
</div>
`
}

const gallery = Array.from({ length: 9 })
.map((_, i) => i + 1)
.map((i) => imageContainer(i))
.join('')

const html = `
<!DOCTYPE html>
<html lang="en">
Expand All @@ -21,12 +35,7 @@ export const imageGalleryRoute: FastifyPluginAsync = async (fastify) => {
<body>
<h1>Slow Loading Image Gallery</h1>
<div class="gallery">
${ Array.from({length: 9}).map((_, i) => i + 1).map(i => `
<div class="image-container">
<div class="loading">Loading...</div>
<img src="/problems/slow-image?complexity=${i}" alt="Slow image ${i}" loading="lazy" onload="this.previousElementSibling.style.display='none';">
</div>
`).join('')}
${gallery}
</div>
<script>
document.addEventListener('DOMContentLoaded', () => {
Expand Down
2 changes: 0 additions & 2 deletions source/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@ import routes from './routes/index.ts'
const DEFAULT_PORT = 3000
const DEFAULT_HOST = '127.0.0.1'

// biome-ignore lint/complexity/useLiteralKeys: tsc > biome
const PORT = Number.parseInt(process.env['PORT'] || DEFAULT_PORT.toString(), 10)
// biome-ignore lint/complexity/useLiteralKeys: tsc > biome
const HOST = process.env['HOST'] || DEFAULT_HOST

const server = fastify()
Expand Down
4 changes: 2 additions & 2 deletions source/simulate/load.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,8 @@ export const slowImageGeneration = async (
ctx.fillStyle = `#${hash.slice(i * 6, (i + 1) * 6)}`
ctx.beginPath()
ctx.arc(
parseInt(hash.slice(i * 2, i * 2 + 2), 16) * 300 / 255,
parseInt(hash.slice(i * 2 + 2, i * 2 + 4), 16) * 300 / 255,
(Number.parseInt(hash.slice(i * 2, i * 2 + 2), 16) * 300) / 255,
(Number.parseInt(hash.slice(i * 2 + 2, i * 2 + 4), 16) * 300) / 255,
20 + i * 10,
0,
Math.PI * 2
Expand Down
3 changes: 2 additions & 1 deletion tsconfig.build.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"extends": "./tsconfig.json",
"exclude": ["build", "**/*.test.ts", "vitest.config.ts"],
"include": ["source/**/*"],
"exclude": ["**/*.test.ts"],
"tsc-alias": {
"verbose": true,
"resolveFullPaths": true
Expand Down
1 change: 1 addition & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"extends": "@2bad/tsconfig",
"include": ["source/**/*", "vitest.config.ts"],
"compilerOptions": {
"outDir": "build",
"baseUrl": "source",
Expand Down

0 comments on commit 2686849

Please sign in to comment.