diff --git a/.gitignore b/.gitignore index 9a5aced..4aa3500 100644 --- a/.gitignore +++ b/.gitignore @@ -137,3 +137,4 @@ dist # Vite logs files vite.config.js.timestamp-* vite.config.ts.timestamp-* +node.txt \ No newline at end of file diff --git a/src/entity/hostslog.entity.ts b/src/entity/hostslog.entity.ts index d816209..b1847b6 100644 --- a/src/entity/hostslog.entity.ts +++ b/src/entity/hostslog.entity.ts @@ -13,4 +13,4 @@ export class HostsLog { @CreateDateColumn() created_at: Date; -} \ No newline at end of file +} \ No newline at end of file diff --git a/src/entity/service.entity.ts b/src/entity/service.entity.ts new file mode 100644 index 0000000..8cacd3c --- /dev/null +++ b/src/entity/service.entity.ts @@ -0,0 +1,25 @@ +import { Column, Entity, PrimaryGeneratedColumn } from "typeorm"; + +@Entity({name: 'services'}) +export class Service { + @PrimaryGeneratedColumn() + id: number; + + @Column() + name: string; + + @Column() + host: string; + + @Column() + alive: boolean; + + @Column() + ping_type: string; + + @Column() + type: string; + + @Column() + notify: boolean; +} \ No newline at end of file diff --git a/src/services/status.service.ts b/src/services/status.service.ts index 85e3d2b..3f7afbc 100644 --- a/src/services/status.service.ts +++ b/src/services/status.service.ts @@ -9,6 +9,7 @@ import { Follow } from "../entity/follow.entity"; import { Guild } from "../entity/guild.entity"; import dayjs, { Dayjs } from "dayjs"; import { Canvas } from "canvas"; +import { Service } from "../entity/service.entity"; type Nofity = {time: Date, name : string, alive : boolean, type : InfraType, host: string}; @@ -134,12 +135,14 @@ export class StatusService { private hostsLogRepo: Repository; private followRepo: Repository; private guildRepo: Repository; + private serviceRepo: Repository; constructor() { this.hostsLogRepo = AppDataSource.getRepository(HostsLog); this.followRepo = AppDataSource.getRepository(Follow); this.guildRepo = AppDataSource.getRepository(Guild); + this.serviceRepo = AppDataSource.getRepository(Service); setTimeout(async () => { await this.fetch() diff --git a/test.js b/test.js deleted file mode 100644 index 872f94c..0000000 --- a/test.js +++ /dev/null @@ -1,77 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -var canvas_1 = require("canvas"); -var dayjs = require("dayjs"); -var fs_1 = require("fs"); -function createUptimeBar(uptimes) { - var now = dayjs(); - var week = now.clone().subtract(1, 'week'); - var canvas = new canvas_1.Canvas(100, 2, "image"); - var ctx = canvas.getContext('2d'); - ctx.fillStyle = "#27FF00"; - ctx.fillRect(0, 0, canvas.width, canvas.height); - var maxTime = (now.unix() - week.unix()); - var ranges = []; - var minTime = null; - uptimes.map(function (element, index) { - var positionForMaxTime = (element.date.unix() - week.unix()); - var percent = Math.round((positionForMaxTime / maxTime) * 100); - if (ranges.length == 0 && minTime == null) { - if (element.up && minTime == null) { - ranges.push({ - min: 0, - max: percent - }); - } - else { - minTime = percent; - } - } - else { - if (!element.up) { - minTime = percent; - if (minTime != null && index == uptimes.length - 1) { - ranges.push({ - min: minTime, - max: 100 - }); - } - } - else { - if (minTime) { - ranges.push({ - min: minTime, - max: percent - }); - } - } - } - }); - ctx.fillStyle = '#ff0000'; - ranges.map(function (value) { - ctx.fillRect(value.min, 0, value.max - value.min, canvas.height); - }); - (0, fs_1.writeFile)('test.png', canvas.toBuffer('image/png'), function (err) { - if (err) - throw err; - console.log('Image saved!'); - }); -} -createUptimeBar([ - { - up: true, - date: dayjs().subtract(6, 'day') - }, - { - up: false, - date: dayjs().subtract(3, 'day') - }, - { - up: true, - date: dayjs().subtract(1, 'day') - }, - { - up: false, - date: dayjs().subtract(1, 'hour') - } -]); diff --git a/test.png b/test.png deleted file mode 100644 index b03665b..0000000 Binary files a/test.png and /dev/null differ diff --git a/test.ts b/test.ts deleted file mode 100644 index 3c1b65d..0000000 --- a/test.ts +++ /dev/null @@ -1,81 +0,0 @@ -import { Canvas } from "canvas"; -import * as dayjs from "dayjs"; -import { Dayjs } from "dayjs"; -import { writeFile } from "fs"; - -function createUptimeBar(uptimes: { up: boolean, date: Dayjs }[]) { - const now = dayjs(); - const week = now.clone().subtract(1, 'week'); - - const canvas = new Canvas(100, 2, "image"); - const ctx = canvas.getContext('2d'); - - ctx.fillStyle = "#27FF00"; - ctx.fillRect(0, 0, canvas.width, canvas.height); - - const maxTime = (now.unix() - week.unix()); - const ranges: { min: number, max: number }[] = []; - - let minTime: number | null = null; - uptimes.map((element, index) => { - const positionForMaxTime = (element.date.unix() - week.unix()); - const percent = Math.round((positionForMaxTime / maxTime) * 100); - - if (ranges.length == 0 && minTime == null) { - if (element.up && minTime == null) { - ranges.push({ - min: 0, - max: percent - }); - } else { - minTime = percent; - } - } else { - if (!element.up) { - minTime = percent; - - if(minTime != null && index == uptimes.length - 1) { - ranges.push({ - min: minTime, - max: 100 - }); - } - } else { - if (minTime) { - ranges.push({ - min: minTime, - max: percent - }); - } - } - } - }); - ctx.fillStyle = '#ff0000'; - ranges.map((value) => { - ctx.fillRect(value.min, 0, value.max - value.min, canvas.height); - }); - - writeFile('test.png', canvas.toBuffer('image/png'), (err) => { - if (err) throw err; - console.log('Image saved!'); - }); -} - -createUptimeBar([ - { - up: true, - date: dayjs().subtract(6, 'day') - }, - { - up: false, - date: dayjs().subtract(3, 'day') - }, - { - up: true, - date: dayjs().subtract(1, 'day') - }, - { - up: false, - date: dayjs().subtract(1, 'hour') - } -]); \ No newline at end of file