Skip to content

Commit bc60c24

Browse files
Merge pull request #112 from observerly/feature/client/exposure/store
feat: add client.exposure.store() router handler.
2 parents aa25053 + cfcc021 commit bc60c24

File tree

3 files changed

+131
-0
lines changed

3 files changed

+131
-0
lines changed

src/routes/exposure.ts

+52
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,28 @@ import { dispatchRequest } from '../internals/dispatchRequest'
1010

1111
/*****************************************************************************************************************/
1212

13+
export type ExposureStorePayload = {
14+
bucketName: string
15+
userId: string
16+
uuid: string
17+
duration: number
18+
start: string
19+
filter: string
20+
isDark: boolean
21+
isFlat: boolean
22+
mimetype: string
23+
target: string
24+
mjd: number
25+
equinox: number
26+
ra: number
27+
dec: number
28+
telescope: string
29+
instrument: string
30+
observer: string
31+
}
32+
33+
/*****************************************************************************************************************/
34+
1335
export const exposure = (
1436
base: URL,
1537
init?: RequestInit,
@@ -63,6 +85,36 @@ export const exposure = (
6385

6486
return dispatchRequest<T>(url, { ...init, method: 'DELETE' }, headers)
6587
}
88+
},
89+
{
90+
name: 'store',
91+
action: <
92+
T = {
93+
ccdXSize: number
94+
ccdYSize: number
95+
isDark: boolean
96+
isFlat: boolean
97+
locations: string[]
98+
maxADU: number
99+
mimetype: string
100+
sensor: string
101+
userId: string
102+
uuid: string
103+
}
104+
>(
105+
body: ExposureStorePayload
106+
) => {
107+
const url = new URL('exposure/store', base)
108+
109+
const data = JSON.stringify(body)
110+
111+
return dispatchRequest<T>(
112+
url,
113+
{ ...init, method: 'POST', body: JSON.stringify(body) },
114+
headers,
115+
data
116+
)
117+
}
66118
}
67119
] as const
68120

tests/exposure.spec.ts

+39
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,45 @@ suite('@observerly/hyper NOX API Observing Exposure Client', () => {
5555
if (!isDataResult(status)) return
5656
expect(status).toStrictEqual({})
5757
})
58+
59+
it('should be able to store an exposure from the camera', async () => {
60+
const client = setupClient(getURL('/api/v1/'))
61+
const store = await client.camera.storeExposure({
62+
bucketName: 'test.ex.observerly.com',
63+
duration: 130,
64+
start: '2021-05-15T03:00:00.000Z',
65+
filter: 'Hα',
66+
isDark: false,
67+
isFlat: false,
68+
mimetype: 'application/fits',
69+
target: 'M42',
70+
userId: 'sK0EFowNCXQ0JOK4UES2AjSnrVc2',
71+
uuid: '01H3WK0383PNKTT0240B53JX5N',
72+
mjd: 59379.0,
73+
equinox: 2021.5,
74+
ra: 83.82208,
75+
dec: -5.39111,
76+
telescope: 'Namibiascope 1',
77+
instrument: '20" AG Optical iDK Planewave L-500s',
78+
observer: 'Michael Roberts'
79+
})
80+
expect(isDataResult(store)).toBe(true)
81+
if (!isDataResult(store)) return
82+
expect(store).toStrictEqual({
83+
ccdXSize: 1463,
84+
ccdYSize: 1168,
85+
isDark: false,
86+
isFlat: false,
87+
locations: [
88+
'gs://test.ex.observerly.com/sK0EFowNCXQ0JOK4UES2AjSnrVc2/01H3WK0383PNKTT0240B53JX5N/M42_[Hα]_monochrome_M_130s_2021-05-15T03:00:00.000Z.fits'
89+
],
90+
maxADU: 65535,
91+
mimetype: 'application/fits',
92+
sensor: 'Monochrome',
93+
userId: 'sK0EFowNCXQ0JOK4UES2AjSnrVc2',
94+
uuid: '01H3WK0383PNKTT0240B53JX5N'
95+
})
96+
})
5897
})
5998
})
6099

tests/mocks/exposure.ts

+40
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ import { eventHandler, getMethod, readBody } from 'h3'
1010

1111
import { type Handler } from '../shared/handler'
1212

13+
import { type ExposureStorePayload } from '../../src/routes/exposure'
14+
1315
/*****************************************************************************************************************/
1416

1517
export const exposureHandlers: Handler[] = [
@@ -74,6 +76,44 @@ export const exposureHandlers: Handler[] = [
7476

7577
return {}
7678
})
79+
},
80+
{
81+
method: ['POST'],
82+
url: '/api/v1/exposure/store',
83+
handler: eventHandler(async event => {
84+
const method = getMethod(event)
85+
86+
if (method !== 'POST') {
87+
return new Response('Method Not Allowed', {
88+
status: 405,
89+
statusText: 'Method Not Allowed'
90+
})
91+
}
92+
93+
const body = await readBody<ExposureStorePayload>(event)
94+
95+
if (!body) {
96+
return new Response('Bad Request', {
97+
status: 400,
98+
statusText: 'Bad Request'
99+
})
100+
}
101+
102+
return {
103+
ccdXSize: 1463,
104+
ccdYSize: 1168,
105+
isDark: body.isDark,
106+
isFlat: body.isFlat,
107+
locations: [
108+
`gs://${body.bucketName}/${body.userId}/${body.uuid}/${body.target}_[${body.filter}]_monochrome_M_${body.duration}s_2021-05-15T03:00:00.000Z.fits`
109+
],
110+
maxADU: 65535,
111+
mimetype: body.mimetype,
112+
sensor: 'Monochrome',
113+
userId: body.userId,
114+
uuid: body.uuid
115+
}
116+
})
77117
}
78118
]
79119

0 commit comments

Comments
 (0)