Skip to content

Commit 3388ea1

Browse files
committed
Add Iconsets List UIDs API
1 parent 9a4439d commit 3388ea1

File tree

3 files changed

+387
-356
lines changed

3 files changed

+387
-356
lines changed

lib/api.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import Security from './api/security.js';
1111
import Contacts from './api/contacts.js';
1212
import Profile from './api/profile.js';
1313
import Files from './api/files.js';
14+
import Iconsets from './api/iconsets.js';
1415
import Injectors from './api/injectors.js';
1516
import Repeater from './api/repeater.js';
1617
import Group from './api/groups.js';
@@ -30,6 +31,7 @@ export const CommandList: Record<string, keyof TAKAPI> = {
3031
'mission-log': 'MissionLog',
3132
'mission-layer': 'MissionLayer',
3233
credential: 'Credentials',
34+
iconsets: 'Iconsets',
3335
contact: 'Contacts',
3436
subscription: 'Subscription',
3537
injector: 'Injectors',
@@ -53,6 +55,7 @@ export default class TAKAPI {
5355
Mission: Mission;
5456
Locate: Locate;
5557
Security: Security;
58+
Iconsets: Iconsets;
5659
MissionLog: MissionLog;
5760
MissionLayer: MissionLayer;
5861
Credentials: Credentials;
@@ -78,6 +81,7 @@ export default class TAKAPI {
7881
this.Profile = new Profile(this);
7982
this.OAuth = new OAuth(this);
8083
this.Export = new Export(this);
84+
this.Iconsets = new Iconsets(this);
8185
this.Mission = new Mission(this);
8286
this.MissionLog = new MissionLog(this);
8387
this.MissionLayer = new MissionLayer(this);

lib/api/iconsets.ts

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import { TAKList } from './types.js';
2+
import type { ParsedArgs } from 'minimist'
3+
import { Type, Static } from '@sinclair/typebox';
4+
import Commands, { CommandOutputFormat } from '../commands.js';
5+
6+
export const TAKList_Iconsets = TAKList(Type.String());
7+
8+
export default class InjectorCommands extends Commands {
9+
schema = {
10+
list: {
11+
description: 'List Iconsets',
12+
params: Type.Object({}),
13+
query: Type.Object({}),
14+
formats: [ CommandOutputFormat.JSON ]
15+
}
16+
}
17+
18+
async cli(args: ParsedArgs): Promise<object | string> {
19+
if (args._[3] === 'list') {
20+
const list = await this.list();
21+
22+
if (args.format === 'json') {
23+
return list;
24+
} else {
25+
return list.data.map((iconset) => {
26+
return iconset;
27+
}).join('\n');
28+
}
29+
} else {
30+
throw new Error('Unsupported Subcommand');
31+
}
32+
}
33+
34+
/**
35+
* Return a list of iconset UIDs
36+
*
37+
* {@link https://docs.tak.gov/api/takserver/redoc#tag/iconset-icon-api/operation/getAllIconsetUids TAK Server Docs}.
38+
*/
39+
async list(): Promise<Static<typeof TAKList_Iconsets>> {
40+
const url = new URL('/Marti/api/iconset/all/uid', this.api.url);
41+
42+
return await this.api.fetch(url, {
43+
method: 'GET'
44+
});
45+
}
46+
}

0 commit comments

Comments
 (0)