mirror of
https://github.com/HeyPuter/puter
synced 2024-11-15 06:15:47 +00:00
feat: send notification when file gets shared
This commit is contained in:
parent
f9d2a87d25
commit
2f6c428a40
@ -13,6 +13,8 @@ const { TYPE_DIRECTORY } = require('../filesystem/FSNodeContext');
|
|||||||
const { PermissionUtil } = require('../services/auth/PermissionService');
|
const { PermissionUtil } = require('../services/auth/PermissionService');
|
||||||
const { validate } = require('uuid');
|
const { validate } = require('uuid');
|
||||||
const configurable_auth = require('../middleware/configurable_auth');
|
const configurable_auth = require('../middleware/configurable_auth');
|
||||||
|
const { UsernameNotifSelector } = require('../services/NotificationService');
|
||||||
|
const { quot } = require('../util/strutil');
|
||||||
|
|
||||||
const uuidv4 = require('uuid').v4;
|
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_token = req.services.get('token');
|
||||||
const svc_email = req.services.get('email');
|
const svc_email = req.services.get('email');
|
||||||
const svc_permission = req.services.get('permission');
|
const svc_permission = req.services.get('permission');
|
||||||
|
const svc_notification = req.services.get('notification');
|
||||||
|
|
||||||
console.log('which actor exists?',
|
console.log('which actor exists?',
|
||||||
req.actor,
|
req.actor,
|
||||||
@ -85,7 +88,9 @@ const handler_item_by_username = async (req, res) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let email_path = path;
|
let email_path = path;
|
||||||
|
let is_dir = true;
|
||||||
if ( await node.get('type') !== TYPE_DIRECTORY ) {
|
if ( await node.get('type') !== TYPE_DIRECTORY ) {
|
||||||
|
is_dir = false;
|
||||||
// remove last component
|
// remove last component
|
||||||
email_path = email_path.slice(0, path.lastIndexOf('/')+1);
|
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);
|
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({});
|
res.send({});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -5,6 +5,7 @@ const Endpoint = function Endpoint (spec) {
|
|||||||
attach (route) {
|
attach (route) {
|
||||||
const eggspress_options = {
|
const eggspress_options = {
|
||||||
allowedMethods: spec.methods ?? ['GET'],
|
allowedMethods: spec.methods ?? ['GET'],
|
||||||
|
...(spec.mw ? { mw: spec.mw } : {}),
|
||||||
};
|
};
|
||||||
const eggspress_router = eggspress(
|
const eggspress_router = eggspress(
|
||||||
spec.route,
|
spec.route,
|
||||||
|
Loading…
Reference in New Issue
Block a user