Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions lib/api.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import FormData from 'form-data';
import OAuth from './api/oauth.js';
import Locate from './api/locate.js';
import Package from './api/package.js';
import Query from './api/query.js';
import Mission from './api/mission.js';
Expand All @@ -21,6 +22,7 @@
package: 'Package',
oauth: 'OAuth',
mission: 'Mission',
locate: 'Locate',
'mission-log': 'MissionLog',
'mission-layer': 'MissionLayer',
credential: 'Credentials',
Expand Down Expand Up @@ -53,6 +55,7 @@
Injectors: Injectors;
Repeater: Repeater;
Group: Group;
Locate: Locate;
Video: Video;
Export: Export;
Query: Query;
Expand All @@ -72,6 +75,7 @@
this.Credentials = new Credentials(this);
this.Contacts = new Contacts(this);
this.Subscription = new Subscription(this);
this.Locate = new Locate(this);
this.Group = new Group(this);
this.Video = new Video(this);
this.Injectors = new Injectors(this);
Expand Down Expand Up @@ -104,7 +108,7 @@
* @param {URL|String} url - Full URL or API fragment to request
* @param {Object} [opts={}] - Options
*/
async fetch(url: URL, opts: any = {}, raw=false) {

Check warning on line 111 in lib/api.ts

View workflow job for this annotation

GitHub Actions / test

Unexpected any. Specify a different type

Check warning on line 111 in lib/api.ts

View workflow job for this annotation

GitHub Actions / test

Unexpected any. Specify a different type
url = this.stdurl(url);

try {
Expand All @@ -130,7 +134,7 @@

if (raw) return res;

let bdy: any = {};

Check warning on line 137 in lib/api.ts

View workflow job for this annotation

GitHub Actions / test

Unexpected any. Specify a different type

Check warning on line 137 in lib/api.ts

View workflow job for this annotation

GitHub Actions / test

Unexpected any. Specify a different type

if ((res.status < 200 || res.status >= 400)) {
try {
Expand Down
46 changes: 45 additions & 1 deletion lib/api/groups.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,27 @@ export const GroupListInput = Type.Object({
useCache: Type.Optional(Type.Boolean())
})

export const MemberListInput = Type.Object({
groupNameFilter: Type.String()
})

export const TAKList_Group = TAKList(Group);
export const TAKList_Member = TAKList(Group);

export default class GroupCommands extends Commands {
schema = {
list: {
description: 'List Missions',
description: 'List Groups',
params: Type.Object({}),
query: Type.Object({}),
formats: [ CommandOutputFormat.JSON ]
},

'list-members': {
description: 'List Members',
params: Type.Object({}),
query: Type.Object(MemberListInput),
formats: [ CommandOutputFormat.JSON ]
}
}

Expand All @@ -40,6 +52,19 @@ export default class GroupCommands extends Commands {
return `${channel.name} - ${channel.description}`;
}).join('\n');
}
} else if (args._[3] === 'list-members') {
const list = await this.members({
groupNameFilter: args.groupNameFilter || ''
});

if (args.format === 'json') {
return list;
} else {
return list.data.map((member) => {
console.error(member);
return `${channel.name} - ${channel.description}`;
}).join('\n');
}
} else {
throw new Error('Unsupported Subcommand');
}
Expand Down Expand Up @@ -80,4 +105,23 @@ export default class GroupCommands extends Commands {
body
});
}

async members(
query: Static<typeof MemberListInput> = {}
): Promise<Static<typeof TAKList_Member>> {
const url = new URL(`/Marti/api/groups/members`, this.api.url);

let q: keyof Static<typeof MemberListInput>;
for (q in query) {
if (query[q] !== undefined) {
url.searchParams.append(q, String(query[q]));
}
}

console.error(url);

return await this.api.fetch(url, {
method: 'GET'
});
}
}
Loading