-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #274 from esek/feat/latexifyservice
HTML tags to Latex service added for future efterphest feature
- Loading branch information
Showing
9 changed files
with
79 additions
and
2 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
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
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,15 @@ | ||
import { hasAuthenticated } from '@/util'; | ||
import { Resolvers } from '@generated/graphql'; | ||
import { latexify } from '@service/latexify'; | ||
|
||
const latexifyResolver: Resolvers = { | ||
Query: { | ||
latexify: async (_, { text }, ctx) => { | ||
await hasAuthenticated(ctx); | ||
const res = await latexify(text); | ||
return res; | ||
}, | ||
}, | ||
}; | ||
|
||
export default latexifyResolver; |
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,3 @@ | ||
type Query { | ||
latexify(text: String!): String! | ||
} |
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,30 @@ | ||
import config from '@/config'; | ||
import { ServerError } from '@/errors/request.errors'; | ||
import { QueryLatexifyArgs } from '@generated/graphql'; | ||
import axios, { AxiosResponse } from 'axios'; | ||
|
||
const { | ||
LATEXIFY: { URL }, | ||
} = config; | ||
|
||
const api = axios.create({ | ||
baseURL: URL, | ||
headers: { | ||
'Content-Type': 'application/json', | ||
}, | ||
}); | ||
|
||
export const latexify = async (text: string) => { | ||
try { | ||
const res = await api.post<QueryLatexifyArgs, AxiosResponse>('/latexify', { | ||
text: text, | ||
}); | ||
if (res.status == 200) { | ||
return res.data as string; | ||
} else { | ||
throw new ServerError(`${res.status}: ${res.statusText}`); | ||
} | ||
} catch { | ||
throw new ServerError('Texten kunde inte konverteras till LaTeX'); | ||
} | ||
}; |