Add feature to send share with email
This commit is contained in:
@@ -7,6 +7,7 @@
|
||||
"author": "",
|
||||
"license": "ISC",
|
||||
"dependencies": {
|
||||
"node-appwrite": "^5.0.0"
|
||||
"node-appwrite": "^5.0.0",
|
||||
"nodemailer": "^6.7.5"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,8 +4,8 @@ const util = require("./util")
|
||||
module.exports = async function (req, res) {
|
||||
const client = new sdk.Client();
|
||||
|
||||
// You can remove services you don't use
|
||||
let database = new sdk.Database(client);
|
||||
let users = new sdk.Users(client);
|
||||
let storage = new sdk.Storage(client);
|
||||
|
||||
client
|
||||
@@ -34,6 +34,18 @@ module.exports = async function (req, res) {
|
||||
).$id;
|
||||
}
|
||||
|
||||
let userIds;
|
||||
if (payload.emails) {
|
||||
const creatorEmail = (await users.get(userId)).email
|
||||
userIds = []
|
||||
userIds.push(userId)
|
||||
for (const email of payload.emails) {
|
||||
userIds.push((await users.list(`email='${email}'`)).users[0].$id)
|
||||
util.sendMail(email, creatorEmail, payload.id)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Create the storage bucket
|
||||
await storage.createBucket(
|
||||
payload.id,
|
||||
@@ -48,6 +60,7 @@ module.exports = async function (req, res) {
|
||||
// Create document in Shares collection
|
||||
await database.createDocument("shares", payload.id, {
|
||||
securityID: securityDocumentId,
|
||||
users: userIds,
|
||||
createdAt: Date.now(),
|
||||
expiresAt: expiration,
|
||||
});
|
||||
|
||||
@@ -1,9 +1,32 @@
|
||||
const { scryptSync } = require("crypto");
|
||||
const mail = require("nodemailer")
|
||||
|
||||
|
||||
const transporter = mail.createTransport({
|
||||
host: process.env["SMTP_HOST"],
|
||||
port: process.env["SMTP_PORT"],
|
||||
secure: false,
|
||||
auth: {
|
||||
user: process.env["SMTP_USER"],
|
||||
pass: process.env["SMTP_PASSWORD"],
|
||||
},
|
||||
});
|
||||
|
||||
const hashPassword = (password, salt) => {
|
||||
return scryptSync(password, salt, 64).toString("hex");
|
||||
}
|
||||
|
||||
const sendMail = (receiver, creatorEmail, shareId) => {
|
||||
let message = {
|
||||
from: process.env["SMTP_FROM"],
|
||||
to: receiver,
|
||||
subject: "New share from Pingvin Share",
|
||||
text: `Hey, ${creatorEmail} shared files with you. To access the files, visit ${process.env.FRONTEND_URL}/share/${shareId}`
|
||||
|
||||
}
|
||||
transporter.sendMail(message)
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
hashPassword,
|
||||
hashPassword, sendMail
|
||||
}
|
||||
Reference in New Issue
Block a user