fixed dockerfile and function name. it's working

This commit is contained in:
rafaelsideguide 2024-09-03 14:08:07 -03:00
parent ebf4035484
commit d60fa6e084
2 changed files with 9 additions and 6 deletions

View File

@ -17,11 +17,11 @@ RUN pnpm install
RUN --mount=type=secret,id=SENTRY_AUTH_TOKEN \
bash -c 'export SENTRY_AUTH_TOKEN="$(cat /run/secrets/SENTRY_AUTH_TOKEN)"; if [ -z $SENTRY_AUTH_TOKEN ]; then pnpm run build:nosentry; else pnpm run build; fi'
# Install Go 1.19
# Install Go
FROM golang:1.19 AS go-base
COPY src/lib/go-html-to-md /app/src/lib/go-html-to-md
# Install Go dependencies and build
# Install Go dependencies and build parser lib
RUN cd /app/src/lib/go-html-to-md && \
go mod tidy && \
go build -o html-to-markdown.so -buildmode=c-shared html-to-markdown.go && \
@ -33,9 +33,8 @@ RUN apt-get update -qq && \
rm -rf /var/lib/apt/lists /var/cache/apt/archives
COPY --from=prod-deps /app/node_modules /app/node_modules
COPY --from=build /app /app
COPY --from=go-base /app/src/lib/go-html-to-md/html-to-markdown.so /app/src/lib/go-html-to-md/html-to-markdown.so
COPY --from=go-base /app/src/lib/go-html-to-md/html-to-markdown.so /app/dist/src/lib/go-html-to-md/html-to-markdown.so
# Start the server by default, this can be overwritten at runtime
EXPOSE 8080
ENV PUPPETEER_EXECUTABLE_PATH="/usr/bin/chromium"
ENV PUPPETEER_EXECUTABLE_PATH="/usr/bin/chromium"

View File

@ -8,6 +8,10 @@ import dotenv from 'dotenv';
import { Logger } from './logger';
dotenv.config();
// TODO: test with invalid html
// TODO: create a singleton for the converter
// TODO: add a timeout to the Go parser
export async function parseMarkdown(html: string): Promise<string> {
if (!html) {
return '';
@ -18,7 +22,7 @@ export async function parseMarkdown(html: string): Promise<string> {
const goExecutablePath = join(__dirname, 'go-html-to-md/html-to-markdown.so');
const lib = koffi.load(goExecutablePath);
const convert = lib.func('Convert', 'string', ['string']);
const convert = lib.func('ConvertHTMLToMarkdown', 'string', ['string']);
let markdownContent = await new Promise<string>((resolve, reject) => {
convert.async(html, (err: Error, res: string) => {