Skip to content

Commit 88215b8

Browse files
authored
Merge branch 'fac29b:master' into master
2 parents c41b157 + 4af15d6 commit 88215b8

27 files changed

Lines changed: 2271 additions & 917 deletions
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
# This workflow will build and push a node.js application to an Azure Web App when a commit is pushed to your default branch.
2+
#
3+
# This workflow assumes you have already created the target Azure App Service web app.
4+
# For instructions see https://docs.microsoft.com/en-us/azure/app-service/quickstart-nodejs?tabs=linux&pivots=development-environment-cli
5+
#
6+
# To configure this workflow:
7+
#
8+
# 1. Download the Publish Profile for your Azure Web App. You can download this file from the Overview page of your Web App in the Azure Portal.
9+
# For more information: https://docs.microsoft.com/en-us/azure/app-service/deploy-github-actions?tabs=applevel#generate-deployment-credentials
10+
#
11+
# 2. Create a secret in your repository named AZURE_WEBAPP_PUBLISH_PROFILE, paste the publish profile contents as the value of the secret.
12+
# For instructions on obtaining the publish profile see: https://docs.microsoft.com/azure/app-service/deploy-github-actions#configure-the-github-secret
13+
#
14+
# 3. Change the value for the AZURE_WEBAPP_NAME. Optionally, change the AZURE_WEBAPP_PACKAGE_PATH and NODE_VERSION environment variables below.
15+
#
16+
# For more information on GitHub Actions for Azure: https://github.com/Azure/Actions
17+
# For more information on the Azure Web Apps Deploy action: https://github.com/Azure/webapps-deploy
18+
# For more samples to get started with GitHub Action workflows to deploy to Azure: https://github.com/Azure/actions-workflow-samples
19+
20+
21+
22+
23+
24+
25+
26+
27+
28+
name: Build and Deploy Node.js App to Azure
29+
30+
on:
31+
push:
32+
branches: [ "master" ]
33+
workflow_dispatch:
34+
35+
env:
36+
AZURE_WEBAPP_NAME: recipe-for-success
37+
AZURE_WEBAPP_PACKAGE_PATH: '.'
38+
NODE_VERSION: '14.x'
39+
40+
permissions:
41+
contents: read
42+
43+
jobs:
44+
build:
45+
runs-on: ubuntu-latest
46+
steps:
47+
- uses: actions/checkout@v4
48+
- name: Set up Node.js
49+
uses: actions/setup-node@v3
50+
with:
51+
node-version: ${{ env.NODE_VERSION }}
52+
cache: 'npm'
53+
- name: Install Dependencies
54+
run: npm install
55+
- name: Build Application
56+
run: npm run build --if-present
57+
- name: Test Application
58+
run: npm run test --if-present
59+
- name: Upload artifact for deployment job
60+
uses: actions/upload-artifact@v3
61+
with:
62+
name: node-app
63+
path: .
64+
65+
deploy:
66+
permissions:
67+
contents: none
68+
runs-on: ubuntu-latest
69+
needs: build
70+
steps:
71+
- name: Download artifact from build job
72+
uses: actions/download-artifact@v3
73+
with:
74+
name: node-app
75+
- name: 'Login via Azure CLI'
76+
uses: azure/login@v1
77+
with:
78+
creds: ${{ secrets.AZURE_CREDENTIALS }}
79+
- name: 'Deploy to Azure WebApp'
80+
uses: azure/webapps-deploy@v2
81+
with:
82+
app-name: ${{ env.AZURE_WEBAPP_NAME }}
83+
publish-profile: ${{ secrets.AZURE_WEBAPP_PUBLISH_PROFILE }}
84+
package: ${{ env.AZURE_WEBAPP_PACKAGE_PATH }}

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
.env
2-
node_modules
2+
node_modules

.vscode/launch.json

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
// Use IntelliSense to learn about possible attributes.
3+
// Hover to view descriptions of existing attributes.
4+
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
5+
"version": "0.2.0",
6+
"configurations": [
7+
{
8+
"type": "node",
9+
"request": "launch",
10+
"name": "Launch Program",
11+
"skipFiles": [
12+
"<node_internals>/**"
13+
],
14+
"program": "${workspaceFolder}/server.js"
15+
}
16+
]
17+
}

