feat(service): add Service entity with properties for service management

This commit is contained in:
2025-11-26 09:45:16 +01:00
parent 58403fd32e
commit 104023162a
7 changed files with 30 additions and 159 deletions

1
.gitignore vendored
View File

@@ -137,3 +137,4 @@ dist
# Vite logs files
vite.config.js.timestamp-*
vite.config.ts.timestamp-*
node.txt

View File

@@ -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;
}

View File

@@ -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<HostsLog>;
private followRepo: Repository<Follow>;
private guildRepo: Repository<Guild>;
private serviceRepo: Repository<Service>;
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()

77
test.js
View File

@@ -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')
}
]);

BIN
test.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 115 B

81
test.ts
View File

@@ -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')
}
]);