Formatting
This commit is contained in:
@@ -10,19 +10,22 @@ app.use(cors())
|
||||
const invocationURL = (port) =>
|
||||
`http://localhost:${port}/2015-03-31/functions/function/invocations`
|
||||
|
||||
const makeRequest = (route, port) => [route, async (req, res) => {
|
||||
console.log(`making post request to ${port}, ${route}`)
|
||||
try {
|
||||
const { data } = await axios.post(invocationURL(port), {
|
||||
body: JSON.stringify(req.body),
|
||||
})
|
||||
res.status(data.statusCode)
|
||||
res.send(data.body)
|
||||
} catch (e) {
|
||||
res.status(500)
|
||||
res.send()
|
||||
}
|
||||
}]
|
||||
const makeRequest = (route, port) => [
|
||||
route,
|
||||
async (req, res) => {
|
||||
console.log(`making post request to ${port}, ${route}`)
|
||||
try {
|
||||
const { data } = await axios.post(invocationURL(port), {
|
||||
body: JSON.stringify(req.body),
|
||||
})
|
||||
res.status(data.statusCode)
|
||||
res.send(data.body)
|
||||
} catch (e) {
|
||||
res.status(500)
|
||||
res.send()
|
||||
}
|
||||
},
|
||||
]
|
||||
|
||||
app.post(...makeRequest('/openscad/preview', 5052))
|
||||
app.post(...makeRequest('/openscad/stl', 5053))
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
const { makeFile, runCommand } = require('../common/utils')
|
||||
const { nanoid } = require('nanoid')
|
||||
|
||||
module.exports.runCQ = async ({ file, settings: {
|
||||
deflection = 0.3
|
||||
} = {} } = {}) => {
|
||||
module.exports.runCQ = async ({
|
||||
file,
|
||||
settings: { deflection = 0.3 } = {},
|
||||
} = {}) => {
|
||||
const tempFile = await makeFile(file, '.py', nanoid)
|
||||
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};"`
|
||||
|
||||
@@ -3,7 +3,7 @@ import { db } from 'src/lib/db'
|
||||
import { sentryWrapper } from 'src/lib/sentry'
|
||||
import { enforceAlphaNumeric, generateUniqueString } from 'src/services/helpers'
|
||||
import 'graphql-tag'
|
||||
import {sendMail} from 'src/lib/sendmail'
|
||||
import { sendMail } from 'src/lib/sendmail'
|
||||
|
||||
const unWrappedHandler = async (req, _context) => {
|
||||
const body = JSON.parse(req.body)
|
||||
@@ -57,7 +57,7 @@ const unWrappedHandler = async (req, _context) => {
|
||||
const user = body.user
|
||||
const email = user.email
|
||||
|
||||
let roles = []
|
||||
const roles = []
|
||||
|
||||
if (eventType === 'signup') {
|
||||
roles.push('user')
|
||||
@@ -77,7 +77,7 @@ const unWrappedHandler = async (req, _context) => {
|
||||
await sendMail({
|
||||
to: 'k.hutten@protonmail.ch',
|
||||
from: {
|
||||
address:'news@mail.cadhub.xyz',
|
||||
address: 'news@mail.cadhub.xyz',
|
||||
name: 'CadHub',
|
||||
},
|
||||
subject: `New Cadhub User`,
|
||||
|
||||
@@ -121,7 +121,7 @@ export const getCurrentUser = async (decoded, { _token, _type }) => {
|
||||
* requireAuth({ role: ['editor', 'author'] })
|
||||
* requireAuth({ role: ['publisher'] })
|
||||
*/
|
||||
export const requireAuth = ({ role }: {role?: string | string[]} = {}) => {
|
||||
export const requireAuth = ({ role }: { role?: string | string[] } = {}) => {
|
||||
console.log(context.currentUser)
|
||||
if (!context.currentUser) {
|
||||
throw new AuthenticationError("You don't have permission to do that.")
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import nodemailer, {SendMailOptions} from 'nodemailer'
|
||||
import nodemailer, { SendMailOptions } from 'nodemailer'
|
||||
|
||||
interface Args {
|
||||
to: SendMailOptions['to']
|
||||
@@ -15,42 +15,49 @@ interface SuccessResult {
|
||||
messageSize: number
|
||||
response: string
|
||||
envelope: {
|
||||
from: string | false,
|
||||
from: string | false
|
||||
to: string[]
|
||||
},
|
||||
}
|
||||
messageId: string
|
||||
}
|
||||
|
||||
export function sendMail({to, from, subject, text}: Args): Promise<SuccessResult> {
|
||||
let transporter = nodemailer.createTransport({
|
||||
export function sendMail({
|
||||
to,
|
||||
from,
|
||||
subject,
|
||||
text,
|
||||
}: Args): Promise<SuccessResult> {
|
||||
const transporter = nodemailer.createTransport({
|
||||
host: 'smtp.mailgun.org',
|
||||
port: 587,
|
||||
secure: false,
|
||||
tls: {
|
||||
ciphers:'SSLv3'
|
||||
ciphers: 'SSLv3',
|
||||
},
|
||||
auth: {
|
||||
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) => {
|
||||
transporter.sendMail({
|
||||
from,
|
||||
to,
|
||||
subject,
|
||||
text,
|
||||
}, (error, info) => {
|
||||
if (error) {
|
||||
reject(error);
|
||||
} else {
|
||||
resolve(info);
|
||||
transporter.sendMail(
|
||||
{
|
||||
from,
|
||||
to,
|
||||
subject,
|
||||
text,
|
||||
},
|
||||
(error, info) => {
|
||||
if (error) {
|
||||
reject(error)
|
||||
} else {
|
||||
resolve(info)
|
||||
}
|
||||
}
|
||||
});
|
||||
)
|
||||
}) as any as Promise<SuccessResult>
|
||||
return emailPromise
|
||||
}
|
||||
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
import { requireAuth } from 'src/lib/auth'
|
||||
import {sendMail} from 'src/lib/sendmail'
|
||||
import {users} from 'src/services/users/users'
|
||||
import { sendMail } from 'src/lib/sendmail'
|
||||
import { users } from 'src/services/users/users'
|
||||
|
||||
export const sendAllUsersEmail = async ({input: {body, subject}}) => {
|
||||
export const sendAllUsersEmail = async ({ input: { body, subject } }) => {
|
||||
requireAuth({ role: 'admin' })
|
||||
const recipients = (await users()).map(({email}) => email)
|
||||
const recipients = (await users()).map(({ email }) => email)
|
||||
const from = {
|
||||
address:'news@mail.cadhub.xyz',
|
||||
address: 'news@mail.cadhub.xyz',
|
||||
name: 'CadHub',
|
||||
}
|
||||
const result = await sendMail({
|
||||
|
||||
Reference in New Issue
Block a user