Update export.js
This commit is contained in:
parent
27b348efb0
commit
c4c9140095
|
@ -1,14 +1,19 @@
|
||||||
const { logger, db, file } = require('../../core')
|
const { logger, db, api, file } = require('../../core')
|
||||||
const _ = require('lodash')
|
const _ = require('lodash')
|
||||||
|
const dayjs = require('dayjs')
|
||||||
|
const utc = require('dayjs/plugin/utc')
|
||||||
|
dayjs.extend(utc)
|
||||||
|
|
||||||
const PUBLIC_DIR = process.env.PUBLIC_DIR || '.api'
|
const PUBLIC_DIR = process.env.PUBLIC_DIR || '.api'
|
||||||
|
|
||||||
async function main() {
|
async function main() {
|
||||||
|
await api.streams.load()
|
||||||
await db.streams.load()
|
await db.streams.load()
|
||||||
|
const now = dayjs.utc().format()
|
||||||
let streams = await db.streams.find({})
|
let streams = await db.streams.find({})
|
||||||
streams = _.sortBy(streams, 'channel')
|
streams = _.sortBy(streams, 'channel')
|
||||||
streams = streams.map(stream => {
|
streams = streams.map(stream => {
|
||||||
return {
|
const data = {
|
||||||
channel: stream.channel,
|
channel: stream.channel,
|
||||||
url: stream.url,
|
url: stream.url,
|
||||||
http_referrer: stream.http_referrer,
|
http_referrer: stream.http_referrer,
|
||||||
|
@ -19,6 +24,26 @@ async function main() {
|
||||||
bitrate: stream.bitrate,
|
bitrate: stream.bitrate,
|
||||||
frame_rate: stream.frame_rate
|
frame_rate: stream.frame_rate
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let addedAt = now
|
||||||
|
let updatedAt = now
|
||||||
|
let found = api.streams.find({ url: stream.url })
|
||||||
|
if (found) {
|
||||||
|
normalized = _.omit(found, ['added_at', 'updated_at', 'checked_at'])
|
||||||
|
if (_.isEqual(data, normalized)) {
|
||||||
|
addedAt = found.added_at || now
|
||||||
|
updatedAt = found.updated_at || now
|
||||||
|
} else {
|
||||||
|
addedAt = found.added_at || now
|
||||||
|
updatedAt = now
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
data.added_at = addedAt
|
||||||
|
data.updated_at = updatedAt
|
||||||
|
data.checked_at = now
|
||||||
|
|
||||||
|
return data
|
||||||
})
|
})
|
||||||
|
|
||||||
await file.create(`${PUBLIC_DIR}/streams.json`, JSON.stringify(streams))
|
await file.create(`${PUBLIC_DIR}/streams.json`, JSON.stringify(streams))
|
||||||
|
|
Loading…
Reference in New Issue