Files
iptv/scripts/core/issueParser.ts

53 lines
1.6 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({
'Channel ID': 'channel_id',
'Channel ID (required)': 'channel_id',
'Stream URL': 'stream_url',
'Stream URL (optional)': 'stream_url',
'Stream URL (required)': 'stream_url',
2024-12-26 03:10:22 +03:00
'Broken Link': 'broken_links',
'Broken Links': 'broken_links',
2023-09-17 04:08:50 +03:00
Label: 'label',
Quality: 'quality',
2023-11-01 05:38:07 +03:00
Timeshift: 'timeshift',
'Timeshift (optional)': 'timeshift',
2023-09-17 04:08:50 +03:00
'Channel Name': 'channel_name',
'HTTP User-Agent': 'user_agent',
'HTTP Referrer': 'http_referrer',
2023-09-18 01:51:15 +03:00
'What happened to the stream?': 'reason',
2023-09-17 04:08:50 +03:00
Reason: 'reason',
Notes: 'notes',
'Notes (optional)': 'notes'
})
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()
2023-09-15 18:40:35 +03:00
_label = _label ? _label.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
}
}