记录连接时间
parent
5099ba9c96
commit
9ac26be65d
|
@ -3,8 +3,8 @@ const sio = require('socket.io')
|
|||
const { createHttpTerminator } = require('http-terminator')
|
||||
const modules = require('../modules')
|
||||
const { authCode, authConnect } = require('./auth')
|
||||
const { getAddress, getServerId, generateCode, getClientKeyInfo } = require('./utils')
|
||||
const syncList = require('./syncList')
|
||||
const { getAddress, getServerId, generateCode, getClientKeyInfo, setClientKeyInfo } = require('./utils')
|
||||
const { syncList, removeSnapshot } = require('./syncList')
|
||||
const { log } = require('@common/utils')
|
||||
|
||||
|
||||
|
@ -84,6 +84,8 @@ const handleStartServer = (port = 9527) => new Promise((resolve, reject) => {
|
|||
global.lx_event.sync.status(status)
|
||||
})
|
||||
const keyInfo = getClientKeyInfo(socket.handshake.query.i)
|
||||
keyInfo.connectionTime = Date.now()
|
||||
setClientKeyInfo(keyInfo)
|
||||
// socket.lx_keyInfo = keyInfo
|
||||
socket.data.keyInfo = keyInfo
|
||||
try {
|
||||
|
@ -172,3 +174,5 @@ exports.generateCode = async() => {
|
|||
global.lx_event.sync.status(status)
|
||||
return status.code
|
||||
}
|
||||
|
||||
exports.removeSnapshot = removeSnapshot
|
||||
|
|
|
@ -1,8 +1,6 @@
|
|||
const path = require('path')
|
||||
const fs = require('fs')
|
||||
const fsPromises = fs.promises
|
||||
const { app } = require('electron')
|
||||
const { encryptMsg, decryptMsg } = require('./utils')
|
||||
const { encryptMsg, decryptMsg, getSnapshotFilePath } = require('./utils')
|
||||
const SYNC_EVENT_NAMES = require('../event/name')
|
||||
const { common: COMMON_EVENT_NAME } = require('@main/events/_name')
|
||||
const { throttle } = require('@common/utils')
|
||||
|
@ -403,7 +401,7 @@ const registerUpdateSnapshotTask = (socket, snapshot) => {
|
|||
}
|
||||
|
||||
const syncList = async socket => {
|
||||
socket.data.snapshotFilePath = path.join(app.getPath('userData'), `snapshot-${Buffer.from(socket.data.keyInfo.clientId).toString('hex').substring(0, 10)}.json`)
|
||||
socket.data.snapshotFilePath = getSnapshotFilePath(socket.data.keyInfo)
|
||||
let fileData
|
||||
let isSyncRequired = false
|
||||
try {
|
||||
|
@ -423,7 +421,7 @@ const checkSyncQueue = async() => {
|
|||
await wait()
|
||||
return checkSyncQueue()
|
||||
}
|
||||
module.exports = async(_io, socket) => {
|
||||
exports.syncList = async(_io, socket) => {
|
||||
io = _io
|
||||
await checkSyncQueue()
|
||||
syncingId = socket.data.keyInfo.clientId
|
||||
|
@ -434,3 +432,7 @@ module.exports = async(_io, socket) => {
|
|||
syncingId = null
|
||||
})
|
||||
}
|
||||
exports.removeSnapshot = keyInfo => {
|
||||
const filePath = getSnapshotFilePath(keyInfo)
|
||||
return fsPromises.unlink(filePath)
|
||||
}
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
const { app } = require('electron')
|
||||
const { networkInterfaces } = require('os')
|
||||
const { randomBytes, createCipheriv, createDecipheriv } = require('crypto')
|
||||
const path = require('path')
|
||||
const getStore = require('@common/store')
|
||||
const STORE_NAME = 'sync'
|
||||
|
||||
|
@ -91,3 +93,7 @@ exports.decryptMsg = (keyInfo, enMsg) => {
|
|||
// }
|
||||
// return msg
|
||||
}
|
||||
|
||||
exports.getSnapshotFilePath = keyInfo => {
|
||||
return path.join(app.getPath('userData'), `snapshot-${Buffer.from(keyInfo.clientId).toString('hex').substring(0, 10)}.json`)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue