Skip to content

Commit 0405d2c

Browse files
committed
Revert "Merge branch 'master' into fix-404-error"
This reverts commit 552a6a3, reversing changes made to e1bc12f.
1 parent 3a1840f commit 0405d2c

6 files changed

Lines changed: 28 additions & 127 deletions

File tree

package.json

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
{
22
"scripts": {
3-
"start": "nodemon server.cjs",
4-
"devStart": "nodemon server.cjs"
5-
3+
"start": "nodemon server.js",
4+
"devStart": "nodemon server.js"
65
},
76
"dependencies": {
87
"dotenv": "^16.4.5",
@@ -17,5 +16,4 @@
1716
"devDependencies": {
1817
"nodemon": "^3.1.0"
1918
}
20-
2119
}

public/index.css

Lines changed: 3 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,6 @@
99
--black: rgb(67, 63, 63);
1010
}
1111

12-
13-
.fa-paper-plane {
14-
background: white;
15-
16-
}
17-
18-
19-
20-
2112
.parent-container {
2213
height: 100vh;
2314
width: 100vw;
@@ -110,14 +101,6 @@ h1 {
110101
margin-top: 80px;
111102
}
112103

113-
114-
.user-img {
115-
height: 200px;
116-
width: 200px;
117-
}
118-
119-
120-
121104
.want-another-recipe,
122105
button {
123106
text-transform: uppercase;
@@ -135,15 +118,9 @@ button {
135118
margin: auto;
136119
}
137120

138-
139121
.email-section {
140122
width: 200px;
141123
display: none;
142-
143-
144-
.grid {
145-
/* display: grid; */
146-
147124
grid-template-columns: 2fr 1fr;
148125
gap: 1rem;
149126
margin:auto
@@ -159,11 +136,9 @@ button {
159136
background-color: var(--green);
160137
transition: background-color 0.5s ease;
161138
display: block;
162-
163139
margin: auto;
164140
margin-top: 20px;
165141
width: fit-content;
166-
167142
}
168143

169144
.gpt-response {
@@ -237,7 +212,6 @@ input:checked + .slider:before {
237212
transform: translateX(26px);
238213
}
239214

240-
241215
/* Rounded sliders */
242216
.slider.round {
243217
border-radius: 34px;
@@ -249,11 +223,6 @@ input:checked + .slider:before {
249223

250224
/* Loading indicator */
251225

252-
#user-text {
253-
display: none;
254-
}
255-
r
256-
257226
#loading-container {
258227
display: none;
259228
margin-bottom: 1em;
@@ -277,6 +246,9 @@ r
277246
text-align: center;
278247
}
279248

249+
.off {
250+
display: none;
251+
}
280252

281253
.legend {
282254
/* background: var(--green) */

public/index.html

Lines changed: 1 addition & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -54,22 +54,12 @@ <h1 aria-label="app text" class="headline">
5454
/>
5555
<label for="other-dietary-requirements">other</label>
5656
<input
57-
5857
id="user-text"
5958
type="text"
6059
class="dietary-requirements off"
6160
value=""
6261
name="what_are_user_other_dietary_requirements"
6362
placeholder="I don't eat:"
64-
65-
id="user-text"
66-
type="text"
67-
class="dietary-requirements"
68-
value=""
69-
name="what_are_user_other_dietary_requirements"
70-
placeholder="I don't eat:"
71-
72-
7363
/>
7464
</fieldset>
7565

@@ -107,19 +97,6 @@ <h1 aria-label="app text" class="headline">
10797
<div id="loading-indicator"></div>
10898
<h3 id="loading-text">Creating Recipe...</h3>
10999
</div>
110-
111-
<section
112-
aria-label="gpt-response"
113-
class="gpt-response preserve-line-breaks"
114-
></section>
115-
<button class="want-another-recipe">I want another recipe</button>
116-
<button class="send-recipe-to-user-inbox" name="do_we_email_user" value="false">send recipe to my inbox</button>
117-
<section class="email-section">
118-
<input type="email" id="user-email" class="" name="user_email_address" placeholder="sophie@example.com">
119-
<i class="fa fa-paper-plane" aria-hidden="true" fa-lg ></i>
120-
<!-- <button class="send-email-btn">send</button> -->
121-
</section>
122-
123100

124101

125102

@@ -153,10 +130,6 @@ <h3 id="loading-text">Creating Recipe...</h3>
153130

154131
</div>
155132
</div>
156-
<!-- <script src="index.js"></script> -->
157-
<script type="module" src="index.js"></script>
158-
159-
160-
133+
<script src="index.js"></script>
161134
</body>
162135
</html>

public/index.js

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,6 @@ let errorMessage = `
8888

8989
tryAgainBtn.style.display = "none";
9090

91-
9291
function createQuery(myObject) {
9392
let esc = encodeURIComponent;
9493
let query = Object.keys(myObject)
@@ -97,8 +96,6 @@ function createQuery(myObject) {
9796
return query;
9897
}
9998

100-
101-
10299
function loopOverArrayOfElements(array, display) {
103100
array.forEach((elememt) => {
104101
elememt.style.display = display;
@@ -206,8 +203,8 @@ paperPlane.addEventListener("click", () => {
206203
recipeButtons.forEach((button) => {
207204
console.log(userText.value);
208205
button.addEventListener("click", async () => {
209-
// recipeTextLoaded = false; undefined
210-
// recipeImageLoaded = false; undefined
206+
recipeTextLoaded = false;
207+
recipeImageLoaded = false;
211208

212209
let userRecipe = {
213210
[button.name]: button.value,
@@ -243,9 +240,7 @@ recipeButtons.forEach((button) => {
243240
.catch((error) => {
244241
console.error("Error", error);
245242
});
246-
247243
fetch(`/openai?${createQuery(userRecipe)}`)
248-
249244
.then((response) => response.json())
250245
.then((data) => {
251246
// CREATE IMAGE PROMISE

public/url_folder/url_folder.txt

Lines changed: 0 additions & 1 deletion
This file was deleted.

server.js

Lines changed: 20 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,9 @@
11
const express = require("express");
2-
const fs = require("fs");
3-
const nodemailer = require("nodemailer");
2+
var nodemailer = require("nodemailer");
3+
require("dotenv").config();
44
const { OpenAI } = require("openai");
55
const app = express();
66
const bodyParser = require("body-parser");
7-
const path = require("path");
8-
require("dotenv").config();
9-
let doubleResponse;
10-
117
app.use(bodyParser.json());
128
app.post("/server.js", (req, res) => {
139
const dishCountry = req.body.recipe_country_of_origin;
@@ -19,6 +15,9 @@ app.post("/server.js", (req, res) => {
1915
const openai = new OpenAI({
2016
apiKey: process.env.openaiAPI,
2117
});
18+
19+
let doubleResponse;
20+
2221
app.get("/email", async (req, res) => {
2322
var transporter = nodemailer.createTransport({
2423
service: process.env.service,
@@ -28,49 +27,16 @@ app.get("/email", async (req, res) => {
2827
},
2928
});
3029

31-
const folderPath = path.join(__dirname, "./public/url_folder");
32-
const url = doubleResponse.image.data[0].url;
33-
const filePath = path.join(folderPath, "url_folder.txt");
34-
fs.writeFileSync(filePath, url);
35-
36-
const emailDocument = `
37-
<html>
38-
<head>
39-
<style>
40-
.preserve-line-breaks {
41-
white-space: pre-line
42-
}
43-
.user-img {
44-
width: 200px;
45-
height: 200px;
46-
}
47-
</style>
48-
</head>
49-
<body class="preserve-line-breaks" >
50-
${doubleResponse.text.choices[0].message.content}
51-
<br />
52-
Embedded image:
53-
<br />
54-
<img class="user-img" src="${url}"/>
55-
</body>
56-
</html>
57-
`;
58-
59-
var mailOptions = {
60-
from: process.env.from,
61-
to: req.query.user_email_address,
62-
subject: "Your recipe from recipe-for-success dynamic app",
63-
html: emailDocument,
64-
attachments: [
65-
{
66-
filename: "url_folder.txt",
67-
path: path.join(__dirname, "/public/url_folder/url_folder.txt"),
68-
cid: "url",
69-
},
70-
],
71-
};
72-
73-
console.log(mailOptions)
30+
if (doubleResponse && doubleResponse.text && doubleResponse.text.choices) {
31+
var mailOptions = {
32+
from: process.env.from,
33+
to: req.query.user_email_address,
34+
subject: "Your recipe from recipe-for-success dynamic app",
35+
text: doubleResponse.text.choices[0].message.content,
36+
};
37+
} else {
38+
console.log("doubleResponse is not defined yet.");
39+
}
7440

7541
transporter.sendMail(mailOptions, function (error, info) {
7642
if (error) {
@@ -91,20 +57,19 @@ app.get("/openai", async (req, res) => {
9157
{
9258
user_otherdietary_requirements:
9359
req.query.what_are_user_other_dietary_requirements,
94-
},
95-
{ I_do_not_eat: req.query.I_do_not_eat }
60+
}
9661
);
9762

9863
const prompt = `Provide a recipe for a dish from ${
9964
req.query.recipe_country_of_origin
10065
}, taking into account the fact that I'm ${
10166
req.query.is_lactose_intolerant === "true"
102-
? "lactose intolerant,"
103-
: "not lactose intolerant,"
104-
} ${req.query.is_vegan === "true" ? "I'm vegan" : "I'm not vegan"} and ${
67+
? "lactose intolerant"
68+
: "not lactose intolerant"
69+
} ${req.query.is_vegan === "true" ? "vegan" : "not vegan"} and ${
10570
req.query.what_are_user_other_dietary_requirements === ""
10671
? "I have no other dietary requirements"
107-
: `${req.query.I_do_not_eat}${req.query.what_are_user_other_dietary_requirements}`
72+
: req.query.what_are_user_other_dietary_requirements
10873
} `;
10974

11075
console.log(prompt);
@@ -130,7 +95,6 @@ app.get("/openai", async (req, res) => {
13095
text: completion,
13196
image: imageResponse,
13297
};
133-
console.log(doubleResponse.text.choices);
13498
res.json(doubleResponse);
13599
} catch (error) {
136100
console.error("An error occurred:", error.message);

0 commit comments

Comments
 (0)