mirror of https://github.com/iptv-org/iptv
You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
27 lines
549 B
JavaScript
27 lines
549 B
JavaScript
3 years ago
|
const _ = require('lodash')
|
||
|
const file = require('./file')
|
||
|
|
||
|
const DATA_DIR = process.env.DATA_DIR || './scripts/data'
|
||
|
|
||
|
class API {
|
||
|
constructor(filepath) {
|
||
|
this.filepath = file.resolve(filepath)
|
||
|
}
|
||
|
|
||
|
async load() {
|
||
|
const data = await file.read(this.filepath)
|
||
|
this.collection = JSON.parse(data)
|
||
|
}
|
||
|
|
||
|
find(query) {
|
||
|
return _.find(this.collection, query)
|
||
|
}
|
||
|
}
|
||
|
|
||
|
const api = {}
|
||
|
|
||
|
api.channels = new API(`${DATA_DIR}/channels.json`)
|
||
|
api.countries = new API(`${DATA_DIR}/countries.json`)
|
||
|
|
||
|
module.exports = api
|