Formatting

This commit is contained in:
Kurt Hutten
2021-06-29 17:17:21 +10:00
parent 726945c2ab
commit 7417499d4b
11 changed files with 92 additions and 66 deletions

View File

@@ -10,19 +10,22 @@ app.use(cors())
const invocationURL = (port) => const invocationURL = (port) =>
`http://localhost:${port}/2015-03-31/functions/function/invocations` `http://localhost:${port}/2015-03-31/functions/function/invocations`
const makeRequest = (route, port) => [route, async (req, res) => { const makeRequest = (route, port) => [
console.log(`making post request to ${port}, ${route}`) route,
try { async (req, res) => {
const { data } = await axios.post(invocationURL(port), { console.log(`making post request to ${port}, ${route}`)
body: JSON.stringify(req.body), try {
}) const { data } = await axios.post(invocationURL(port), {
res.status(data.statusCode) body: JSON.stringify(req.body),
res.send(data.body) })
} catch (e) { res.status(data.statusCode)
res.status(500) res.send(data.body)
res.send() } catch (e) {
} res.status(500)
}] res.send()
}
},
]
app.post(...makeRequest('/openscad/preview', 5052)) app.post(...makeRequest('/openscad/preview', 5052))
app.post(...makeRequest('/openscad/stl', 5053)) app.post(...makeRequest('/openscad/stl', 5053))

View File

