Skip to content

Commit e986d57

Browse files
authored
Added Node features to Farms request (#4276)
* feat: added node_features to farm filter options * fix: fixed reload issue * refactor: used ignore instead of manual check for node_features * fix: used a copy of filters in reloadfarms to avoid filters reload on adding node_features option
1 parent 67103ea commit e986d57

File tree

4 files changed

+14
-4
lines changed

4 files changed

+14
-4
lines changed

packages/grid_client/src/modules/models.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -675,6 +675,10 @@ class FarmFilterOptions {
675675
@Expose() @IsOptional() @IsBoolean() randomize?: boolean;
676676
@Expose() @IsOptional() @IsBoolean() ret_count?: boolean;
677677
@Expose() @IsOptional() @IsString() region?: string;
678+
@Expose() @IsOptional() @IsBoolean() planetary?: boolean;
679+
@Expose() @IsOptional() @IsBoolean() mycelium?: boolean;
680+
@Expose() @IsOptional() @IsBoolean() wireguard?: boolean;
681+
@Expose() @IsOptional() node_features?: Features[];
678682
}
679683

680684
class CalculatorModel {

packages/grid_client/src/primitives/nodes.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -387,9 +387,10 @@ class Nodes {
387387
}
388388
return nodes;
389389
}
390-
async filterFarms(options: FilterOptions = {}, url = ""): Promise<FarmInfo[]> {
390+
async filterFarms(options: FarmFilterOptions = {}, url = ""): Promise<FarmInfo[]> {
391391
let farms: FarmInfo[] = [];
392392
url = url || this.proxyURL;
393+
options.node_features = this.getFeaturesFromFilters(options);
393394
const query = this.getFarmUrlQuery(options);
394395
farms = await send("get", urlJoin(url, `/farms?${query}`), "", {});
395396
return farms;
@@ -403,8 +404,9 @@ class Nodes {
403404
* @returns A Promise that resolves to the count of available farms as a number.
404405
* @throws Error if there is an issue with the HTTP request or response.
405406
*/
406-
async getFarmsCount(options: FilterOptions = {}, url = ""): Promise<number> {
407+
async getFarmsCount(options: FarmFilterOptions = {}, url = ""): Promise<number> {
407408
const _options = { ...options };
409+
_options.node_features = this.getFeaturesFromFilters(options);
408410
url = url || this.proxyURL;
409411
_options.ret_count = true;
410412
_options.page = 1;
@@ -504,6 +506,7 @@ class Nodes {
504506
randomize: options.randomize,
505507
ret_count: options.ret_count,
506508
region: options.region,
509+
node_features: options.node_features,
507510
};
508511

509512
return convertObjectToQueryString(params);

packages/playground/src/components/node_selector/TfSelectFarm.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,12 +147,12 @@ export default {
147147
const pageCountTask = useAsync(getFarmPageCount, { default: 1, shouldRun: () => props.validFilters });
148148
const pagination = usePagination();
149149
150-
const reloadFarms = () => farmsTask.value.run(gridStore, filters.value, props.filters.exclusiveFor);
150+
const reloadFarms = () => farmsTask.value.run(gridStore, { ...filters.value }, props.filters.exclusiveFor);
151151
152-
useWatchDeep(filters, farmsTask.value.reset, { ignoreFields: ["page"] });
153152
useWatchDeep(
154153
filters,
155154
async filters => {
155+
farmsTask.value.reset();
156156
await pageCountTask.value.run(gridStore, filters);
157157
pagination.value.reset(pageCountTask.value.data as number);
158158
await nextTick();

packages/playground/src/utils/nodeSelector.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,9 @@ export function normalizeFarmFilters(
107107
nodeCertified: filters.certified || undefined,
108108
nodeHasGPU: filters.hasGPU || undefined,
109109
nodeHasIPv6: filters.ipv6 || undefined,
110+
planetary: filters.planetary,
111+
mycelium: filters.mycelium,
112+
wireguard: filters.wireguard,
110113
};
111114
}
112115

0 commit comments

Comments
 (0)