controllers/email.js

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
const nodemailer = require("nodemailer");
2+
const recipeFromStream = require("./stream.js");
3+
const path = require("path");
4+
5+
6+
async function processEmail(req, res) {
7+
console.log(`is picked up ${req.body.pictureSectionText}`)
8+
let recipe = recipeFromStream.getStreamRecipe();
9+
// let recipe = recipeFromStream.getStreamRecipe() !== "" ? recipeFromStream.getStreamRecipe() : req.body.pictureSectionText;
10+
// let recipe = req.body.pictureSectionText !== "" ? req.body.pictureSectionText : recipeFromStream.getStreamRecipe() ;
11+
let url = recipeFromStream.getUrl();
12+
console.log(`email.js file ${url}`)
13+
var transporter = nodemailer.createTransport({
14+
service: process.env.service,
15+
auth: {
16+
user: process.env.from,
17+
pass: process.env.third_party_app_password,
18+
},
19+
});
20+
21+
const emailDocument = `
22+
<html>
23+
<head>
24+
<style>
25+
.preserve-line-breaks {
26+
white-space: pre-line
27+
}
28+
.user-img {
29+
width: 200px;
30+
height: 200px;
31+
}
32+
</style>
33+
</head>
34+
<body class="preserve-line-breaks" >
35+
${recipe}
36+
<br />
37+
Embedded image:
38+
<br />
39+
<img class="user-img" src="${url}"/>
40+
</body>
41+
</html>
42+
`;
43+
44+
// if (recipe !== "") {
45+
var mailOptions = {
46+
from: process.env.from,
47+
to: req.query.user_email_address,
48+
subject: " Your recipe from recipe-for-success dynamic app",
49+
text: recipe,
50+
html: emailDocument,
51+
attachments: [
52+
{
53+
filename: "url_folder.txt",
54+
path: path.join(__dirname, "../public/url_folder/url_folder.txt"),
55+
cid: "url",
56+
},
57+
],
58+
};
59+
// } else {
60+
// console.log("doubleResponse is not defined yet.");
61+
// }
62+
63+
transporter.sendMail(mailOptions, function (error, info) {
64+
if (error) {
65+
res.status(500).json({emailStatus: info.response});
66+
console.log(error);
67+
} else {
68+
res.status(250).json({emailStatus: info.response});
69+
console.log("Email sent: " + info.response);
70+
}
71+
});
72+
73+
console.log(`user recipe ${recipe}`);
74+
recipe = "Empty string";
75+
console.log(recipe)
76+
77+
}
78+
79+
module.exports = {
80+
processEmail
81+
}
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
const nodemailer = require("nodemailer");
2+
const path = require("path");
3+
const recipeFromStream = require("./stream.js");
4+
5+
6+
async function processEmail(req, res) {
7+
console.log(`is picked up ${req.body.pictureTextSection}`)
8+
const {user_email_address} = req.query;
9+
10+
let recipe = req.body.pictureTextSection;
11+
// let recipe = recipeFromStream.getStreamRecipe() !== "" ? recipeFromStream.getStreamRecipe() : req.body.pictureSectionText;
12+
// let recipe = req.body.pictureSectionText !== "" ? req.body.pictureSectionText : recipeFromStream.getStreamRecipe() ;
13+
let url = recipeFromStream.getUrl();
14+
console.log(`email.js file ${url}`)
15+
var transporter = nodemailer.createTransport({
16+
service: process.env.service,
17+
auth: {
18+
user: process.env.from,
19+
pass: process.env.third_party_app_password,
20+
},
21+
});
22+
23+
const emailDocument = `
24+
<html>
25+
<head>
26+
<style>
27+
.preserve-line-breaks {
28+
white-space: pre-line
29+
}
30+
.user-img {
31+
width: 200px;
32+
height: 200px;
33+
}
34+
</style>
35+
</head>
36+
<body class="preserve-line-breaks" >
37+
${recipe}
38+
<br />
39+
</body>
40+
</html>
41+
`;
42+
43+
if (recipe !== "") {
44+
var mailOptions = {
45+
from: process.env.from,
46+
to: user_email_address,
47+
subject: " Your recipe from recipe-for-success dynamic app",
48+
text: recipe,
49+
html: emailDocument,
50+
attachments: [
51+
{
52+
filename: "url_folder.txt",
53+
path: path.join(__dirname, "../public/url_folder/url_folder.txt"),
54+
55+
},
56+
],
57+
};
58+
} else {
59+
console.log("doubleResponse is not defined yet.");
60+
}
61+
62+
transporter.sendMail(mailOptions, function (error, info) {
63+
if (error) {
64+
res.status(500).json({emailStatus: info.response});
65+
console.log(error);
66+
} else {
67+
res.status(250).json({emailStatus: info.response});
68+
console.log("Email sent: " + info.response);
69+
}
70+
});
71+
72+
// console.log(`user recipe ${recipe}`);
73+
// recipe = "Empty string";
74+
// console.log(recipe)
75+
76+
}
77+
78+
module.exports = {
79+
processEmail
80+
}

