feat: release desktop 0.1.9 with device dedupe and new branding
This commit is contained in:
@@ -2750,6 +2750,62 @@ const DeviceSessionDB = {
|
||||
`).all(Math.floor(uid), safeLimit);
|
||||
},
|
||||
|
||||
listActiveByDevice(userId, options = {}) {
|
||||
const uid = Number(userId);
|
||||
if (!Number.isFinite(uid) || uid <= 0) return [];
|
||||
|
||||
const clientType = this._normalizeClientType(options.clientType);
|
||||
const deviceId = this._normalizeText(options.deviceId, 128);
|
||||
const deviceName = this._normalizeText(options.deviceName, 120);
|
||||
const platform = this._normalizeText(options.platform, 80);
|
||||
const safeLimit = Math.max(1, Math.min(50, Math.floor(Number(options.limit) || 20)));
|
||||
|
||||
if (deviceId) {
|
||||
return db.prepare(`
|
||||
SELECT *
|
||||
FROM user_device_sessions
|
||||
WHERE user_id = ?
|
||||
AND client_type = ?
|
||||
AND device_id = ?
|
||||
AND revoked_at IS NULL
|
||||
AND expires_at > datetime('now', 'localtime')
|
||||
ORDER BY datetime(COALESCE(last_active_at, created_at)) DESC, created_at DESC
|
||||
LIMIT ?
|
||||
`).all(Math.floor(uid), clientType, deviceId, safeLimit);
|
||||
}
|
||||
|
||||
if (clientType !== 'desktop') {
|
||||
return [];
|
||||
}
|
||||
|
||||
const extraConditions = [];
|
||||
const params = [Math.floor(uid), clientType];
|
||||
if (deviceName) {
|
||||
extraConditions.push("COALESCE(device_name, '') = ?");
|
||||
params.push(deviceName);
|
||||
}
|
||||
if (platform) {
|
||||
extraConditions.push("COALESCE(platform, '') = ?");
|
||||
params.push(platform);
|
||||
}
|
||||
if (extraConditions.length === 0) {
|
||||
return [];
|
||||
}
|
||||
|
||||
params.push(safeLimit);
|
||||
return db.prepare(`
|
||||
SELECT *
|
||||
FROM user_device_sessions
|
||||
WHERE user_id = ?
|
||||
AND client_type = ?
|
||||
AND ${extraConditions.join(' AND ')}
|
||||
AND revoked_at IS NULL
|
||||
AND expires_at > datetime('now', 'localtime')
|
||||
ORDER BY datetime(COALESCE(last_active_at, created_at)) DESC, created_at DESC
|
||||
LIMIT ?
|
||||
`).all(...params);
|
||||
},
|
||||
|
||||
touch(sessionId, options = {}) {
|
||||
const sid = this._normalizeSessionId(sessionId);
|
||||
if (!sid) return { changes: 0 };
|
||||
|
||||
Reference in New Issue
Block a user