mirror of
https://github.com/iptv-org/epg.git
synced 2025-05-09 08:30:06 -04:00
57 lines
1.1 KiB
TypeScript
57 lines
1.1 KiB
TypeScript
import { Collection } from '@freearhey/core'
|
|
import { Issue } from './'
|
|
|
|
enum StatusCode {
|
|
DOWN = 'down',
|
|
WARNING = 'warning',
|
|
OK = 'ok'
|
|
}
|
|
|
|
type Status = {
|
|
code: StatusCode
|
|
emoji: string
|
|
}
|
|
|
|
type SiteProps = {
|
|
domain: string
|
|
issues: Collection
|
|
}
|
|
|
|
export class Site {
|
|
domain: string
|
|
issues: Collection
|
|
|
|
constructor({ domain, issues }: SiteProps) {
|
|
this.domain = domain
|
|
this.issues = issues
|
|
}
|
|
|
|
getStatus(): Status {
|
|
const issuesWithStatusDown = this.issues.filter((issue: Issue) =>
|
|
issue.labels.find(label => label === 'status:down')
|
|
)
|
|
if (issuesWithStatusDown.notEmpty())
|
|
return {
|
|
code: StatusCode.DOWN,
|
|
emoji: '🔴'
|
|
}
|
|
|
|
const issuesWithStatusWarning = this.issues.filter((issue: Issue) =>
|
|
issue.labels.find(label => label === 'status:warning')
|
|
)
|
|
if (issuesWithStatusWarning.notEmpty())
|
|
return {
|
|
code: StatusCode.WARNING,
|
|
emoji: '🟡'
|
|
}
|
|
|
|
return {
|
|
code: StatusCode.OK,
|
|
emoji: '🟢'
|
|
}
|
|
}
|
|
|
|
getIssues(): Collection {
|
|
return this.issues.map((issue: Issue) => issue.getURL())
|
|
}
|
|
}
|