Add JWT token to the request

This commit is contained in:
Hongbo Wu 2023-02-09 18:05:04 +08:00
parent a91cf9ef63
commit 761f2ff8f2
2 changed files with 14 additions and 1 deletions

View file

@ -464,7 +464,10 @@ export const getArticleResolver: ResolverFn<
if (!page.originalHtml) {
return { errorCodes: [ArticleErrorCode.BadData] }
}
const distillerResult = await getDistillerResult(page.originalHtml)
const distillerResult = await getDistillerResult(
claims.uid,
page.originalHtml
)
if (!distillerResult) {
return { errorCodes: [ArticleErrorCode.BadData] }
}

View file

@ -21,8 +21,11 @@ import {
findEmbeddedHighlight,
} from './highlightGenerator'
import { NodeHtmlMarkdown } from 'node-html-markdown'
import { promisify } from 'util'
import * as jwt from 'jsonwebtoken'
const logger = buildLogger('utils.parse')
const signToken = promisify(jwt.sign)
export const ALLOWED_CONTENT_TYPES = [
'text/html',
@ -487,6 +490,7 @@ export const htmlToMarkdown = (html: string) => {
}
export const getDistillerResult = async (
uid: string,
html: string
): Promise<string | undefined> => {
try {
@ -496,7 +500,13 @@ export const getDistillerResult = async (
return undefined
}
const token = await signToken({ uid }, '1h')
console.debug('Parsing by distiller', url)
const response = await axios.post<string>(url, html, {
headers: {
Authorization: token as string,
},
timeout: 5000,
})
return response.data