2
0
mirror of https://github.com/ad1217/PrinterStatus synced 2024-11-21 15:03:48 -05:00

Transform relative webcam URL into absolute

This commit is contained in:
Adam Goldsmith 2020-02-19 18:38:30 -05:00
parent e2f5d9d0c0
commit ebc24fdfc2

View File

@ -48,7 +48,7 @@ app.get('/webcam/:printer', (req, res) => {
let printer: PrinterStatus | undefined = printerStatuses.find(
p => p.name === req.params.printer
);
if (printer && printer.webcamURL) {
if (printer?.webcamURL) {
req.url = ''; // truncate the url for passing to the proxy
proxy.web(req, res, { target: printer.webcamURL });
} else res.status(404).send('Not Found: Printer not known or has no webcam.');
@ -84,6 +84,9 @@ class PrinterStatus {
// TODO: error handling (try/catch)
const settings = await this.api_get('settings');
this.webcamURL = settings.webcam.streamUrl;
if (this.webcamURL?.startsWith('/')) {
this.webcamURL = this.address + this.webcamURL;
}
this.name = settings.appearance.name;
// do passive login to get a session key from the API key