Skip to content

Commit

Permalink
feat: send notification when file gets shared
Browse files Browse the repository at this point in the history
  • Loading branch information
KernelDeimos committed Jun 16, 2024
1 parent f9d2a87 commit 2f6c428
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
20 changes: 20 additions & 0 deletions packages/backend/src/routers/share.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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);
}
Expand All @@ -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({});
};

Expand Down
1 change: 1 addition & 0 deletions packages/backend/src/util/expressutil.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 2f6c428

Please sign in to comment.