Skip to content

Commit e6a3700

Browse files
committed
fix: backend improvements + success message
1 parent 666e1be commit e6a3700

4 files changed

Lines changed: 35 additions & 15 deletions

File tree

backend/docker-compose.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ services:
1010
- DATABASE_URL=${DATABASE_URL}
1111
networks:
1212
- internal
13+
# add external if you are not planning on using the nginx in this docker file
1314

1415
db:
1516
image: postgres:15
@@ -43,9 +44,7 @@ services:
4344

4445
networks:
4546
internal:
46-
internal: true
4747
external:
48-
external: true
4948

5049
volumes:
5150
pgdata:

backend/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"repository": "https://github.com/beaver-notes/beaver-website",
77
"author": "Daniele Rolli",
88
"license": "MIT",
9+
"type": "module",
910
"dependencies": {
1011
"body-parser": "^1.20.2",
1112
"cors": "^2.8.5",

backend/scripts/export_cvs.js

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
1-
import dotenv from "dotenv";
21
import crypto from "crypto";
3-
import fs from "fs";
42
import pkg from "pg";
3+
import fs from "fs";
54

6-
dotenv.config();
75
const { Pool } = pkg;
86
const pool = new Pool({ connectionString: process.env.DATABASE_URL });
97

108
const algorithm = "aes-256-gcm";
119

12-
function decrypt({ iv, encrypted, authTag }) {
10+
function decrypt(iv, encrypted, authTag) {
11+
if (!iv || !encrypted || !authTag) {
12+
return null;
13+
}
14+
1315
const decipher = crypto.createDecipheriv(
1416
algorithm,
1517
Buffer.from(process.env.ENCRYPTION_KEY, "hex"),
@@ -21,15 +23,17 @@ function decrypt({ iv, encrypted, authTag }) {
2123
return decrypted;
2224
}
2325

24-
(async () => {
25-
const result = await pool.query(
26+
async function exportEmails() {
27+
const { rows } = await pool.query(
2628
"SELECT iv, encrypted, auth_tag FROM beta_emails"
2729
);
28-
const emails = result.rows.map((row) => decrypt(row));
2930

30-
const csv = "email\n" + emails.join("\n");
31-
fs.writeFileSync("beta_testers.csv", csv);
31+
const emails = rows
32+
.map((row) => decrypt(row.iv, row.encrypted, row.auth_tag))
33+
.filter(Boolean);
34+
35+
fs.writeFileSync("emails.csv", emails.join("\n"), "utf8");
36+
console.log(`Exported ${emails.length} emails`);
37+
}
3238

33-
console.log(`Exported ${emails.length} emails to beta_testers.csv`);
34-
process.exit(0);
35-
})();
39+
exportEmails().catch(console.error);

src/Download.vue

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ export default {
2929
intervalId: null,
3030
showEmailPrompt: false,
3131
email: "",
32+
statusMessage: "",
3233
};
3334
},
3435
mounted() {
@@ -94,6 +95,7 @@ export default {
9495
if (response.data.success) {
9596
this.statusMessage = "Email sent successfully!";
9697
this.email = "";
98+
this.showEmailPrompt = false;
9799
} else {
98100
this.statusMessage = "Failed to send email. Try again later.";
99101
}
@@ -287,8 +289,22 @@ export default {
287289
v-if="isAndroid"
288290
class="flex flex-col sm:flex-row gap-4 justify-center items-center w-full max-w-sm"
289291
>
292+
<div v-if="statusMessage" class="mt-6 w-full max-w-sm mx-auto">
293+
<p
294+
class="text-sm text-center"
295+
:class="
296+
statusMessage.includes('successfully')
297+
? 'text-green-600 dark:text-green-400'
298+
: 'text-red-600 dark:text-red-400'
299+
"
300+
>
301+
{{ statusMessage }}
302+
</p>
303+
</div>
304+
305+
<!-- Only show form if no message OR not a success -->
290306
<div
291-
v-if="isAndroid && showEmailPrompt"
307+
v-else-if="isAndroid && showEmailPrompt"
292308
class="mt-6 w-full max-w-sm mx-auto"
293309
>
294310
<p

0 commit comments

Comments
 (0)