-
Notifications
You must be signed in to change notification settings - Fork 78
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
18 changed files
with
840 additions
and
247 deletions.
There are no files selected for viewing
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
13 changes: 8 additions & 5 deletions
13
api/apps/haxcms/site/html.js → api/apps/haxcms/siteToHtml.js
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
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,72 @@ | ||
import { stdResponse } from "../../../utilities/requestHelpers.js"; | ||
import { getBrowserInstance } from '../../../utilities/getBrowserInstance.js'; | ||
|
||
import df from 'mammoth'; | ||
const { convertToHtml } = df; | ||
import busboy from 'busboy'; | ||
import concat from "concat-stream"; | ||
|
||
export default async function handler(req, res) { | ||
var html = ''; | ||
var img = ''; | ||
var buffer = { | ||
filename: null, | ||
data: null, | ||
}; | ||
const bb = busboy({ headers: req.headers }); | ||
bb.on('file', async (name, file, info) => { | ||
const { filename, encoding, mimeType } = info; | ||
if(filename.length > 0 && mimeType == "application/vnd.openxmlformats-officedocument.wordprocessingml.document") { | ||
file.pipe(concat((fileBuffer) => { | ||
buffer.filename = filename; | ||
buffer.data = fileBuffer; | ||
})); | ||
} | ||
}); | ||
// file closed / finished | ||
bb.on('close', async () => { | ||
if (buffer.data) { | ||
try { | ||
html = await convertToHtml({buffer: buffer.data}) | ||
.then((result) => { | ||
return result.value; // The generated HTML | ||
}); | ||
// generate a screenshot of the HTML blob | ||
// capture options | ||
var screenshotOptions = { | ||
quality: 75, | ||
type: 'jpeg', | ||
encoding: "base64" | ||
}; | ||
let browser = null | ||
try { | ||
browser = await getBrowserInstance(); | ||
let page = await browser.newPage(); | ||
await page.setContent(html) | ||
img = await page.screenshot(screenshotOptions) | ||
} catch (error) { | ||
console.log(error) | ||
} finally { | ||
if (browser !== null) { | ||
await browser.close() | ||
} | ||
} | ||
} | ||
catch(e) { | ||
// put in the output | ||
html = e; | ||
} | ||
} | ||
res = stdResponse(res, | ||
{ | ||
contents: html, | ||
filename: buffer.filename, | ||
image: img | ||
}, | ||
{ | ||
methods: "GET,OPTIONS,PATCH,DELETE,POST,PUT" | ||
} | ||
); | ||
}); | ||
req.pipe(bb); | ||
} |
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,76 @@ | ||
import { stdResponse } from "../../../utilities/requestHelpers.js"; | ||
import df from 'mammoth'; | ||
const { convertToHtml } = df; | ||
import busboy from 'busboy'; | ||
import concat from "concat-stream"; | ||
import {create as toPDF } from 'html-pdf'; | ||
|
||
const generatePDF = (html) => { | ||
return new Promise ( | ||
(resolve, reject) => { | ||
toPDF(html, { | ||
format: 'A4', | ||
orientation: 'portrait', | ||
margin: { | ||
top: "10mm", | ||
right: "10mm", | ||
bottom: "10mm", | ||
left: "10mm", | ||
}, | ||
timeout: 30000, | ||
}).toBuffer((error, buffer) => { | ||
if(error) { | ||
reject(error) | ||
} | ||
else { | ||
resolve(buffer.toString('base64')) | ||
} | ||
}); | ||
} | ||
) | ||
} | ||
|
||
export default async function handler(req, res) { | ||
var string64 = ''; | ||
var buffer = { | ||
filename: null, | ||
data: null, | ||
}; | ||
|
||
const bb = busboy({ headers: req.headers }); | ||
bb.on('file', async (name, file, info) => { | ||
const { filename, encoding, mimeType } = info; | ||
if(filename.length > 0 && mimeType == "application/vnd.openxmlformats-officedocument.wordprocessingml.document") { | ||
file.pipe(concat((fileBuffer) => { | ||
buffer.filename = filename; | ||
buffer.data = fileBuffer; | ||
})); | ||
} | ||
}); | ||
// file closed / finished | ||
bb.on('close', async () => { | ||
if (buffer.data) { | ||
try { | ||
string64 = await convertToHtml({buffer: buffer.data}) | ||
.then(async (result) => { | ||
let html = `<html><body>${result.value}</body></html>`; | ||
return await generatePDF(html); | ||
}); | ||
} | ||
catch(e) { | ||
// put in the output | ||
string64 = e; | ||
} | ||
} | ||
|
||
res = stdResponse(res, { | ||
filename: buffer.filename, | ||
pdf: string64 | ||
}, | ||
{ | ||
methods: "GET,OPTIONS,PATCH,DELETE,POST,PUT" | ||
} | ||
); | ||
}); | ||
req.pipe(bb); | ||
} |
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,60 @@ | ||
import { stdResponse } from "../../../utilities/requestHelpers.js"; | ||
|
||
import asciify from 'asciify-image'; | ||
import busboy from 'busboy'; | ||
import concat from "concat-stream"; | ||
|
||
export default async function handler(req, res) { | ||
var img = ''; | ||
var buffer = { | ||
filename: null, | ||
data: null, | ||
}; | ||
const bb = busboy({ headers: req.headers }); | ||
bb.on('file', async (name, file, info) => { | ||
const { filename, encoding, mimeType } = info; | ||
// ensure we have a filename | ||
if(filename.length > 0 && mimeType.startsWith("image/") === true) { | ||
file.pipe(concat((fileBuffer) => { | ||
buffer.filename = filename; | ||
buffer.data = fileBuffer; | ||
})); | ||
} | ||
}); | ||
// file closed / finished | ||
bb.on('close', async () => { | ||
if (buffer.data) { | ||
try { | ||
var options = { | ||
fit: 'box', | ||
width: 50, | ||
height: 25 | ||
} | ||
img = await asciify(buffer.data, options) | ||
.then(function (asciified) { | ||
// Print asciified image to console | ||
console.log(asciified); | ||
return asciified; | ||
}) | ||
.catch(function (err) { | ||
// Print error to console | ||
console.error(err); | ||
}); | ||
} | ||
catch(e) { | ||
// put in the output | ||
img = e; | ||
} | ||
} | ||
res = stdResponse(res, | ||
{ | ||
filename: buffer.filename, | ||
image: img | ||
}, | ||
{ | ||
methods: "GET,OPTIONS,PATCH,DELETE,POST,PUT" | ||
} | ||
); | ||
}); | ||
req.pipe(bb); | ||
} |
File renamed without changes.
Oops, something went wrong.
fe2d1b4
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
lrnwebcomponents – ./
lrnwebcomponents-elmsln.vercel.app
lrnwebcomponents.vercel.app
lrnwebcomponents-git-master-elmsln.vercel.app