<commit_before>import nodemailer from 'nodemailer';
import aws from 'aws-sdk';

import conf from '../conf';

const transporter = nodemailer.createTransport({
    service: 'Mailgun',
    auth: {
        user: conf.get('mailerUser'),
        pass: conf.get('mailerPassword')
    }
});

export const contact = async (ctx) => {
    const { name, email, message } = ctx.request.body;

    // TODO better validation
    if (name && email && message) {
        const mailOptions = {
            to: '<EMAIL>',
            from: `${name} <${email}>`,
            subject: 'Contact Form',
            text: message
        };

        try {
            await transporter.sendMail(mailOptions);
            ctx.body = { status: 'success', message: 'Contact informaton sent successfully' };
        } catch (err) {
            ctx.status = 400;
            ctx.body = { status: 'error', message: 'Invalid contact informaton provided' };
        }
    } else {
        ctx.status = 400;
        ctx.body = { status: 'error', message: 'Invalid contact informaton provided' };
    }
};

const S3_BUCKET = '';

// Ref: https://devcenter.heroku.com/articles/s3-upload-node#uploading-directly-to-s3
export const upload = async (ctx) => {
    const s3 = new aws.S3();
    const fileName = ctx.request.body['file-name'];
    const fileType = ctx.request.body['file-type'];
    const s3Params = {
        Bucket: S3_BUCKET,
        Key: fileName,
        Expires: 60,
        ContentType: fileType,
        ACL: 'public-read'
    };

    try {
        const data = await s3.getSignedUrl('putObject', s3Params);
        ctx.body = {
            signedRequest: data,<commit_msg>added contact form with mailer and amazon s3 file upload<commit_after>import nodemailer from 'nodemailer';
import aws from 'aws-sdk';

import conf from '../conf';

const transporter = nodemailer.createTransport({
    service: 'Mailgun',
    auth: {
        user: conf.get('mailerUser'),
        pass: conf.get('mailerPassword')
    }
});

export const contact = async (ctx) => {
    const { name, email, message } = ctx.request.body;

    // TODO better validation
    if (name && email && message) {
        const mailOptions = {
            to: '<EMAIL>',
            from: `${name} <${email}>`,
            subject: 'Contact Form',
            text: message
        };

        try {
            await transporter.sendMail(mailOptions);
            ctx.body = { status: 'success', message: 'Contact informaton sent successfully' };
        } catch (err) {
            ctx.status = 400;
            ctx.body = { status: 'error', message: 'Invalid contact informaton provided' };
        }
    } else {
        ctx.status = 400;
        ctx.body = { status: 'error', message: 'Invalid contact informaton provided' };
    }
};

const S3_BUCKET = '';

// Ref: https://devcenter.heroku.com/articles/s3-upload-node#uploading-directly-to-s3
// Initialising the s3 object automatically loads the AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY variables that were set into the environment earlier.
export const upload = async (ctx) => {
    const s3 = new aws.S3();
    const fileName = ctx.request.body['file-name'];
    const fileType = ctx.request.body['file-type'];
    const s3Params = {
        Bucket: S3_BUCKET,
        Key: fileName,
        Expires: 60,
        ContentType: fileType,
        ACL: 'public-read'
    };

    try {
        const data = await s3.getSignedUrl('putObject', s3Params);
        ctx.body = {
            signedRequest: data,
{'fraction_non_alphanumeric': 0.13145138294838893, 'fraction_numerical': 0.010265183917878529, 'mean_word_length': 2.2969924812030076, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 11, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3477842', 'n_tokens_mistral': 1056, 'n_tokens_neox': 1037, 'n_words': 276}