-
-
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.
Merge pull request #347 from dfpc-coe/video-api
Video API & Skittle Course
- Loading branch information
Showing
15 changed files
with
635 additions
and
440 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Large diffs are not rendered by default.
Oops, something went wrong.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,72 @@ | ||
import { Static, Type } from '@sinclair/typebox'; | ||
import TAKAPI from '../tak-api.js'; | ||
|
||
export const Feed = Type.Object({ | ||
uuid: Type.String(), | ||
active: Type.Boolean(), | ||
alias: Type.String(), | ||
url: Type.String(), | ||
|
||
order: Type.Union([Type.Integer(), Type.Null()]), | ||
macAddress: Type.String(), | ||
roverPort: Type.String(), | ||
ignoreEmbeddedKLV: Type.String(), | ||
source: Type.Union([Type.String(), Type.Null()]), | ||
networkTimeout: Type.String(), | ||
bufferTime: Type.String(), | ||
rtspReliable: Type.String(), | ||
thumbnail: Type.Union([Type.String(), Type.Null()]), | ||
classification: Type.Union([Type.String(), Type.Null()]), | ||
latitude: Type.Union([Type.String(), Type.Null()]), | ||
longitude: Type.Union([Type.String(), Type.Null()]), | ||
fov: Type.Union([Type.String(), Type.Null()]), | ||
heading: Type.Union([Type.String(), Type.Null()]), | ||
range: Type.Union([Type.String(), Type.Null()]), | ||
width: Type.Union([Type.Integer(), Type.Null()]), | ||
height: Type.Union([Type.Integer(), Type.Null()]), | ||
bitrate: Type.Union([Type.Integer(), Type.Null()]), | ||
}); | ||
|
||
export const Video = Type.Object({ | ||
uuid: Type.String(), | ||
active: Type.Boolean(), | ||
alias: Type.String(), | ||
thumbnail: Type.Union([Type.String(), Type.Null()]), | ||
classification: Type.Union([Type.String(), Type.Null()]), | ||
feeds: Type.Array(Feed) | ||
}) | ||
|
||
export const VideoList = Type.Object({ | ||
videoConnections: Type.Array(Video) | ||
}); | ||
|
||
export const VideoListInput = Type.Object({ | ||
protocol: Type.Optional(Type.String()) | ||
}) | ||
|
||
export default class { | ||
api: TAKAPI; | ||
|
||
constructor(api: TAKAPI) { | ||
this.api = api; | ||
} | ||
|
||
async list( | ||
query: Static<typeof VideoListInput> = {} | ||
): Promise<Static<typeof VideoList>> { | ||
const url = new URL(`/Marti/api/video`, this.api.url); | ||
|
||
let q: keyof Static<typeof VideoListInput>; | ||
for (q in query) { | ||
if (query[q] !== undefined) { | ||
url.searchParams.append(q, String(query[q])); | ||
} | ||
} | ||
|
||
const res = await this.api.fetch(url, { | ||
method: 'GET' | ||
}); | ||
|
||
return await res.typed(VideoList); | ||
} | ||
} |
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
Large diffs are not rendered by default.
Oops, something went wrong.
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,37 @@ | ||
import { Type } from '@sinclair/typebox' | ||
import Schema from '@openaddresses/batch-schema'; | ||
import Err from '@openaddresses/batch-error'; | ||
import Auth from '../lib/auth.js'; | ||
import Config from '../lib/config.js'; | ||
import { | ||
VideoList, | ||
VideoListInput, | ||
} from '../lib/api/video.js'; | ||
import TAKAPI, { | ||
APIAuthCertificate, | ||
} from '../lib/tak-api.js'; | ||
|
||
export default async function router(schema: Schema, config: Config) { | ||
await schema.get('/marti/video', { | ||
name: 'List Video', | ||
group: 'MartiVideos', | ||
params: Type.Object({ | ||
name: Type.String(), | ||
}), | ||
description: 'Helper API to get list video streams', | ||
query: VideoListInput, | ||
res: VideoList | ||
}, async (req, res) => { | ||
try { | ||
const user = await Auth.as_user(config, req); | ||
const auth = (await config.models.Profile.from(user.email)).auth; | ||
const api = await TAKAPI.init(new URL(String(config.server.api)), new APIAuthCertificate(auth.cert, auth.key)); | ||
|
||
const list = await api.Video.list(req.query); | ||
|
||
return res.json(list); | ||
} catch (err) { | ||
return Err.respond(err, res); | ||
} | ||
}); | ||
} |
Oops, something went wrong.