-
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
173 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import TAKAPI from '../tak-api.js'; | ||
import xmljs from 'xml-js'; | ||
import { CoT } from '@tak-ps/node-tak'; | ||
import FormData from 'form-data'; | ||
import { Readable } from 'node:stream'; | ||
import mime from 'mime'; | ||
import { Type, Static } from '@sinclair/typebox'; | ||
import type { Feature } from '@tak-ps/node-cot'; | ||
|
||
export const HistoryOptions = Type.Object({ | ||
start: Type.Optional(Type.String()), | ||
end: Type.Optional(Type.String()), | ||
secago: Type.Optional(Type.String()), | ||
}) | ||
|
||
export default class COTQuery { | ||
api: TAKAPI; | ||
|
||
constructor(api: TAKAPI) { | ||
this.api = api; | ||
} | ||
|
||
async historyFeats(uid: string, opts?: Static<typeof HistoryOptions>): Promise<Static<typeof Feature.Feature>> { | ||
const feats: Static<typeof Feature.Feature>[] = []; | ||
|
||
const res: any = xmljs.xml2js(await this.history(uid, opts), { compact: true }); | ||
|
||
if (!Object.keys(res.events).length) return feats; | ||
if (!res.events.event || (Array.isArray(res.events.event) && !res.events.event.length)) return feats; | ||
|
||
for (const event of Array.isArray(res.events.event) ? res.events.event : [res.events.event] ) { | ||
feats.push((new CoT({ event })).to_geojson()); | ||
} | ||
|
||
return feats; | ||
} | ||
|
||
async history(uid: string, opts?: Static<typeof HistoryOptions>): Promise<string> { | ||
const url = new URL(`/Marti/api/cot/xml/${encodeURIComponent(uid)}/all`, this.api.url); | ||
|
||
let q: keyof Static<typeof HistoryOptions>; | ||
for (q in opts) { | ||
if (opts[q] !== undefined) { | ||
url.searchParams.append(q, String(opts[q])); | ||
} | ||
} | ||
|
||
const res = await this.api.fetch(url, { | ||
method: 'GET' | ||
}, true); | ||
|
||
const body = await res.text(); | ||
|
||
return body; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters