iptv/scripts/core/issueParser.ts

49 lines
1.3 KiB
TypeScript
Raw Normal View History

2023-09-22 04:17:22 +02:00
import { Dictionary } from '@freearhey/core'
2023-09-17 03:08:50 +02:00
import { Issue } from '../models'
const FIELDS = new Dictionary({
'Channel ID': 'channel_id',
'Channel ID (required)': 'channel_id',
'Stream URL': 'stream_url',
'Stream URL (optional)': 'stream_url',
'Stream URL (required)': 'stream_url',
2023-09-18 00:51:15 +02:00
'Broken Link': 'stream_url',
2023-09-17 03:08:50 +02:00
Label: 'label',
Quality: 'quality',
2023-11-01 03:38:07 +01:00
Timeshift: 'timeshift',
'Timeshift (optional)': 'timeshift',
2023-09-17 03:08:50 +02:00
'Channel Name': 'channel_name',
'HTTP User-Agent': 'user_agent',
'HTTP Referrer': 'http_referrer',
2023-09-18 00:51:15 +02:00
'What happened to the stream?': 'reason',
2023-09-17 03:08:50 +02:00
Reason: 'reason',
Notes: 'notes',
'Notes (optional)': 'notes'
})
2023-09-15 17:40:35 +02:00
export class IssueParser {
2023-09-22 05:22:47 +02:00
parse(issue: { number: number; body: string; labels: { name: string }[] }): Issue {
2023-09-15 17:40:35 +02:00
const fields = issue.body.split('###')
2023-09-17 03:08:50 +02:00
const data = new Dictionary()
2023-09-15 17:40:35 +02:00
fields.forEach((field: string) => {
let [_label, , _value] = field.split(/\r?\n/)
_label = _label ? _label.trim() : ''
_value = _value ? _value.trim() : ''
if (!_label || !_value) return data
2023-09-17 03:08:50 +02:00
const id: string = FIELDS.get(_label)
2023-09-15 17:40:35 +02:00
const value: string = _value === '_No response_' || _value === 'None' ? '' : _value
if (!id) return
data.set(id, value)
})
2023-09-18 17:24:40 +02:00
const labels = issue.labels.map(label => label.name)
return new Issue({ number: issue.number, labels, data })
2023-09-15 17:40:35 +02:00
}
}