Skip to content

Commit

Permalink
Options
Browse files Browse the repository at this point in the history
  • Loading branch information
ainsleyclark committed May 9, 2022
1 parent 4d27246 commit b8daf08
Show file tree
Hide file tree
Showing 7 changed files with 13,528 additions and 13,466 deletions.
4 changes: 2 additions & 2 deletions handler/ping.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ import * as express from "express";
* @returns {Promise<void>}
*/
export const ping = async (req: express.Request, res: express.Response) => {
res.status(200).send('PONG').end()
}
res.status(200).send('PONG').end();
};
38 changes: 13 additions & 25 deletions handler/snap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
*/
import * as express from "express";
import {Log} from "../util/logger";
import {Snappy} from "../service/snappy"
import {Snappy} from "../service/snappy";
import {Options} from "../service/options";
import {getErrorMessage} from "../util/error";
import {ValidationError} from "joi";

/**
* TODO
Expand All @@ -14,30 +15,17 @@ import {getErrorMessage} from "../util/error";
* @returns {Promise<void>}
*/
export const snap = async (req: express.Request, res: express.Response) => {
// let hide = [];
// if (req.query.hide) {
// const test = req.query.hi
// hide = req.query.hide.split(',');
// }


const opts = <Options>{
url: req.query.url,
size: req.query.size,
ignoreCache: req.query.ignoreCache,
delay: req.query.delay,
crop: req.query.crop,
script: req.query.script,
//cookies: req.query.cookies,
selector: req.query.selector,
hide: req.query.hide,
scale: req.query.scale,
userAgent: req.query.userAgent,
headers: req.query.headers,
transparent: req.query.transparent,
darkMode: req.query.darkMode,
};
const opts = new Options().fromRequest(req);

try {
opts.validate();
} catch (err) {
if (err instanceof ValidationError) {
Log.error(err.message);
res.json(err.details).end();
}
return;
}

Snappy.snap(opts).then(data => {
const image = Buffer.from(data, 'base64');
Expand All @@ -49,4 +37,4 @@ export const snap = async (req: express.Request, res: express.Response) => {
}).catch(err => {
Log.error(getErrorMessage(err));
});
}
};
Loading

0 comments on commit b8daf08

Please sign in to comment.