From c4c91400950f696e64800b39c11ee7613f567dc2 Mon Sep 17 00:00:00 2001 From: Aleksandr Statciuk Date: Wed, 10 Aug 2022 03:41:06 +0300 Subject: [PATCH] Update export.js --- scripts/commands/database/export.js | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/scripts/commands/database/export.js b/scripts/commands/database/export.js index 12990a0820..675a848479 100644 --- a/scripts/commands/database/export.js +++ b/scripts/commands/database/export.js @@ -1,14 +1,19 @@ -const { logger, db, file } = require('../../core') +const { logger, db, api, file } = require('../../core') const _ = require('lodash') +const dayjs = require('dayjs') +const utc = require('dayjs/plugin/utc') +dayjs.extend(utc) const PUBLIC_DIR = process.env.PUBLIC_DIR || '.api' async function main() { + await api.streams.load() await db.streams.load() + const now = dayjs.utc().format() let streams = await db.streams.find({}) streams = _.sortBy(streams, 'channel') streams = streams.map(stream => { - return { + const data = { channel: stream.channel, url: stream.url, http_referrer: stream.http_referrer, @@ -19,6 +24,26 @@ async function main() { bitrate: stream.bitrate, 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))