mirror of
https://github.com/iptv-org/epg
synced 2026-03-22 11:50:59 -04:00
Update scripts
This commit is contained in:
@@ -3,3 +3,4 @@ export * from './issue'
|
||||
export * from './site'
|
||||
export * from './channel'
|
||||
export * from './program'
|
||||
export * from './worker'
|
||||
|
||||
68
scripts/models/worker.ts
Normal file
68
scripts/models/worker.ts
Normal file
@@ -0,0 +1,68 @@
|
||||
import relativeTime from 'dayjs/plugin/relativeTime'
|
||||
import { Collection } from '@freearhey/core'
|
||||
import { Channel } from './channel'
|
||||
import dayjs from 'dayjs'
|
||||
|
||||
dayjs.extend(relativeTime)
|
||||
|
||||
export interface WorkerData {
|
||||
host: string
|
||||
}
|
||||
|
||||
export class Worker {
|
||||
host: string
|
||||
channelsPath?: string
|
||||
guidePath?: string
|
||||
channels?: Collection<Channel>
|
||||
status?: string
|
||||
lastUpdated?: string
|
||||
|
||||
constructor(data: WorkerData) {
|
||||
this.host = data.host
|
||||
}
|
||||
|
||||
getBaseUrl(): string {
|
||||
return `https://${this.host}`
|
||||
}
|
||||
|
||||
getConfigUrl(): string {
|
||||
const url = new URL('worker.json', this.getBaseUrl())
|
||||
|
||||
return url.href
|
||||
}
|
||||
|
||||
getChannelsUrl(): string {
|
||||
if (!this.channelsPath) return ''
|
||||
|
||||
const url = new URL(this.channelsPath, this.getBaseUrl())
|
||||
|
||||
return url.href
|
||||
}
|
||||
|
||||
getGuideUrl(): string {
|
||||
if (!this.guidePath) return ''
|
||||
|
||||
const url = new URL(this.guidePath, this.getBaseUrl())
|
||||
|
||||
return url.href
|
||||
}
|
||||
|
||||
getStatusEmoji(): string {
|
||||
if (!this.status) return '⚪'
|
||||
if (this.status === 'OK') return '🟢'
|
||||
|
||||
return '🔴'
|
||||
}
|
||||
|
||||
getChannelsCount(): number {
|
||||
if (!this.channels) return 0
|
||||
|
||||
return this.channels.count()
|
||||
}
|
||||
|
||||
getLastUpdated(): string {
|
||||
if (!this.lastUpdated) return '-'
|
||||
|
||||
return dayjs().to(dayjs(this.lastUpdated))
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user