mirror of
https://codeberg.org/timelimit/timelimit-server.git
synced 2026-08-31 19:03:45 +02:00
Add ping support
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* server component for the TimeLimit App
|
||||
* Copyright (C) 2019 - 2024 Jonas Lochmann
|
||||
* Copyright (C) 2019 - 2026 Jonas Lochmann
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
@@ -30,6 +30,7 @@ import { getDeviceDetailList } from './device-detail'
|
||||
import { getDeviceList } from './device-list'
|
||||
import { getDeviceDhKeys } from './dh-keys'
|
||||
import { getFamilyEntry } from './family-entry'
|
||||
import { getPings } from './pings'
|
||||
import { getUserList } from './user-list'
|
||||
import { getKeyRequests } from './key-requests'
|
||||
import { getKeyResponses } from './key-responses'
|
||||
@@ -52,13 +53,14 @@ export const generateServerDataStatus = async ({
|
||||
const doesClientSupportCryptoApps = clientLevel >= 4
|
||||
const doesClientSupportDh = clientLevel >= 5
|
||||
const doesClientSupportU2f = clientLevel >= 6
|
||||
const doesClientSupportPing = clientLevel >= 7
|
||||
|
||||
const result: ServerDataStatus = {
|
||||
fullVersion: config.alwaysPro ? 1 : (
|
||||
familyEntry.hasFullVersion ? parseInt(familyEntry.fullVersionUntil, 10) : 0
|
||||
),
|
||||
message: await getStatusMessage({ database, transaction }) || undefined,
|
||||
apiLevel: 8
|
||||
apiLevel: 9
|
||||
}
|
||||
|
||||
if (familyEntry.deviceListVersion !== clientStatus.devices) {
|
||||
@@ -160,5 +162,14 @@ export const generateServerDataStatus = async ({
|
||||
}) || undefined
|
||||
}
|
||||
|
||||
if (doesClientSupportPing) {
|
||||
result.pings = await getPings({
|
||||
database,
|
||||
transaction,
|
||||
familyEntry,
|
||||
deviceId
|
||||
})
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
@@ -0,0 +1,52 @@
|
||||
/*
|
||||
* server component for the TimeLimit App
|
||||
* Copyright (C) 2019 - 2026 Jonas Lochmann
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, version 3 of the License.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import * as Sequelize from 'sequelize'
|
||||
import { Database } from '../../../database'
|
||||
import { types as pingTypes } from '../../../database/ping'
|
||||
import { ServerPing } from '../../../object/serverdatastatus'
|
||||
import { FamilyEntry } from './family-entry'
|
||||
|
||||
export async function getPings ({
|
||||
database, transaction, familyEntry, deviceId
|
||||
}: {
|
||||
database: Database
|
||||
transaction: Sequelize.Transaction
|
||||
familyEntry: FamilyEntry
|
||||
deviceId: string
|
||||
}): Promise<Array<ServerPing>> {
|
||||
const savedData = await database.ping.findAll({
|
||||
where: {
|
||||
familyId: familyEntry.familyId,
|
||||
receiverDeviceId: deviceId,
|
||||
},
|
||||
attributes: ['senderDeviceId', 'type', 'token'],
|
||||
transaction
|
||||
})
|
||||
|
||||
return savedData.map((row) => ({
|
||||
deviceId: row.senderDeviceId,
|
||||
type: convertType(row.type),
|
||||
token: row.token
|
||||
}))
|
||||
}
|
||||
|
||||
function convertType(type: number): 'ping' | 'pong' {
|
||||
if (type === pingTypes.ping) return 'ping'
|
||||
else if (type === pingTypes.pong) return 'pong'
|
||||
else throw new Error()
|
||||
}
|
||||
Reference in New Issue
Block a user