forked from fac29b/recipe-for-success
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'fac29b:master' into master
- Loading branch information
Showing
27 changed files
with
2,271 additions
and
917 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
# This workflow will build and push a node.js application to an Azure Web App when a commit is pushed to your default branch. | ||
# | ||
# This workflow assumes you have already created the target Azure App Service web app. | ||
# For instructions see https://docs.microsoft.com/en-us/azure/app-service/quickstart-nodejs?tabs=linux&pivots=development-environment-cli | ||
# | ||
# To configure this workflow: | ||
# | ||
# 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. | ||
# For more information: https://docs.microsoft.com/en-us/azure/app-service/deploy-github-actions?tabs=applevel#generate-deployment-credentials | ||
# | ||
# 2. Create a secret in your repository named AZURE_WEBAPP_PUBLISH_PROFILE, paste the publish profile contents as the value of the secret. | ||
# For instructions on obtaining the publish profile see: https://docs.microsoft.com/azure/app-service/deploy-github-actions#configure-the-github-secret | ||
# | ||
# 3. Change the value for the AZURE_WEBAPP_NAME. Optionally, change the AZURE_WEBAPP_PACKAGE_PATH and NODE_VERSION environment variables below. | ||
# | ||
# For more information on GitHub Actions for Azure: https://github.com/Azure/Actions | ||
# For more information on the Azure Web Apps Deploy action: https://github.com/Azure/webapps-deploy | ||
# For more samples to get started with GitHub Action workflows to deploy to Azure: https://github.com/Azure/actions-workflow-samples | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
name: Build and Deploy Node.js App to Azure | ||
|
||
on: | ||
push: | ||
branches: [ "master" ] | ||
workflow_dispatch: | ||
|
||
env: | ||
AZURE_WEBAPP_NAME: recipe-for-success | ||
AZURE_WEBAPP_PACKAGE_PATH: '.' | ||
NODE_VERSION: '14.x' | ||
|
||
permissions: | ||
contents: read | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- name: Set up Node.js | ||
uses: actions/setup-node@v3 | ||
with: | ||
node-version: ${{ env.NODE_VERSION }} | ||
cache: 'npm' | ||
- name: Install Dependencies | ||
run: npm install | ||
- name: Build Application | ||
run: npm run build --if-present | ||
- name: Test Application | ||
run: npm run test --if-present | ||
- name: Upload artifact for deployment job | ||
uses: actions/upload-artifact@v3 | ||
with: | ||
name: node-app | ||
path: . | ||
|
||
deploy: | ||
permissions: | ||
contents: none | ||
runs-on: ubuntu-latest | ||
needs: build | ||
steps: | ||
- name: Download artifact from build job | ||
uses: actions/download-artifact@v3 | ||
with: | ||
name: node-app | ||
- name: 'Login via Azure CLI' | ||
uses: azure/login@v1 | ||
with: | ||
creds: ${{ secrets.AZURE_CREDENTIALS }} | ||
- name: 'Deploy to Azure WebApp' | ||
uses: azure/webapps-deploy@v2 | ||
with: | ||
app-name: ${{ env.AZURE_WEBAPP_NAME }} | ||
publish-profile: ${{ secrets.AZURE_WEBAPP_PUBLISH_PROFILE }} | ||
package: ${{ env.AZURE_WEBAPP_PACKAGE_PATH }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
.env | ||
node_modules | ||
node_modules |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
{ | ||
// Use IntelliSense to learn about possible attributes. | ||
// Hover to view descriptions of existing attributes. | ||
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 | ||
"version": "0.2.0", | ||
"configurations": [ | ||
{ | ||
"type": "node", | ||
"request": "launch", | ||
"name": "Launch Program", | ||
"skipFiles": [ | ||
"<node_internals>/**" | ||
], | ||
"program": "${workspaceFolder}/server.js" | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
const nodemailer = require("nodemailer"); | ||
const recipeFromStream = require("./stream.js"); | ||
const path = require("path"); | ||
|
||
|
||
async function processEmail(req, res) { | ||
console.log(`is picked up ${req.body.pictureSectionText}`) | ||
let recipe = recipeFromStream.getStreamRecipe(); | ||
// let recipe = recipeFromStream.getStreamRecipe() !== "" ? recipeFromStream.getStreamRecipe() : req.body.pictureSectionText; | ||
// let recipe = req.body.pictureSectionText !== "" ? req.body.pictureSectionText : recipeFromStream.getStreamRecipe() ; | ||
let url = recipeFromStream.getUrl(); | ||
console.log(`email.js file ${url}`) | ||
var transporter = nodemailer.createTransport({ | ||
service: process.env.service, | ||
auth: { | ||
user: process.env.from, | ||
pass: process.env.third_party_app_password, | ||
}, | ||
}); | ||
|
||
const emailDocument = ` | ||
<html> | ||
<head> | ||
<style> | ||
.preserve-line-breaks { | ||
white-space: pre-line | ||
} | ||
.user-img { | ||
width: 200px; | ||
height: 200px; | ||
} | ||
</style> | ||
</head> | ||
<body class="preserve-line-breaks" > | ||
${recipe} | ||
<br /> | ||
Embedded image: | ||
<br /> | ||
<img class="user-img" src="${url}"/> | ||
</body> | ||
</html> | ||
`; | ||
|
||
// if (recipe !== "") { | ||
var mailOptions = { | ||
from: process.env.from, | ||
to: req.query.user_email_address, | ||
subject: " Your recipe from recipe-for-success dynamic app", | ||
text: recipe, | ||
html: emailDocument, | ||
attachments: [ | ||
{ | ||
filename: "url_folder.txt", | ||
path: path.join(__dirname, "../public/url_folder/url_folder.txt"), | ||
cid: "url", | ||
}, | ||
], | ||
}; | ||
// } else { | ||
// console.log("doubleResponse is not defined yet."); | ||
// } | ||
|
||
transporter.sendMail(mailOptions, function (error, info) { | ||
if (error) { | ||
res.status(500).json({emailStatus: info.response}); | ||
console.log(error); | ||
} else { | ||
res.status(250).json({emailStatus: info.response}); | ||
console.log("Email sent: " + info.response); | ||
} | ||
}); | ||
|
||
console.log(`user recipe ${recipe}`); | ||
recipe = "Empty string"; | ||
console.log(recipe) | ||
|
||
} | ||
|
||
module.exports = { | ||
processEmail | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
const nodemailer = require("nodemailer"); | ||
const path = require("path"); | ||
const recipeFromStream = require("./stream.js"); | ||
|
||
|
||
async function processEmail(req, res) { | ||
console.log(`is picked up ${req.body.pictureTextSection}`) | ||
const {user_email_address} = req.query; | ||
|
||
let recipe = req.body.pictureTextSection; | ||
// let recipe = recipeFromStream.getStreamRecipe() !== "" ? recipeFromStream.getStreamRecipe() : req.body.pictureSectionText; | ||
// let recipe = req.body.pictureSectionText !== "" ? req.body.pictureSectionText : recipeFromStream.getStreamRecipe() ; | ||
let url = recipeFromStream.getUrl(); | ||
console.log(`email.js file ${url}`) | ||
var transporter = nodemailer.createTransport({ | ||
service: process.env.service, | ||
auth: { | ||
user: process.env.from, | ||
pass: process.env.third_party_app_password, | ||
}, | ||
}); | ||
|
||
const emailDocument = ` | ||
<html> | ||
<head> | ||
<style> | ||
.preserve-line-breaks { | ||
white-space: pre-line | ||
} | ||
.user-img { | ||
width: 200px; | ||
height: 200px; | ||
} | ||
</style> | ||
</head> | ||
<body class="preserve-line-breaks" > | ||
${recipe} | ||
<br /> | ||
</body> | ||
</html> | ||
`; | ||
|
||
if (recipe !== "") { | ||
var mailOptions = { | ||
from: process.env.from, | ||
to: user_email_address, | ||
subject: " Your recipe from recipe-for-success dynamic app", | ||
text: recipe, | ||
html: emailDocument, | ||
attachments: [ | ||
{ | ||
filename: "url_folder.txt", | ||
path: path.join(__dirname, "../public/url_folder/url_folder.txt"), | ||
|
||
}, | ||
], | ||
}; | ||
} else { | ||
console.log("doubleResponse is not defined yet."); | ||
} | ||
|
||
transporter.sendMail(mailOptions, function (error, info) { | ||
if (error) { | ||
res.status(500).json({emailStatus: info.response}); | ||
console.log(error); | ||
} else { | ||
res.status(250).json({emailStatus: info.response}); | ||
console.log("Email sent: " + info.response); | ||
} | ||
}); | ||
|
||
// console.log(`user recipe ${recipe}`); | ||
// recipe = "Empty string"; | ||
// console.log(recipe) | ||
|
||
} | ||
|
||
module.exports = { | ||
processEmail | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
|
||
const path = require("path"); | ||
const fs = require("fs"); | ||
const { OpenAI } = require("openai"); | ||
require("dotenv").config(); | ||
let recipe = "Recipe:" | ||
let url | ||
|
||
console.log(` server.js file value of recipe is: ${recipe}`) | ||
|
||
|
||
const openai = new OpenAI({ | ||
apiKey: process.env.openaiAPI, | ||
}); | ||
|
||
|
||
|
||
// async function processEmail(req, res) { | ||
// var transporter = nodemailer.createTransport({ | ||
// service: process.env.service, | ||
// auth: { | ||
// user: process.env.from, | ||
// pass: process.env.third_party_app_password, | ||
// }, | ||
// }); | ||
|
||
// const emailDocument = ` | ||
// <html> | ||
// <head> | ||
// <style> | ||
// .preserve-line-breaks { | ||
// white-space: pre-line | ||
// } | ||
// .user-img { | ||
// width: 200px; | ||
// height: 200px; | ||
// } | ||
// </style> | ||
// </head> | ||
// <body class="preserve-line-breaks" > | ||
// ${recipe} | ||
// <br /> | ||
// Embedded image: | ||
// <br /> | ||
// <img class="user-img" src="${url}"/> | ||
// </body> | ||
// </html> | ||
// `; | ||
|
||
// if (recipe !== "") { | ||
// var mailOptions = { | ||
// from: process.env.from, | ||
// to: req.query.user_email_address, | ||
// subject: "Your recipe from recipe-for-success dynamic app", | ||
// text: recipe, | ||
// html: emailDocument, | ||
// attachments: [ | ||
// { | ||
// filename: "url_folder.txt", | ||
// path: path.join(__dirname, "../public/url_folder/url_folder.txt"), | ||
// cid: "url", | ||
// }, | ||
// ], | ||
// }; | ||
// } else { | ||
// console.log("doubleResponse is not defined yet."); | ||
// } | ||
|
||
// transporter.sendMail(mailOptions, function (error, info) { | ||
// if (error) { | ||
// console.log(error); | ||
// } else { | ||
// console.log("Email sent: " + info.response); | ||
// } | ||
// }); | ||
// } | ||
|
||
async function processUpload(req, res) { | ||
const picture = req.body.image; | ||
console.log({ josue_upload: picture }); | ||
// res.status(200).json({ message: `variable ${JSON.stringify(picture)} received` }); | ||
|
||
|
||
|
||
const response = await openai.chat.completions.create({ | ||
model: "gpt-4o", | ||
messages: [ | ||
{ | ||
role: "user", | ||
content: [ | ||
{ type: "text", text: "What can I cook with these ingredients?" }, | ||
{ | ||
type: "image_url", | ||
image_url: { | ||
url: picture, | ||
}, | ||
}, | ||
], | ||
}, | ||
], | ||
}); | ||
|
||
recipe = response.choices[0].message.content | ||
|
||
console.log(`your recipe is ${recipe}`); | ||
res.send(response.choices[0]); | ||
|
||
recipe = "Recipe:" | ||
|
||
|
||
} | ||
|
||
|
||
|
||
|
||
module.exports = { | ||
processUpload, | ||
} |
Oops, something went wrong.