WIP
This commit is contained in:
parent
f340da7e02
commit
582b7743f7
4 changed files with 39 additions and 23 deletions
14
etherpad2latex.nimble
Normal file
14
etherpad2latex.nimble
Normal file
|
|
@ -0,0 +1,14 @@
|
||||||
|
# Package
|
||||||
|
|
||||||
|
version = "0.1.0"
|
||||||
|
author = "joachimschmidt557"
|
||||||
|
description = "Fetch and compile latex from etherpad"
|
||||||
|
license = "MIT"
|
||||||
|
srcDir = "src"
|
||||||
|
bin = @["etherpad2latex"]
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# Dependencies
|
||||||
|
|
||||||
|
requires "nim >= 0.20.0"
|
||||||
23
server.nim
23
server.nim
|
|
@ -1,23 +0,0 @@
|
||||||
import asynchttpserver, asyncdispatch
|
|
||||||
import osproc
|
|
||||||
|
|
||||||
proc requestHandler(req:Request) {.async.} =
|
|
||||||
if req.url.path == "/compile":
|
|
||||||
let (output, exitCode) = execCmdEx("make")
|
|
||||||
let headers = if exitCode == 0: newHttpHeaders([("Content-Type","application/pdf")])
|
|
||||||
else: newHttpHeaders([("Content-Type","text/plain")])
|
|
||||||
let content = if exitCode == 0: readFile("Abgabe.pdf")
|
|
||||||
else: output
|
|
||||||
await req.respond(Http200, content, headers)
|
|
||||||
elif req.url.path == "/backup":
|
|
||||||
let (output, exitCode) = execCmdEx("make backup")
|
|
||||||
let headers = newHttpHeaders([("Content-Type","text/plain")])
|
|
||||||
let content = if exitCode == 0: "Backup succeded"
|
|
||||||
else: output
|
|
||||||
await req.respond(Http200, content, headers)
|
|
||||||
else:
|
|
||||||
await req.respond(Http404, "Not a valid API call")
|
|
||||||
|
|
||||||
when isMainModule:
|
|
||||||
var server = newAsyncHttpServer()
|
|
||||||
waitFor server.serve(Port(8080), requestHandler)
|
|
||||||
1
src/.gitignore
vendored
Normal file
1
src/.gitignore
vendored
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
etherpad2latex
|
||||||
24
src/etherpad2latex.nim
Normal file
24
src/etherpad2latex.nim
Normal file
|
|
@ -0,0 +1,24 @@
|
||||||
|
import asynchttpserver, asyncdispatch
|
||||||
|
import osproc, strutils, parseopt
|
||||||
|
|
||||||
|
proc getContent(pad:string):string =
|
||||||
|
discard
|
||||||
|
|
||||||
|
proc requestHandler(req:Request) {.async.} =
|
||||||
|
if req.url.path.startsWith("/compile"):
|
||||||
|
let
|
||||||
|
padName = req.url.path
|
||||||
|
content = getContent(padName)
|
||||||
|
let (output, exitCode) = execCmdEx("make")
|
||||||
|
let headers = if exitCode == 0: newHttpHeaders([("Content-Type","application/pdf")])
|
||||||
|
else: newHttpHeaders([("Content-Type","text/plain")])
|
||||||
|
let pdf = if exitCode == 0: readFile("Abgabe.pdf")
|
||||||
|
else: output
|
||||||
|
await req.respond(Http200, pdf, headers)
|
||||||
|
else:
|
||||||
|
await req.respond(Http404, "Not a valid API call")
|
||||||
|
|
||||||
|
when isMainModule:
|
||||||
|
var
|
||||||
|
server = newAsyncHttpServer()
|
||||||
|
waitFor server.serve(Port(8080), requestHandler)
|
||||||
Loading…
Add table
Add a link
Reference in a new issue