diff --git a/server/services/monitoringService.ts b/server/services/monitoringService.ts index 2a043f9..416ff81 100644 --- a/server/services/monitoringService.ts +++ b/server/services/monitoringService.ts @@ -16,7 +16,7 @@ import {normalizeMac} from "../utils/strings"; import {monitoringDisableUrl} from "../utils/urlBuilder"; import CONSTRAINTS from "../validation/constraints"; import {forConstraint} from "../validation/validator"; -import {MAC, MailType, Node, NodeId, NodeState, NodeStateData, UnixTimestamp} from "../types"; +import {MAC, MailType, Node, NodeId, NodeState, NodeStateData, UnixTimestampSeconds} from "../types"; const MONITORING_STATE_MACS_CHUNK_SIZE = 100; const NEVER_ONLINE_NODES_DELETION_CHUNK_SIZE = 20; @@ -688,7 +688,7 @@ export async function deleteOfflineNodes(): Promise { await deleteNodesOfflineSinceBefore(deleteBefore); } -async function deleteNeverOnlineNodesBefore(deleteBefore: UnixTimestamp): Promise { +async function deleteNeverOnlineNodesBefore(deleteBefore: UnixTimestampSeconds): Promise { Logger .tag('nodes', 'delete-never-online') .info( @@ -765,7 +765,7 @@ async function deleteNeverOnlineNodesBefore(deleteBefore: UnixTimestamp): Promis } } -async function deleteNodesOfflineSinceBefore(deleteBefore: UnixTimestamp): Promise { +async function deleteNodesOfflineSinceBefore(deleteBefore: UnixTimestampSeconds): Promise { const rows = await db.all( 'SELECT * FROM node_state WHERE state = ? AND last_seen < ?', [ diff --git a/server/services/nodeService.ts b/server/services/nodeService.ts index d1bbeb4..9f20bc7 100644 --- a/server/services/nodeService.ts +++ b/server/services/nodeService.ts @@ -10,7 +10,7 @@ import Logger from "../logger"; import * as MailService from "../services/mailService"; import {normalizeString} from "../utils/strings"; import {monitoringConfirmUrl, monitoringDisableUrl} from "../utils/urlBuilder"; -import {FastdKey, MonitoringState, MonitoringToken, Node, NodeSecrets, NodeStatistics, UnixTimestamp, Token} from "../types"; +import {FastdKey, MonitoringState, MonitoringToken, Node, NodeSecrets, NodeStatistics, UnixTimestampSeconds, Token} from "../types"; import util from "util"; const pglob = util.promisify(glob); @@ -235,7 +235,7 @@ async function deleteNodeFile(token: Token): Promise { async function parseNodeFile(file: string): Promise<{node: Node, nodeSecrets: NodeSecrets}> { const contents = await fs.readFile(file); const stats = await fs.lstat(file); - const modifiedAt = stats.mtimeMs; + const modifiedAt = Math.floor(stats.mtimeMs / 1000); const lines = contents.toString(); @@ -491,7 +491,7 @@ export async function fixNodeFilenames(): Promise { } } -export async function findNodesModifiedBefore(timestamp: UnixTimestamp): Promise { +export async function findNodesModifiedBefore(timestamp: UnixTimestampSeconds): Promise { const nodes = await getAllNodes(); return _.filter(nodes, node => node.modifiedAt < timestamp); } diff --git a/server/types/index.ts b/server/types/index.ts index de03658..8b27f9d 100644 --- a/server/types/index.ts +++ b/server/types/index.ts @@ -6,7 +6,8 @@ export type Token = string; export type FastdKey = string; export type MAC = string; -export type UnixTimestamp = number; +export type UnixTimestampSeconds = number; +export type UnixTimestampMilliseconds = number; export type MonitoringToken = string; export enum MonitoringState { @@ -39,7 +40,7 @@ export type Node = { monitoring: boolean; monitoringConfirmed: boolean; monitoringState: MonitoringState; - modifiedAt: UnixTimestamp; + modifiedAt: UnixTimestampSeconds; }; // TODO: Complete interface / class declaration.