controllers/recipes.js

Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
2+
const path = require("path");
3+
const fs = require("fs");
4+
const { OpenAI } = require("openai");
5+
require("dotenv").config();
6+
let recipe = "Recipe:"
7+
let url
8+
9+
console.log(` server.js file value of recipe is: ${recipe}`)
10+
11+
12+
const openai = new OpenAI({
13+
apiKey: process.env.openaiAPI,
14+
});
15+
16+
17+
18+
// async function processEmail(req, res) {
19+
// var transporter = nodemailer.createTransport({
20+
// service: process.env.service,
21+
// auth: {
22+
// user: process.env.from,
23+
// pass: process.env.third_party_app_password,
24+
// },
25+
// });
26+
27+
// const emailDocument = `
28+
// <html>
29+
// <head>
30+
// <style>
31+
// .preserve-line-breaks {
32+
// white-space: pre-line
33+
// }
34+
// .user-img {
35+
// width: 200px;
36+
// height: 200px;
37+
// }
38+
// </style>
39+
// </head>
40+
// <body class="preserve-line-breaks" >
41+
// ${recipe}
42+
// <br />
43+
// Embedded image:
44+
// <br />
45+
// <img class="user-img" src="${url}"/>
46+
// </body>
47+
// </html>
48+
// `;
49+
50+
// if (recipe !== "") {
51+
// var mailOptions = {
52+
// from: process.env.from,
53+
// to: req.query.user_email_address,
54+
// subject: "Your recipe from recipe-for-success dynamic app",
55+
// text: recipe,
56+
// html: emailDocument,
57+
// attachments: [
58+
// {
59+
// filename: "url_folder.txt",
60+
// path: path.join(__dirname, "../public/url_folder/url_folder.txt"),
61+
// cid: "url",
62+
// },
63+
// ],
64+
// };
65+
// } else {
66+
// console.log("doubleResponse is not defined yet.");
67+
// }
68+
69+
// transporter.sendMail(mailOptions, function (error, info) {
70+
// if (error) {
71+
// console.log(error);
72+
// } else {
73+
// console.log("Email sent: " + info.response);
74+
// }
75+
// });
76+
// }
77+
78+
async function processUpload(req, res) {
79+
const picture = req.body.image;
80+
console.log({ josue_upload: picture });
81+
// res.status(200).json({ message: `variable ${JSON.stringify(picture)} received` });
82+
83+
84+
85+
const response = await openai.chat.completions.create({
86+
model: "gpt-4o",
87+
messages: [
88+
{
89+
role: "user",
90+
content: [
91+
{ type: "text", text: "What can I cook with these ingredients?" },
92+
{
93+
type: "image_url",
94+
image_url: {
95+
url: picture,
96+
},
97+
},
98+
],
99+
},
100+
],
101+
});
102+
103+
recipe = response.choices[0].message.content
104+
105+
console.log(`your recipe is ${recipe}`);
106+
res.send(response.choices[0]);
107+
108+
recipe = "Recipe:"
109+
110+
111+
}
112+
113+
114+
115+
116+
module.exports = {
117+
processUpload,
118+
}

0 commit comments

Comments
 (0)