Skip to content

Commit

Permalink
Updated handler & service
Browse files Browse the repository at this point in the history
  • Loading branch information
ainsleyclark committed May 6, 2022
1 parent 79ff69e commit bc3ded1
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 15 deletions.
29 changes: 18 additions & 11 deletions handler/snap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
* snap.ts
*/
import * as express from "express";
import {Options} from "../service/options";
import {Log} from "../util/logger";
import {Snappy} from "../service/snappy"
import {Options} from "../service/options";
import {getErrorMessage} from "../util/error";
import {Snappy} from "../service/snappy";

/**
* TODO
Expand All @@ -14,22 +14,29 @@ import {Snappy} from "../service/snappy";
* @returns {Promise<void>}
*/
export const snap = async (req: express.Request, res: express.Response) => {
// This is an object, we can loop.
const opts = <Options>{
url: req.query.url,
size: req.query.size,
ignoreCache: req.query.ignoreCache,
delay: req.query.delay,
crop: req.query.crop,
hide: req.query.hide,
script: req.query.script,
// TODO - More?
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,
};

// TODO
Snappy.snap({
url: opts.url,
sizes: ['1920x1080'],
crop: true,
}).then(data => {
console.log(opts);

res.json(opts).end();
return;

Snappy.snap(opts).then(data => {
const image = Buffer.from(data, 'base64');
res.writeHead(200, {
'Content-Type': 'image/png',
Expand Down
3 changes: 1 addition & 2 deletions service/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,4 @@ export class NullImageError extends Error {
super(message);
this.name = "NullImageError";
}
}

}
2 changes: 1 addition & 1 deletion service/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export interface Options {
/**
* TODO
*/
sizes: string[];
size: string;
/**
* TODO
*/
Expand Down
2 changes: 1 addition & 1 deletion service/snappy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ class Snapper {
// Process the image screenshot download.
try {
const screenshots = await new pageres({delay: 1})
.src(opts.url, opts.sizes, pageresOptions)
.src(opts.url, [opts.size], pageresOptions)
.dest(dir)
.run();
const data = this.processScreenshot(screenshots, dir, cacheKey);
Expand Down
6 changes: 6 additions & 0 deletions tests/handler/ping.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
describe('Ping Handler', () => {

it('Should render PONG', () => {

});
});

0 comments on commit bc3ded1

Please sign in to comment.