iptv/scripts/core/api.js

42 lines
1.0 KiB
JavaScript
Raw Normal View History

2022-02-05 00:28:21 +01:00
const _ = require('lodash')
const file = require('./file')
2023-04-30 04:16:45 +02:00
const DATA_DIR = process.env.DATA_DIR || './scripts/tmp/data'
2022-02-05 00:28:21 +01:00
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)
}
2022-02-06 22:04:56 +01:00
filter(query) {
return _.filter(this.collection, query)
}
all() {
return this.collection
}
2022-02-05 00:28:21 +01:00
}
const api = {}
api.channels = new API(`${DATA_DIR}/channels.json`)
2022-08-10 02:40:15 +02:00
api.streams = new API(`${DATA_DIR}/streams.json`)
2022-02-05 00:28:21 +01:00
api.countries = new API(`${DATA_DIR}/countries.json`)
2022-02-06 22:04:56 +01:00
api.guides = new API(`${DATA_DIR}/guides.json`)
api.categories = new API(`${DATA_DIR}/categories.json`)
api.languages = new API(`${DATA_DIR}/languages.json`)
api.regions = new API(`${DATA_DIR}/regions.json`)
api.blocklist = new API(`${DATA_DIR}/blocklist.json`)
api.subdivisions = new API(`${DATA_DIR}/subdivisions.json`)
2022-02-05 00:28:21 +01:00
module.exports = api