update(object){ let existingRecord = this._table.get(parseInt(object.id)); if (!existingRecord) return; for (let property in object){ // id is an artificial property added on returned objects only, so do not persist it if (property === 'id') continue; existingRecord[property] = object[property]; } this._table.update(existingRecord); }
srv.on('UPDATE', 'Media', (req, next) => { const url = req._.req.path if (url.includes('content')) { const id = req.data.id const obj = mediaDB.get(id) if (!obj) { req.reject(404, 'No record found for the ID') return } const stream = new PassThrough() const chunks = [] stream.on('data', chunk => { chunks.push(chunk) }) stream.on('end', () => { obj.media = Buffer.concat(chunks).toString('base64') mediaDB.update(obj) }) req.data.content.pipe(stream) } else return next() })
clients.update(client);