feat: send notification when file gets shared

This commit is contained in:
KernelDeimos 2024-06-15 20:15:29 -04:00 committed by Eric Dubé
parent f9d2a87d25
commit 2f6c428a40
2 changed files with 21 additions and 0 deletions

View File

@ -13,6 +13,8 @@ const { TYPE_DIRECTORY } = require('../filesystem/FSNodeContext');
const { PermissionUtil } = require('../services/auth/PermissionService');
const { validate } = require('uuid');
const configurable_auth = require('../middleware/configurable_auth');
const { UsernameNotifSelector } = require('../services/NotificationService');
const { quot } = require('../util/strutil');
const uuidv4 = require('uuid').v4;
@ -47,6 +49,7 @@ const handler_item_by_username = async (req, res) => {
const svc_token = req.services.get('token');
const svc_email = req.services.get('email');
const svc_permission = req.services.get('permission');
const svc_notification = req.services.get('notification');
console.log('which actor exists?',
req.actor,
@ -85,7 +88,9 @@ const handler_item_by_username = async (req, res) => {
}
let email_path = path;
let is_dir = true;
if ( await node.get('type') !== TYPE_DIRECTORY ) {
is_dir = false;
// remove last component
email_path = email_path.slice(0, path.lastIndexOf('/')+1);
}
@ -106,6 +111,21 @@ const handler_item_by_username = async (req, res) => {
await svc_email.send_email({ email: recipient.email }, email_tmpl, email_values);
const wut = is_dir ? 'directory' : 'file';
svc_notification.notify(UsernameNotifSelector(username), {
source: 'sharing',
icon: 'shared.svg',
title: 'A file was shared with you!',
template: 'file-shared-with-you',
fields: {
username: req.user.username,
type: wut,
filename: await node.get('name'),
},
text: `The user ${quot(req.user.username)} shared a ${wut} ` +
`with you called ${quot(await node.get('name'))}`
});
res.send({});
};

View File

@ -5,6 +5,7 @@ const Endpoint = function Endpoint (spec) {
attach (route) {
const eggspress_options = {
allowedMethods: spec.methods ?? ['GET'],
...(spec.mw ? { mw: spec.mw } : {}),
};
const eggspress_router = eggspress(
spec.route,