diff --git a/scripts/commands/database/export.js b/scripts/commands/database/export.js index 675a848479..9ce347f7b9 100644 --- a/scripts/commands/database/export.js +++ b/scripts/commands/database/export.js @@ -13,7 +13,7 @@ async function main() { let streams = await db.streams.find({}) streams = _.sortBy(streams, 'channel') streams = streams.map(stream => { - const data = { + let data = { channel: stream.channel, url: stream.url, http_referrer: stream.http_referrer, @@ -29,6 +29,7 @@ async function main() { let updatedAt = now let found = api.streams.find({ url: stream.url }) if (found) { + data = JSON.parse(JSON.stringify(data)) normalized = _.omit(found, ['added_at', 'updated_at', 'checked_at']) if (_.isEqual(data, normalized)) { addedAt = found.added_at || now diff --git a/tests/__data__/input/data/streams.json b/tests/__data__/input/data/streams.json index 69f43a964f..f5b4f45bc0 100644 --- a/tests/__data__/input/data/streams.json +++ b/tests/__data__/input/data/streams.json @@ -1 +1 @@ -[{"channel":"LDPRTV.ru","url":"http://46.46.143.222:1935/live/mp4:ldpr.stream/playlist.m3u8","http_referrer":null,"user_agent":null,"status":"online","width":1920,"height":1080,"bitrate":6542556,"frame_rate":50,"added_at":"2022-07-07T00:00:00Z","checked_at":"2022-08-07T00:00:00Z","updated_at":"2022-08-07T00:00:00Z"},{"channel":"LibyasChannel.ly","url":"https://master.starmena-cloud.com/hls/libyas.m3u8","http_referrer":null,"user_agent":null,"status":"online","width":1024,"height":576,"bitrate":0,"frame_rate":25,"added_at":"2022-07-07T00:00:00Z","checked_at":"2022-07-07T00:00:00Z","updated_at":"2022-07-07T00:00:00Z"}] \ No newline at end of file +[{"channel":"AndorraTV.ad","url":"https://iptv-all.lanesh4d0w.repl.co/andorra/atv","http_referrer":"http://imn.iq","user_agent":"Mozilla/5.0 (iPhone; CPU iPhone OS 12_2 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148","status":"error","added_at":"2022-07-07T00:00:00Z","updated_at":"2022-08-07T00:00:00Z","checked_at":"2022-08-07T00:00:00Z"},{"channel":"LDPRTV.ru","url":"http://46.46.143.222:1935/live/mp4:ldpr.stream/playlist.m3u8","http_referrer":null,"user_agent":null,"status":"online","width":1920,"height":1080,"bitrate":6542556,"frame_rate":50,"added_at":"2022-07-07T00:00:00Z","checked_at":"2022-08-07T00:00:00Z","updated_at":"2022-08-07T00:00:00Z"},{"channel":"LibyasChannel.ly","url":"https://master.starmena-cloud.com/hls/libyas.m3u8","http_referrer":null,"user_agent":null,"status":"online","width":1024,"height":576,"bitrate":0,"frame_rate":25,"added_at":"2022-07-07T00:00:00Z","checked_at":"2022-07-07T00:00:00Z","updated_at":"2022-07-07T00:00:00Z"}] \ No newline at end of file diff --git a/tests/commands/database/export.test.js b/tests/commands/database/export.test.js index 05a3364961..04fba3d36e 100644 --- a/tests/commands/database/export.test.js +++ b/tests/commands/database/export.test.js @@ -21,22 +21,34 @@ it('can create streams.json', () => { let output = content(`output/.api/streams.json`) let expected = content(`expected/.api/streams.json`) - const updatedUrl = 'https://master.starmena-cloud.com/hls/libyas.m3u8' - let outputData = output.find(i => i.url === updatedUrl) - let savedData = api.find(i => i.url === updatedUrl) + const samples = { + unchanged_online: 'https://master.starmena-cloud.com/hls/libyas.m3u8', + unchanged_error: 'https://iptv-all.lanesh4d0w.repl.co/andorra/atv', + updated_error: 'http://46.46.143.222:1935/live/mp4:ldpr.stream/playlist.m3u8', + added_online: 'https://master.starmena-cloud.com/hls/bbc.m3u8' + } + + let outputData, savedData + + outputData = output.find(i => i.url === samples['unchanged_online']) + savedData = api.find(i => i.url === samples['unchanged_online']) expect(outputData.added_at).toBe(savedData.added_at) expect(outputData.updated_at).toBe(savedData.updated_at) expect(dayjs().diff(outputData.checked_at, 'h')).toBe(0) - const sameUrl = 'http://46.46.143.222:1935/live/mp4:ldpr.stream/playlist.m3u8' - outputData = output.find(i => i.url === sameUrl) - savedData = api.find(i => i.url === sameUrl) + outputData = output.find(i => i.url === samples['unchanged_error']) + savedData = api.find(i => i.url === samples['unchanged_error']) + expect(outputData.added_at).toBe(savedData.added_at) + expect(outputData.updated_at).toBe(savedData.updated_at) + expect(dayjs().diff(outputData.checked_at, 'h')).toBe(0) + + outputData = output.find(i => i.url === samples['updated_error']) + savedData = api.find(i => i.url === samples['unchanged_error']) expect(outputData.added_at).toBe(savedData.added_at) expect(dayjs().diff(outputData.updated_at, 'h')).toBe(0) expect(dayjs().diff(outputData.checked_at, 'h')).toBe(0) - const addedUrl = 'https://master.starmena-cloud.com/hls/bbc.m3u8' - outputData = output.find(i => i.url === addedUrl) + outputData = output.find(i => i.url === samples['added_online']) expect(dayjs().diff(outputData.added_at, 'h')).toBe(0) expect(dayjs().diff(outputData.updated_at, 'h')).toBe(0) expect(dayjs().diff(outputData.checked_at, 'h')).toBe(0)