mirror of https://github.com/iptv-org/iptv
Merge branch 'features/db-export' into experiment
commit
4d72198955
@ -0,0 +1,23 @@
|
|||||||
|
const { logger, db, file } = require('../../core')
|
||||||
|
const _ = require('lodash')
|
||||||
|
|
||||||
|
const PUBLIC_DIR = process.env.PUBLIC_DIR || '.gh-pages'
|
||||||
|
|
||||||
|
async function main() {
|
||||||
|
await db.streams.load()
|
||||||
|
let streams = await db.streams.find({})
|
||||||
|
streams = _.sortBy(streams, 'channel_id')
|
||||||
|
streams = streams.map(stream => {
|
||||||
|
return {
|
||||||
|
channel: stream.channel_id,
|
||||||
|
display_name: stream.display_name,
|
||||||
|
url: stream.url,
|
||||||
|
http_referrer: stream.http['referrer'],
|
||||||
|
user_agent: stream.http['user-agent']
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
await file.create(`${PUBLIC_DIR}/streams.json`, JSON.stringify(streams))
|
||||||
|
}
|
||||||
|
|
||||||
|
main()
|
@ -0,0 +1,25 @@
|
|||||||
|
const { execSync } = require('child_process')
|
||||||
|
const fs = require('fs-extra')
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
fs.emptyDirSync('tests/__data__/output')
|
||||||
|
fs.copyFileSync(
|
||||||
|
'tests/__data__/input/database/base_streams.db',
|
||||||
|
'tests/__data__/output/streams.db'
|
||||||
|
)
|
||||||
|
|
||||||
|
const stdout = execSync(
|
||||||
|
'DB_DIR=tests/__data__/output PUBLIC_DIR=tests/__data__/output/.gh-pages npm run db:export',
|
||||||
|
{ encoding: 'utf8' }
|
||||||
|
)
|
||||||
|
})
|
||||||
|
|
||||||
|
it('can create streams.json', () => {
|
||||||
|
expect(content(`output/.gh-pages/streams.json`)).toBe(content(`expected/.gh-pages/streams.json`))
|
||||||
|
})
|
||||||
|
|
||||||
|
function content(filepath) {
|
||||||
|
return fs.readFileSync(`tests/__data__/${filepath}`, {
|
||||||
|
encoding: 'utf8'
|
||||||
|
})
|
||||||
|
}
|
Loading…
Reference in New Issue