const deleted = [], updated = []
for (let oldidx = 0, newidx = 0; oldidx < current_data.length || newidx < new_data.length;) {
if (newidx >= new_data.length || current_data[oldidx]?.id < new_data[newidx].id) {
deleted.push(current_data[oldidx])
oldidx++
continue
}
if (oldidx >= current_data.length || current_data[oldidx].id > new_data[newidx]?.id || !lodash.isEqual(new_data[newidx], current_data[oldidx])) {
updated.push(new_data[newidx])
oldidx++
newidx++
continue
}
oldidx++
newidx++
}
const axios = require('axios').default
const axios = require('axios')
// npm i csv-parser
// npm i csv-writer
const fs = require('fs')
const csvParser = require('csv-parser')
const createCsvWriter = require('csv-writer').createObjectCsvWriter
const video = []
fs.createReadStream('./ссылка на файл.csv')
.pipe(csvParser())
.on('data', data => video.push(data))
.on('end', () => {
const movies = video.filter(video => video.TYPE == 'movie')
const serals = video.filter(video => video.TYPE == 'serials')
createCsvWriter({
path: 'папка/названиефайла.csv',
header: Object.keys(movies[0]).map(key => ({ id: key, title: key })) // не важно
}).writeRecords(movies)
createCsvWriter({
path: 'папка/названиефайла.csv',
header: Object.keys(serals[0]).map(key => ({ id: key, title: key }))
}).writeRecords(serals)
})
const session = require('express-session')
const express = require('express')
const app = express()
const server = require('http').Server(app)
const io = require('socket.io')(server)
const sessionMiddleware = session({
secret: '...',
saveUninitialized: false,
resave: false,
store: ...
})
app.use(sessionMiddleware)
io.use((socket, next) => {
sessionMiddleware(socket.request, {}, next)
})
io.on('connect', socket => {
const session = socket.request.session
// Используем примерно так:
session.user.login
})