Skip to content

Commit

Permalink
Run linter (#16)
Browse files Browse the repository at this point in the history
  • Loading branch information
aivus authored Dec 9, 2024
1 parent cc13785 commit 1a2c00a
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 39 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ jobs:
node-version: ${{ matrix.node-version }}
- name: Install dependencies
run: npm i
- name: Install dependencies
run: npm run lint
- name: Check the application
uses: BerniWittmann/background-server-action@v1
with:
Expand Down
8 changes: 4 additions & 4 deletions src/app/app.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,16 @@ export class AppController {
@Get(['/', '/pages/:pageName.html'])
@Render('index')
root(
@Param('pageName') pageName: string,
@Query('img') imagesCount: string = '100',
@Query('a') linksCount: string = '20'
@Param('pageName') pageName: string,
@Query('img') imagesCount = '100',
@Query('a') linksCount = '20',
) {
const childPageQuery = `?img=${imagesCount}&a=${linksCount}`;

return {
pageName: pageName || 'root',
imageUrls: this.appService.getImageUrls(Number(imagesCount), pageName),
linkUrls: this.appService.getLinkUrls(Number(linksCount), childPageQuery)
linkUrls: this.appService.getLinkUrls(Number(linksCount), childPageQuery),
};
}
}
28 changes: 14 additions & 14 deletions src/app/app.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,31 @@ import { Injectable } from '@nestjs/common';
import humanId from 'human-id';

export interface Resource {
url: string,
name?: string
url: string;
name?: string;
}

@Injectable()
export class AppService {
getImageUrls(count:Number = 0, prefix:string = ''): Array<Resource> {
getImageUrls(count = 0, prefix = ''): Array<Resource> {
return Array.from(new Array(count), (x, i) => {
return {
url: `/files/images/${prefix}${++i}.png`
}
});
return {
url: `/files/images/${prefix}${++i}.png`,
};
});
}

getLinkUrls(count:Number = 0, query:string = ''): Array<Resource> {
getLinkUrls(count = 0, query = ''): Array<Resource> {
return Array.from(new Array(count), () => {
const pageName = humanId({
separator: '-',
capitalize: false
const pageName = humanId({
separator: '-',
capitalize: false,
});

return {
url: `/pages/${pageName}.html${query}`,
name: pageName
name: pageName,
};
});​​​​​
});
}
}
2 changes: 1 addition & 1 deletion src/file/file.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ import { FileService } from './file.service';
controllers: [FileController],
providers: [FileService],
})
export class FileModule {}
export class FileModule {}
40 changes: 22 additions & 18 deletions src/file/file.service.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
import { Injectable } from '@nestjs/common';
import { createCanvas, JPEGStream, PNGStream } from 'canvas';
import { createCanvas, PNGStream } from 'canvas';
import * as uniqolor from 'uniqolor';

@Injectable()
export class FileService {
createImageStream({
text='test image',
text = 'test image',
width = 600,
height = 600
height = 600,
}: {
text?: string,
width?: number,
height?: number
}): JPEGStream {

text?: string;
width?: number;
height?: number;
}): PNGStream {
const canvas = createCanvas(width, height);
const context = canvas.getContext('2d');

Expand All @@ -31,19 +30,24 @@ export class FileService {
const textWidth = context.measureText(text).width;

context.fillStyle = '#000';
context.fillRect((width - textWidth) / 2 - 10, (height - fontSize) / 2 - 10, textWidth + 20, fontSize + 20);

context.fillRect(
(width - textWidth) / 2 - 10,
(height - fontSize) / 2 - 10,
textWidth + 20,
fontSize + 20,
);

context.fillStyle = '#fff';
context.fillText(text, width / 2, height / 2);

return canvas.createPNGStream({compressionLevel: 0});
return canvas.createPNGStream({ compressionLevel: 0 });
}
}

function getRandomColor():string {
const color = uniqolor.random({
saturation: [50, 100],
lightness: [50, 80],
});
return color.color;
}
function getRandomColor(): string {
const color = uniqolor.random({
saturation: [50, 100],
lightness: [50, 80],
});
return color.color;
}
7 changes: 5 additions & 2 deletions src/main.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
import { NestFactory } from '@nestjs/core';
import { AppModule } from './app/app.module';
import { NestFastifyApplication, FastifyAdapter } from '@nestjs/platform-fastify';
import {
NestFastifyApplication,
FastifyAdapter,
} from '@nestjs/platform-fastify';
import { join } from 'path';
//import handlebars from 'handlebars'

async function bootstrap() {
const app = await NestFactory.create<NestFastifyApplication>(
AppModule,
new FastifyAdapter(),
{ abortOnError: false }
{ abortOnError: false },
);

app.setViewEngine({
Expand Down

0 comments on commit 1a2c00a

Please sign in to comment.