Initial commit
This commit is contained in:
38
ts/main.ts
Normal file
38
ts/main.ts
Normal file
@@ -0,0 +1,38 @@
|
||||
import { BambuddyAddress } from './constants';
|
||||
import { login } from './login';
|
||||
import { getPrinterDetails } from './printer';
|
||||
import { getStreamToken } from './streamToken';
|
||||
import * as express from 'express';
|
||||
import { Request, Response } from 'express';
|
||||
|
||||
async function getToken() {
|
||||
const loginResponse = await login('screen', 'e8$o$u@F8XtHt#');
|
||||
|
||||
console.log('Login response:', loginResponse);
|
||||
|
||||
const streamToken = await getStreamToken(
|
||||
loginResponse?.access_token as string,
|
||||
);
|
||||
|
||||
return streamToken?.token;
|
||||
}
|
||||
|
||||
const app = express();
|
||||
|
||||
app.get('/', async (req: Request, res: Response) => {
|
||||
res.send(
|
||||
'Bambuddy Camera Bridge is running. Use /:printerId to access the camera stream.',
|
||||
);
|
||||
});
|
||||
|
||||
app.get('/:printerId', async (req: Request, res: Response) => {
|
||||
const token = await getToken();
|
||||
|
||||
res.redirect(
|
||||
`${BambuddyAddress}/api/v1/printers/${req.params.printerId}/camera/stream?fps=15&t=${Date.now()}&token=${token}`,
|
||||
);
|
||||
});
|
||||
|
||||
app.listen(3838, () => {
|
||||
console.log('Server is running on port 3838');
|
||||
});
|
||||
Reference in New Issue
Block a user