Skip to content

Commit

Permalink
feat: move method
Browse files Browse the repository at this point in the history
  • Loading branch information
alexey-yarmosh committed Apr 9, 2024
1 parent 0713f5d commit 7af1a5e
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 26 deletions.
29 changes: 29 additions & 0 deletions src/lib/adopted-probes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { scopedLogger } from './logger.js';
import type { fetchProbesWithAdminData as serverFetchProbesWithAdminData } from './ws/server.js';
import type { Probe } from '../probe/types.js';
import { normalizeFromPublicName } from './geoip/utils.js';
import { getIndex } from '../probe/builder.js';

const logger = scopedLogger('adopted-probes');

Expand Down Expand Up @@ -125,6 +126,34 @@ export class AdoptedProbes {
];
}

getUpdatedProbes (probes: Probe[]) {
return probes.map((probe) => {
const adopted = this.getByIp(probe.ipAddress);

if (!adopted) {
return probe;
}

const isCustomCity = adopted.isCustomCity;
const hasUserTags = adopted.tags && adopted.tags.length;

if (!isCustomCity && !hasUserTags) {
return probe;
}

const newLocation = this.getUpdatedLocation(probe);

const newTags = this.getUpdatedTags(probe);

return {
...probe,
location: newLocation,
tags: newTags,
index: getIndex(newLocation, newTags),
};
});
}

scheduleSync () {
setTimeout(() => {
this.syncDashboardData()
Expand Down
27 changes: 1 addition & 26 deletions src/lib/probe-override.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { getIndex } from '../probe/builder.js';
import type { Probe } from '../probe/types.js';
import type { AdoptedProbes } from './adopted-probes.js';
import type { AdminData } from './admin-data.js';
Expand Down Expand Up @@ -32,30 +31,6 @@ export class ProbeOverride {
}

addAdoptedData (probes: Probe[]) {
return probes.map((probe) => {
const adopted = this.adoptedProbes.getByIp(probe.ipAddress);

if (!adopted) {
return probe;
}

const isCustomCity = adopted.isCustomCity;
const hasUserTags = adopted.tags && adopted.tags.length;

if (!isCustomCity && !hasUserTags) {
return probe;
}

const newLocation = this.adoptedProbes.getUpdatedLocation(probe);

const newTags = this.adoptedProbes.getUpdatedTags(probe);

return {
...probe,
location: newLocation,
tags: newTags,
index: getIndex(newLocation, newTags),
};
});
return this.adoptedProbes.getUpdatedProbes(probes);
}
}

0 comments on commit 7af1a5e

Please sign in to comment.