Skip to content

Commit

Permalink
이미지 export 기능 추가 #43
Browse files Browse the repository at this point in the history
  • Loading branch information
bekker committed Jan 27, 2019
1 parent 061c5ea commit 17eae6f
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 2 deletions.
29 changes: 27 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions resources/src/api/views/member.html
Original file line number Diff line number Diff line change
Expand Up @@ -103,4 +103,13 @@ <h5><a href="mailto:[email protected]" target="_blank">개발자 괴롭히
</div>

</body>

<script>
function printMessageAfterSecond(msg) {
setTimeout(function() {
console.log(msg);
}, 1000);
return "called";
}
</script>
</html>
12 changes: 12 additions & 0 deletions src/core/nightmare/NightmareService.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
import Nightmare = require('nightmare');
import AsyncLock = require('async-lock');
import log4js = require('log4js');
let logger = log4js.getLogger();

let nm = Nightmare({
show: false,
executionTimeout: 1000,
waitTimeout: 1000
});

nm.on('console', function(log, msg) {
logger.info("console msg: " + msg);
});

let nmLock = new AsyncLock({maxPending : 100, timeout: 5000});
const NM_LOCK_KEY = "NightmareServiceLock";

Expand All @@ -21,9 +27,15 @@ function execute<T>(f: (Nightmare) => Promise<T>): Promise<T> {

export function renderHtmlAsPng(html: string, width: number, height: number): Promise<Buffer> {
return execute(async function(nm) {
let printMessageAfterSecond: any;
nm.viewport(width, height);
nm.goto("data:text/html;charset=utf-8," + html);
await nm.wait(function(){ return true; }); // HTML 전체 로딩까지 대기
let result = await nm.evaluate(function(msg) {
return printMessageAfterSecond(msg);
}, "abcd");

logger.info("function result: " + result);
let buffer: Buffer = await nm.screenshot();
return buffer;
});
Expand Down

0 comments on commit 17eae6f

Please sign in to comment.