Files
epg/scripts/core/api.js

33 lines
679 B
JavaScript
Raw Normal View History

2022-01-30 04:37:27 +03:00
const _ = require('lodash')
2022-01-30 05:50:38 +03:00
const file = require('./file')
2023-05-15 19:11:07 +03:00
const DATA_DIR = process.env.DATA_DIR || './scripts/tmp/data'
2022-01-30 04:37:27 +03:00
2022-01-30 04:02:29 +03:00
class API {
constructor(filepath) {
2022-01-30 05:50:38 +03:00
this.filepath = file.resolve(filepath)
}
async load() {
const data = await file.read(this.filepath)
this.collection = JSON.parse(data)
2022-01-30 04:02:29 +03:00
}
2022-01-30 04:37:27 +03:00
find(query) {
return _.find(this.collection, query)
2022-01-30 04:02:29 +03:00
}
2022-03-04 00:38:35 +03:00
all() {
return this.collection
}
2022-01-30 04:02:29 +03:00
}
const api = {}
2022-01-30 05:50:38 +03:00
api.channels = new API(`${DATA_DIR}/channels.json`)
2022-10-26 04:35:37 +03:00
api.regions = new API(`${DATA_DIR}/regions.json`)
2022-01-30 05:50:38 +03:00
api.countries = new API(`${DATA_DIR}/countries.json`)
api.subdivisions = new API(`${DATA_DIR}/subdivisions.json`)
2022-01-30 04:02:29 +03:00
module.exports = api