Skip to content

Commit

Permalink
Add Mission Subscription APIs
Browse files Browse the repository at this point in the history
  • Loading branch information
ingalls committed Feb 14, 2024
1 parent d8e0124 commit 8a75a94
Show file tree
Hide file tree
Showing 2 changed files with 154 additions and 71 deletions.
83 changes: 83 additions & 0 deletions api/lib/api/mission.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,19 @@ export type Mission = {
missionChanges?: Array<unknown>; // Only present on Mission.get()
}

/**
* @class
*/
export default class {
api: TAKAPI;

constructor(api: TAKAPI) {
this.api = api;
}

/**
* Return users associated with this mission
*/
async contacts(name: string) {
const url = new URL(`/Marti/api/missions/${encodeURIComponent(name)}/contacts`, this.api.url);

Expand All @@ -49,6 +55,9 @@ export default class {
});
}

/**
* Remove a file from the mission
*/
async detachContents(name: string, hash: string) {
const url = new URL(`/Marti/api/missions/${encodeURIComponent(name)}/contents`, this.api.url);
url.searchParams.append('hash', hash);
Expand All @@ -58,6 +67,9 @@ export default class {
});
}

/**
* Attach a file resource by hash from the TAK Server file manager
*/
async attachContents(name: string, hashes: string[]) {
const url = new URL(`/Marti/api/missions/${encodeURIComponent(name)}/contents`, this.api.url);

Expand All @@ -69,6 +81,9 @@ export default class {
});
}

/**
* Upload a Mission Package
*/
async upload(name: string, creatorUid: string, body: Readable) {
const url = new URL(`/Marti/api/missions/${encodeURIComponent(name)}/contents/missionpackage`, this.api.url);
url.searchParams.append('creatorUid', creatorUid);
Expand All @@ -79,6 +94,62 @@ export default class {
});
}

/**
* Subscribe to a mission
*/
async subscribe(query: {
uid: string;
password: string;
secago: number;
start: string;
end: string;

[key: string]: unknown;
}) {
const url = new URL(`/Marti/api/missions/${encodeURIComponent(name)}/subscription`, this.api.url);

for (const q in query) url.searchParams.append(q, String(query[q]));
return await this.api.fetch(url, {
method: 'PUT'
});
}

/**
* Get current subscription status
*/
async subscribed(query: {
uid: string;

[key: string]: unknown;
}) {
const url = new URL(`/Marti/api/missions/${encodeURIComponent(name)}/subscription`, this.api.url);

for (const q in query) url.searchParams.append(q, String(query[q]));
return await this.api.fetch(url, {
method: 'GET'
});
}

/**
* Unsubscribe from a mission
*/
async unsubscribe(query: {
uid: string;
disconnectOnly: string;

[key: string]: unknown;
}) {
const url = new URL(`/Marti/api/missions/${encodeURIComponent(name)}/subscription`, this.api.url);

for (const q in query) url.searchParams.append(q, String(query[q]));
return await this.api.fetch(url, {
method: 'DELETE'
});
}

/**
* List missions in currently active channels
*/
async list(query: {
passwordProtected?: string;
defaultRole?: string;
Expand All @@ -94,6 +165,9 @@ export default class {
});
}

/**
* Get mission by its GUID
*/
async getGuid(guid: string, query: {
password?: string;
changes?: string;
Expand All @@ -112,6 +186,9 @@ export default class {
});
}

/**
* Get mission by its Name
*/
async get(name: string, query: {
password?: string;
changes?: string;
Expand All @@ -130,6 +207,9 @@ export default class {
});
}

/**
* Create a new mission
*/
async create(name: string, query: {
group: Array<string> | string;
creatorUid: string;
Expand Down Expand Up @@ -158,6 +238,9 @@ export default class {
});
}

/**
* Delete a mission
*/
async delete(name: string, query: {
creatorUid?: string;
deepDelete?: string;
Expand Down
Loading

0 comments on commit 8a75a94

Please sign in to comment.