Fix admin rename payload and harden RustDesk ID sync
This commit is contained in:
parent
bd1bd4bef1
commit
f7ad7f6a17
4 changed files with 146 additions and 6 deletions
|
|
@ -2166,6 +2166,37 @@ function normalizeRemoteAccessList(raw: unknown): RemoteAccessEntry[] {
|
|||
return entries
|
||||
}
|
||||
|
||||
async function removeDuplicateRemoteAccessEntries(
|
||||
ctx: MutationCtx,
|
||||
tenantId: string,
|
||||
currentMachineId: Id<"machines">,
|
||||
provider: string,
|
||||
identifier: string,
|
||||
now: number
|
||||
) {
|
||||
const machines = await ctx.db
|
||||
.query("machines")
|
||||
.withIndex("by_tenant", (q) => q.eq("tenantId", tenantId))
|
||||
.collect()
|
||||
|
||||
const providerLc = provider.toLowerCase()
|
||||
const identifierLc = identifier.toLowerCase()
|
||||
|
||||
for (const device of machines) {
|
||||
if (device._id === currentMachineId) continue
|
||||
const entries = normalizeRemoteAccessList(device.remoteAccess)
|
||||
const filtered = entries.filter(
|
||||
(entry) =>
|
||||
entry.provider.toLowerCase() !== providerLc || entry.identifier.toLowerCase() !== identifierLc
|
||||
)
|
||||
if (filtered.length === entries.length) continue
|
||||
await ctx.db.patch(device._id, {
|
||||
remoteAccess: filtered.length > 0 ? filtered : null,
|
||||
updatedAt: now,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
async function upsertRemoteAccessSnapshotFromHeartbeat(
|
||||
ctx: MutationCtx,
|
||||
machine: Doc<"machines">,
|
||||
|
|
@ -2189,6 +2220,8 @@ async function upsertRemoteAccessSnapshotFromHeartbeat(
|
|||
snapshotSource: "heartbeat",
|
||||
provider,
|
||||
identifier,
|
||||
machineId: machine._id,
|
||||
hostname: machine.hostname,
|
||||
lastVerifiedAt: timestamp,
|
||||
}
|
||||
|
||||
|
|
@ -2423,6 +2456,7 @@ export const upsertRemoteAccessViaToken = mutation({
|
|||
notes: cleanedNotes,
|
||||
lastVerifiedAt: timestamp,
|
||||
metadata: {
|
||||
source: "machine-token",
|
||||
provider: trimmedProvider,
|
||||
identifier: trimmedIdentifier,
|
||||
url: normalizedUrl,
|
||||
|
|
@ -2430,6 +2464,9 @@ export const upsertRemoteAccessViaToken = mutation({
|
|||
password: cleanedPassword,
|
||||
notes: cleanedNotes,
|
||||
lastVerifiedAt: timestamp,
|
||||
machineId: machine._id,
|
||||
hostname: machine.hostname,
|
||||
tenantId: machine.tenantId,
|
||||
},
|
||||
}
|
||||
|
||||
|
|
@ -2438,6 +2475,8 @@ export const upsertRemoteAccessViaToken = mutation({
|
|||
? existingEntries.map((entry, index) => (index === existingIndex ? updatedEntry : entry))
|
||||
: [...existingEntries, updatedEntry]
|
||||
|
||||
await removeDuplicateRemoteAccessEntries(ctx, machine.tenantId, machine._id, trimmedProvider, trimmedIdentifier, timestamp)
|
||||
|
||||
await ctx.db.patch(machine._id, {
|
||||
remoteAccess: nextEntries,
|
||||
updatedAt: timestamp,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue