-
-
Notifications
You must be signed in to change notification settings - Fork 0
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
61 changed files
with
10,584 additions
and
6,903 deletions.
There are no files selected for viewing
3,433 changes: 3,433 additions & 0 deletions
3,433
apps/converter-frontend-e2e/src/fixtures/indexnoimg.jats copy.xml
Large diffs are not rendered by default.
Oops, something went wrong.
2,700 changes: 2,700 additions & 0 deletions
2,700
apps/converter-frontend-e2e/src/fixtures/indexwithimg.jats.xml
Large diffs are not rendered by default.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import { NextApiRequest, NextApiResponse } from 'next' | ||
import tar from 'tar-stream' | ||
import { WritableStreamBuffer } from 'stream-buffers' | ||
import { streamToBuffer } from '@jorgeferrero/stream-to-buffer' | ||
import { Writable } from 'stream' | ||
import axios from 'axios' | ||
import FormData from 'form-data' | ||
import { fsyncSync } from 'fs' | ||
import { writeFile } from 'fs/promises' | ||
|
||
export default async (req: NextApiRequest, res: NextApiResponse) => { | ||
req.statusCode = 200 | ||
const tex = req.body | ||
const tarStream = new WritableStreamBuffer() | ||
console.log('Received tex') | ||
|
||
const tararr: any[] = [] | ||
const writable = new Writable({ | ||
write: (chunk, encoding, next) => { | ||
console.log(chunk) | ||
tararr.push(chunk) | ||
next() | ||
}, | ||
}) | ||
const formdata = new FormData() | ||
const pack = tar.pack() | ||
console.log('Packing tarball') | ||
pack.entry({ name: 'article.tex' }, tex) | ||
pack.on('finish', function () {}) | ||
console.log('Laying pipe') | ||
|
||
pack.finalize() | ||
pack.pipe(writable) | ||
console.log('Converting tarball to buffer') | ||
let tarball | ||
writable.on('finish', async () => { | ||
tarball = Buffer.concat(tararr) | ||
|
||
formdata.append('files[]', tarball, 'tarball.tar.gz') | ||
console.log('Posting tarball...') | ||
|
||
axios | ||
.post( | ||
'https://texlive2020.latexonline.cc/data?command=lualatex&target=article.tex&force=true&download=sample.pdf', | ||
|
||
formdata, | ||
{ | ||
responseType: 'arraybuffer', | ||
headers: { | ||
...formdata.getHeaders(), | ||
Accept: 'application/pdf', | ||
}, | ||
} | ||
) | ||
.then(async (result) => { | ||
console.log('PDF Received!') | ||
console.log('Sending back result...') | ||
const data = Buffer.from(result.data) | ||
res.status(200) | ||
res.setHeader('Content-Type', 'application/pdf') | ||
res.send(data) | ||
}) | ||
.catch(async (e) => { | ||
console.log('Oopsie whoopsie, we made a fucky wucky!') | ||
console.error(e) | ||
res.status(400) | ||
res.send(e) | ||
}) | ||
}) | ||
} |
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
Binary file not shown.
Oops, something went wrong.