Files
iptv/scripts/core/issueParser.ts

50 lines
1.5 KiB
TypeScript
Raw Normal View History

2023-09-22 05:17:22 +03:00
import { Dictionary } from '@freearhey/core'
2023-09-17 04:08:50 +03:00
import { Issue } from '../models'
2025-02-22 12:54:00 +03:00
import { IssueData } from './issueData'
2023-09-17 04:08:50 +03:00
const FIELDS = new Dictionary({
2025-03-29 11:39:46 +03:00
'Stream ID': 'streamId',
2025-03-09 19:53:25 +03:00
'Channel ID': 'channelId',
2025-03-29 11:39:46 +03:00
'Feed ID': 'feedId',
2025-03-09 19:53:25 +03:00
'Stream URL': 'streamUrl',
2025-05-01 00:51:41 +03:00
'New Stream URL': 'newStreamUrl',
2023-09-17 04:08:50 +03:00
Label: 'label',
Quality: 'quality',
2025-03-09 19:53:25 +03:00
'Channel Name': 'channelName',
'HTTP User-Agent': 'httpUserAgent',
'HTTP User Agent': 'httpUserAgent',
'HTTP Referrer': 'httpReferrer',
2023-09-18 01:51:15 +03:00
'What happened to the stream?': 'reason',
2023-09-17 04:08:50 +03:00
Reason: 'reason',
2025-07-10 21:13:43 +03:00
Notes: 'notes',
Directives: 'directives'
2023-09-17 04:08:50 +03:00
})
2023-09-15 18:40:35 +03:00
export class IssueParser {
2023-09-22 06:22:47 +03:00
parse(issue: { number: number; body: string; labels: { name: string }[] }): Issue {
2025-02-27 20:55:39 +03:00
const fields = typeof issue.body === 'string' ? issue.body.split('###') : []
2023-09-15 18:40:35 +03:00
2023-09-17 04:08:50 +03:00
const data = new Dictionary()
2023-09-15 18:40:35 +03:00
fields.forEach((field: string) => {
2025-02-27 20:55:39 +03:00
const parsed = typeof field === 'string' ? field.split(/\r?\n/).filter(Boolean) : []
2024-12-26 03:10:22 +03:00
let _label = parsed.shift()
2025-03-29 11:39:46 +03:00
_label = _label ? _label.replace(/ \(optional\)| \(required\)/, '').trim() : ''
2024-12-26 03:10:22 +03:00
let _value = parsed.join('\r\n')
2023-09-15 18:40:35 +03:00
_value = _value ? _value.trim() : ''
if (!_label || !_value) return data
2023-09-17 04:08:50 +03:00
const id: string = FIELDS.get(_label)
2023-09-15 18:40:35 +03:00
const value: string = _value === '_No response_' || _value === 'None' ? '' : _value
if (!id) return
data.set(id, value)
})
2023-09-18 18:24:40 +03:00
const labels = issue.labels.map(label => label.name)
2025-02-22 12:54:00 +03:00
return new Issue({ number: issue.number, labels, data: new IssueData(data) })
2023-09-15 18:40:35 +03:00
}
}