@@ -1,9 +1,10 @@
const { makeFile, runCommand } = require('../common/utils') const { makeFile, runCommand } = require('../common/utils')
const { nanoid } = require('nanoid') const { nanoid } = require('nanoid')
module.exports.runCQ = async ({ file, settings: { module.exports.runCQ = async ({
deflection = 0.3 file,
} = {} } = {}) => { settings: { deflection = 0.3 } = {},
} = {}) => {
const tempFile = await makeFile(file, '.py', nanoid) const tempFile = await makeFile(file, '.py', nanoid)
const fullPath = `/tmp/${tempFile}/output.stl` const fullPath = `/tmp/${tempFile}/output.stl`
const command = `cq-cli/cq-cli --codec stl --infile /tmp/${tempFile}/main.py --outfile ${fullPath} --outputopts "deflection:${deflection};angularDeflection:${deflection};"` const command = `cq-cli/cq-cli --codec stl --infile /tmp/${tempFile}/main.py --outfile ${fullPath} --outputopts "deflection:${deflection};angularDeflection:${deflection};"`

View File

@@ -3,7 +3,7 @@ import { db } from 'src/lib/db'
import { sentryWrapper } from 'src/lib/sentry' import { sentryWrapper } from 'src/lib/sentry'
import { enforceAlphaNumeric, generateUniqueString } from 'src/services/helpers' import { enforceAlphaNumeric, generateUniqueString } from 'src/services/helpers'
import 'graphql-tag' import 'graphql-tag'
import {sendMail} from 'src/lib/sendmail' import { sendMail } from 'src/lib/sendmail'
const unWrappedHandler = async (req, _context) => { const unWrappedHandler = async (req, _context) => {
const body = JSON.parse(req.body) const body = JSON.parse(req.body)
@@ -57,7 +57,7 @@ const unWrappedHandler = async (req, _context) => {
const user = body.user const user = body.user
const email = user.email const email = user.email
let roles = [] const roles = []
if (eventType === 'signup') { if (eventType === 'signup') {
roles.push('user') roles.push('user')
@@ -77,7 +77,7 @@ const unWrappedHandler = async (req, _context) => {
await sendMail({ await sendMail({
to: 'k.hutten@protonmail.ch', to: 'k.hutten@protonmail.ch',
from: { from: {
address:'news@mail.cadhub.xyz', address: 'news@mail.cadhub.xyz',
name: 'CadHub', name: 'CadHub',
}, },
subject: `New Cadhub User`, subject: `New Cadhub User`,

View File

@@ -121,7 +121,7 @@ export const getCurrentUser = async (decoded, { _token, _type }) => {
* requireAuth({ role: ['editor', 'author'] }) * requireAuth({ role: ['editor', 'author'] })
* requireAuth({ role: ['publisher'] }) * requireAuth({ role: ['publisher'] })
*/ */
export const requireAuth = ({ role }: {role?: string | string[]} = {}) => { export const requireAuth = ({ role }: { role?: string | string[] } = {}) => {
console.log(context.currentUser) console.log(context.currentUser)
if (!context.currentUser) { if (!context.currentUser) {
throw new AuthenticationError("You don't have permission to do that.") throw new AuthenticationError("You don't have permission to do that.")

View File

@@ -1,4 +1,4 @@
import nodemailer, {SendMailOptions} from 'nodemailer' import nodemailer, { SendMailOptions } from 'nodemailer'
interface Args { interface Args {
to: SendMailOptions['to'] to: SendMailOptions['to']
@@ -15,42 +15,49 @@ interface SuccessResult {
messageSize: number messageSize: number
response: string response: string
envelope: { envelope: {
from: string | false, from: string | false
to: string[] to: string[]
}, }
messageId: string messageId: string
} }
export function sendMail({to, from, subject, text}: Args): Promise<SuccessResult> { export function sendMail({
let transporter = nodemailer.createTransport({ to,
from,
subject,
text,
}: Args): Promise<SuccessResult> {
const transporter = nodemailer.createTransport({
host: 'smtp.mailgun.org', host: 'smtp.mailgun.org',
port: 587, port: 587,
secure: false, secure: false,
tls: { tls: {
ciphers:'SSLv3' ciphers: 'SSLv3',
}, },
auth: { auth: {
user: 'postmaster@mail.cadhub.xyz', user: 'postmaster@mail.cadhub.xyz',
pass: process.env.EMAIL_PASSWORD pass: process.env.EMAIL_PASSWORD,
} },
}); })
console.log({to, from, subject, text}); console.log({ to, from, subject, text })
const emailPromise = new Promise((resolve, reject) => { const emailPromise = new Promise((resolve, reject) => {
transporter.sendMail({ transporter.sendMail(
from, {
to, from,
subject, to,
text, subject,
}, (error, info) => { text,
if (error) { },
reject(error); (error, info) => {
} else { if (error) {
resolve(info); reject(error)
} else {
resolve(info)
}
} }
}); )
}) as any as Promise<SuccessResult> }) as any as Promise<SuccessResult>
return emailPromise return emailPromise
} }

View File

@@ -1,12 +1,12 @@
import { requireAuth } from 'src/lib/auth' import { requireAuth } from 'src/lib/auth'
import {sendMail} from 'src/lib/sendmail' import { sendMail } from 'src/lib/sendmail'
import {users} from 'src/services/users/users' import { users } from 'src/services/users/users'
export const sendAllUsersEmail = async ({input: {body, subject}}) => { export const sendAllUsersEmail = async ({ input: { body, subject } }) => {
requireAuth({ role: 'admin' }) requireAuth({ role: 'admin' })
const recipients = (await users()).map(({email}) => email) const recipients = (await users()).map(({ email }) => email)
const from = { const from = {
address:'news@mail.cadhub.xyz', address: 'news@mail.cadhub.xyz',
name: 'CadHub', name: 'CadHub',
} }
const result = await sendMail({ const result = await sendMail({

View File

@@ -14,10 +14,7 @@ const Footer = () => {
> >
Road Map Road Map
</OutBound> </OutBound>
<OutBound <OutBound className="mr-8" to="https://learn.cadhub.xyz/blog">
className="mr-8"
to="https://learn.cadhub.xyz/blog"
>
Blog Blog
</OutBound> </OutBound>
<Link className="mr-8" to={routes.codeOfConduct()}> <Link className="mr-8" to={routes.codeOfConduct()}>

View File

@@ -13,7 +13,7 @@ import { requestRender } from 'src/helpers/hooks/useIdeState'
import texture from './dullFrontLitMetal.png' import texture from './dullFrontLitMetal.png'
import { TextureLoader } from 'three/src/loaders/TextureLoader' import { TextureLoader } from 'three/src/loaders/TextureLoader'
const loader = new TextureLoader const loader = new TextureLoader()
const colorMap = loader.load(texture) const colorMap = loader.load(texture)
extend({ OrbitControls }) extend({ OrbitControls })
@@ -200,8 +200,8 @@ const IdeViewer = ({ Loading }) => {
/> />
<ambientLight intensity={1} /> <ambientLight intensity={1} />
<pointLight position={[15, 5, 10]} intensity={4} /> <pointLight position={[15, 5, 10]} intensity={4} />
<pointLight position={[-1000, -1000, -1000]} intensity={1}/> <pointLight position={[-1000, -1000, -1000]} intensity={1} />
<pointLight position={[-1000, 0, 1000]} intensity={1}/> <pointLight position={[-1000, 0, 1000]} intensity={1} />
{state.objectData?.type === 'png' && ( {state.objectData?.type === 'png' && (
<> <>
<Sphere position={[0, 0, 0]} color={pink400} /> <Sphere position={[0, 0, 0]} color={pink400} />

View File

@@ -9,7 +9,7 @@ import {
export const render = async ({ code }) => { export const render = async ({ code }) => {
const body = JSON.stringify({ const body = JSON.stringify({
settings: { settings: {
deflection: 0.2 deflection: 0.2,
}, },
file: code, file: code,
}) })

View File

@@ -1,37 +1,55 @@
import {useState} from 'react' import { useState } from 'react'
import { useMutation } from '@redwoodjs/web' import { useMutation } from '@redwoodjs/web'
import { toast, Toaster } from '@redwoodjs/web/toast' import { toast, Toaster } from '@redwoodjs/web/toast'
const SEND_EMAIL_MUTATION = gql` const SEND_EMAIL_MUTATION = gql`
mutation sendEmailMutation($email: Email!) { mutation sendEmailMutation($email: Email!) {
sendAllUsersEmail(input: $email) { sendAllUsersEmail(input: $email) {
accepted accepted
}
} }
}
` `
const AdminEmailPage = () => { const AdminEmailPage = () => {
const [subject, setSubject] = useState('') const [subject, setSubject] = useState('')
const [body, setBody] = useState('') const [body, setBody] = useState('')
const [sendEmailMutation] = useMutation(SEND_EMAIL_MUTATION, { const [sendEmailMutation] = useMutation(SEND_EMAIL_MUTATION, {
onCompleted: ({sendAllUsersEmail}) => { onCompleted: ({ sendAllUsersEmail }) => {
toast.success(`Emails sent, ${sendAllUsersEmail?.accepted.join(', ')}`) toast.success(`Emails sent, ${sendAllUsersEmail?.accepted.join(', ')}`)
setSubject('') setSubject('')
setBody('') setBody('')
}, },
}) })
const sendEmail = () => sendEmailMutation({ variables: { email: { subject, body } } }) const sendEmail = () =>
sendEmailMutation({ variables: { email: { subject, body } } })
return ( return (
<div className="flex justify-center"> <div className="flex justify-center">
<div className="max-w-7xl pt-8"> <div className="max-w-7xl pt-8">
<h2 className="" style={{width: '46rem'}}>Email all users</h2> <h2 className="" style={{ width: '46rem' }}>
Email all users
</h2>
<label htmlFor="subject">Subject</label> <label htmlFor="subject">Subject</label>
<input name="subject" className="rounded border border-gray-400 px-2 w-full" value={subject} onChange={({target}) => setSubject(target.value)}/> <input
name="subject"
className="rounded border border-gray-400 px-2 w-full"
value={subject}
onChange={({ target }) => setSubject(target.value)}
/>
<label htmlFor="body">Body</label> <label htmlFor="body">Body</label>
<textarea className="w-full rounded border border-gray-400 p-2" name="text" value={body} onChange={({target}) => setBody(target.value)}></textarea> <textarea
<button className="rounded px-2 p-1 mt-4 bg-ch-purple-400 text-indigo-200" onClick={sendEmail}>Send</button> className="w-full rounded border border-gray-400 p-2"
name="text"
value={body}
onChange={({ target }) => setBody(target.value)}
></textarea>
<button
className="rounded px-2 p-1 mt-4 bg-ch-purple-400 text-indigo-200"
onClick={sendEmail}
>
Send
</button>
</div> </div>
<Toaster timeout={1500} /> <Toaster timeout={1500} />
</div> </div>

View File

@@ -1,6 +1,6 @@
import { useState, useEffect } from 'react' import { useState, useEffect } from 'react'
import SubjectAccessRequestsCell from 'src/components/SubjectAccessRequestsCell' import SubjectAccessRequestsCell from 'src/components/SubjectAccessRequestsCell'
import { Flash, useQuery, useMutation, useFlash } from '@redwoodjs/web' import { useQuery, useMutation } from '@redwoodjs/web'
import { Form, Submit } from '@redwoodjs/forms' import { Form, Submit } from '@redwoodjs/forms'
import MainLayout from 'src/layouts/MainLayout' import MainLayout from 'src/layouts/MainLayout'