This repository has been archived by the owner on Jan 24, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
68 additions
and
1 deletion.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import Nightmare = require('nightmare'); | ||
import AsyncLock = require('async-lock'); | ||
|
||
let nm = Nightmare({ | ||
show: false, | ||
executionTimeout: 1000, | ||
waitTimeout: 1000 | ||
}); | ||
|
||
let nmLock = new AsyncLock({maxPending : 100, timeout: 5000}); | ||
const NM_LOCK_KEY = "NightmareServiceLock"; | ||
|
||
function execute<T>(f: (Nightmare) => Promise<T>): Promise<T> { | ||
return nmLock.acquire(NM_LOCK_KEY, function() { | ||
return f(nm); | ||
}); | ||
} | ||
|
||
export function renderHtmlAsPng(html: string, width: number, height: number): Promise<Buffer> { | ||
return execute(async function(nm) { | ||
nm.viewport(width, height); | ||
nm.goto("about:blank"); | ||
await nm.wait(function (html: string){ | ||
document.body.innerHTML = html; | ||
return true; | ||
}, html); | ||
let buffer: Buffer = await nm.screenshot(); | ||
return buffer; | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import log4js = require('log4js'); | ||
|
||
import NightmareService = require('@app/core/nightmare/NightmareService'); | ||
import Timetable from './model/Timetable'; | ||
|
||
let logger = log4js.getLogger(); | ||
|
||
export function renderTimetableAsPng(timetable: Timetable, width: number, height: number): Promise<Buffer> { | ||
let html = "<p>Timetable title: " + timetable.title + "</p>"; | ||
return NightmareService.renderHtmlAsPng(html, width, height); | ||
} |