Skip to content

Commit

Permalink
add ebook renderer (+adjust timeout, environment option) (#57)
Browse files Browse the repository at this point in the history
  • Loading branch information
Kruemmelspalter authored Jan 14, 2023
1 parent 8f27f58 commit 5a2616f
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 4 deletions.
1 change: 1 addition & 0 deletions backend/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ RUN apt-get update -y && apt-get install -y npm nodejs
RUN npm install -g n && n stable
RUN npm install -g @mermaid-js/mermaid-cli
COPY mmdc-puppeteer-config.json .
RUN apt-get update -y && apt-get install -y calibre

COPY app/build/distributions/app.tar FileSpider.tar
RUN tar -xf FileSpider.tar
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,19 @@ class Renderer {
Renderer().tempDir().command(10) { listOf("xournalpp", "-p", "out.pdf", it.fileName) }
.outputFile("application/pdf", "pdf") { "out.pdf" }

private val ebookRenderer = Renderer().tempDir()
.command(15, mapOf("QTWEBENGINE_CHROMIUM_FLAGS" to "--no-sandbox")) {
listOf("ebook-convert", it.fileName, "out.pdf")
}
.outputFile("application/pdf", "pdf") { "out.pdf" }

private val mimeSpecificRenderer = Renderer().useRenderer {
when (it.document.mimeType) {
"application/x-tex", "application/x-latex" -> latexRenderer
"text/markdown" -> markdownRenderer
"application/x-xopp" -> xournalppRenderer
"text/html" -> htmlRenderer
"application/zip+epub" -> ebookRenderer
else -> plainRenderer
}
}
Expand All @@ -87,6 +94,7 @@ class Renderer {
"tex", "latex" -> latexRenderer
"xournal", "xournalpp" -> xournalppRenderer
"html" -> htmlRenderer
"renderer" -> ebookRenderer
else -> mimeSpecificRenderer
}
}
Expand Down Expand Up @@ -125,13 +133,16 @@ class Renderer {

fun command(
timeout: Long,
environment: Map<String, String> = mapOf(),
timeUnit: TimeUnit = TimeUnit.SECONDS,
commandProvider: (RenderMeta) -> List<String>
): Renderer {
return addStep {
val process = ProcessBuilder(commandProvider(it)).redirectErrorStream(true)
val pb = ProcessBuilder(commandProvider(it)).redirectErrorStream(true)
.redirectOutput(it.fsService.getLogPathFromID(it.document.id).toFile())
.directory(it.workingDirectory.toFile()).start()
.directory(it.workingDirectory.toFile())
environment.toMap(pb.environment())
val process = pb.start()
if (!process.waitFor(timeout, timeUnit) || process.exitValue() != 0)
throw RenderingException(String(it.fsService.readLog(it.document.id)?.readAllBytes() ?: byteArrayOf()))
}
Expand Down Expand Up @@ -175,9 +186,13 @@ class Renderer {
filenameProvider
)
}

fun copy(srcProvider: (RenderMeta) -> String, dstProvider: (RenderMeta) -> String): Renderer {
return addStep {
Files.copy(Paths.get(it.workingDirectory.toString(), srcProvider(it)), Paths.get(it.workingDirectory.toString(), dstProvider(it)))
Files.copy(
Paths.get(it.workingDirectory.toString(), srcProvider(it)),
Paths.get(it.workingDirectory.toString(), dstProvider(it))
)
}
}

Expand Down
2 changes: 2 additions & 0 deletions frontend/components/DocumentCreationDialog.vue
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,8 @@ export default {
'fLD2M8105EclOejoneKwSFYio341tuWZWl+z1j/jkrxDi9aXhqsnj9N/QI/qnjL1QAAAA==', 'base64'),
},
},
{ text: 'ePub', value: { mime: 'application/zip+epub', fileExtension: 'epub', renderer: 'ebook' } },
{ text: 'eBook', value: { renderer: 'ebook' } },
],
}
},
Expand Down
2 changes: 1 addition & 1 deletion frontend/components/DocumentDisplay.vue
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ export default {
if (this.iframeState === 0) {
this.iframeState = 2
}
}, 5e3)
}, 20e3)
},
methods: {
copyIdToClipboard () {
Expand Down

0 comments on commit 5a2616f

Please sign in to comment.