-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
modal-tex-render.sh
52 lines (40 loc) · 1.44 KB
/
modal-tex-render.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
TEMPDIR=$(mktemp -d)
TEXFILE=$TEMPDIR/file.tex
BOUNDARY="boundary"
putboundary(){
echo -e "\r\n--${BOUNDARY}$1"
}
echo "Content-Type: multipart/form-data; boundary=$BOUNDARY"
echo "Status: 200 OK"
echo
jq '.data.components[] | select(.components[0].custom_id=="latex").components[0].value' "$1" -r >> $TEMPDIR/src.tex
bash latex-render.sh "$TEMPDIR" "$(jq '.data.components[] | select(.components[0].custom_id=="texenv").components[0].values[0]' "$1" -r)"
if [ $? -eq 0 ]; then
# Success!
# Send through the JSON
putboundary
echo 'Content-Disposition: form-data; name="payload_json"'
echo "Content-Type: application/json"
echo
echo '{"type": 4, "data":{"embeds":[{"image":{"url":"attachment://tex.png"}}]}}'
putboundary
# Send through the image
echo 'Content-Disposition: form-data; name="files[0]"; filename="tex.png"'
echo "Content-Type: image/png"
echo
cat $TEMPDIR/file.png
else
putboundary
echo 'Content-Disposition: form-data; name="payload_json"'
echo "Content-Type: application/json"
echo
echo '{"type": 4, "data":{"embeds":[{"title":"Failed to Render"}], "attachments": [{"id":0, "description":"Error Logs", "filename":"error.log"}]}}'
# Send through the logs
putboundary
echo 'Content-Disposition: form-data; name="files[0]"; filename="error.log"'
echo "Content-Type: text/plain"
echo
cat $TEMPDIR/aggr.log
fi
putboundary "--"
rm -rf $TEMPDIR