diff --git a/.env.example b/.env.example index 5e4f6e2..1f8af55 100644 --- a/.env.example +++ b/.env.example @@ -31,4 +31,10 @@ REDIS_PASSWORD="" REDIS_URL="redis://${REDIS_USER}:${REDIS_PASSWORD}@${REDIS_HOST}:${REDIS_PORT}" # Vercel Blob Storage -BLOB_READ_WRITE_TOKEN="vercel_blob_rw_0511953119b0c1167283c7453a088727" # Fake vercel token \ No newline at end of file +BLOB_READ_WRITE_TOKEN="vercel_blob_rw_0511953119b0c1167283c7453a088727" # Fake vercel token + +# Pusher +PUSHER_APP_ID="1684269" +PUSHER_APP_KEY="3a4575271634ad5a09ef" +PUSHER_APP_SECRET="486036ded3c32d02bac3" +PUSHER_APP_CLUSTER="eu" \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index aa5e642..86262db 100644 --- a/package-lock.json +++ b/package-lock.json @@ -24,7 +24,8 @@ "dotenv": "^16.3.1", "fastify": "^4.23.2", "fastify-i18n": "^1.1.1", - "fastify-plugin": "^4.5.1" + "fastify-plugin": "^4.5.1", + "pusher": "^5.1.3" }, "devDependencies": { "@swc/core": "^1.3.85", @@ -1842,6 +1843,15 @@ "resolved": "https://registry.npmjs.org/@types/node/-/node-20.6.2.tgz", "integrity": "sha512-Y+/1vGBHV/cYk6OI1Na/LHzwnlNCAfU3ZNGrc1LdRe/LAIbdDPTTv/HU3M7yXN448aTVDq3eKRm2cg7iKLb8gw==" }, + "node_modules/@types/node-fetch": { + "version": "2.6.6", + "resolved": "https://registry.npmjs.org/@types/node-fetch/-/node-fetch-2.6.6.tgz", + "integrity": "sha512-95X8guJYhfqiuVVhRFxVQcf4hW/2bCuoPwDasMf/531STFoNoWTT7YDnWdXHEZKqAGUigmpG31r2FE70LwnzJw==", + "dependencies": { + "@types/node": "*", + "form-data": "^4.0.0" + } + }, "node_modules/@types/semver": { "version": "7.5.2", "resolved": "https://registry.npmjs.org/@types/semver/-/semver-7.5.2.tgz", @@ -4602,6 +4612,15 @@ "integrity": "sha512-zz06S8t0ozoDXMG+ube26zeCTNXcKIPJZJi8hBrF4idCLms4CG9QtK7qBl1boi5ODzFpjswb5JPmHCbMpjaYzg==", "dev": true }, + "node_modules/is-base64": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/is-base64/-/is-base64-1.1.0.tgz", + "integrity": "sha512-Nlhg7Z2dVC4/PTvIFkgVVNvPHSO2eR/Yd0XzhGiXCXEvWnptXlXa/clQ8aePPiMuxEGcWfzWbGw2Fe3d+Y3v1g==", + "bin": { + "is_base64": "bin/is-base64", + "is-base64": "bin/is-base64" + } + }, "node_modules/is-bigint": { "version": "1.0.4", "resolved": "https://registry.npmjs.org/is-bigint/-/is-bigint-1.0.4.tgz", @@ -6712,6 +6731,22 @@ } ] }, + "node_modules/pusher": { + "version": "5.1.3", + "resolved": "https://registry.npmjs.org/pusher/-/pusher-5.1.3.tgz", + "integrity": "sha512-Bmy5guFxQsbYSFLF3CM7GA2qE1zDJYn51PnNme9QlSjGguvkqUg4nj31PbgiLVDFK2sJvxPfx4JrB2HLgM3kaw==", + "dependencies": { + "@types/node-fetch": "^2.5.7", + "abort-controller": "^3.0.0", + "is-base64": "^1.1.0", + "node-fetch": "^2.6.1", + "tweetnacl": "^1.0.0", + "tweetnacl-util": "^0.15.0" + }, + "engines": { + "node": ">= 4.0.0" + } + }, "node_modules/querystringify": { "version": "2.2.0", "resolved": "https://registry.npmjs.org/querystringify/-/querystringify-2.2.0.tgz", @@ -7751,6 +7786,16 @@ "node": ">=0.10.0" } }, + "node_modules/tweetnacl": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/tweetnacl/-/tweetnacl-1.0.3.tgz", + "integrity": "sha512-6rt+RN7aOi1nGMyC4Xa5DdYiukl2UWCbcJft7YhxReBGQD7OAM8Pbxw6YMo4r2diNEA8FEmu32YOn9rhaiE5yw==" + }, + "node_modules/tweetnacl-util": { + "version": "0.15.1", + "resolved": "https://registry.npmjs.org/tweetnacl-util/-/tweetnacl-util-0.15.1.tgz", + "integrity": "sha512-RKJBIj8lySrShN4w6i/BonWp2Z/uxwC3h4y7xsRrpP59ZboCd0GpEVsOnMDYLMmKBpYhb5TgHzZXy7wTfYFBRw==" + }, "node_modules/type-check": { "version": "0.4.0", "resolved": "https://registry.npmjs.org/type-check/-/type-check-0.4.0.tgz", diff --git a/package.json b/package.json index 3459b46..4530b41 100644 --- a/package.json +++ b/package.json @@ -33,7 +33,8 @@ "dotenv": "^16.3.1", "fastify": "^4.23.2", "fastify-i18n": "^1.1.1", - "fastify-plugin": "^4.5.1" + "fastify-plugin": "^4.5.1", + "pusher": "^5.1.3" }, "devDependencies": { "@swc/core": "^1.3.85", diff --git a/src/modules/item/folder/folder.controller.ts b/src/modules/item/folder/folder.controller.ts index 1a51753..923c50b 100644 --- a/src/modules/item/folder/folder.controller.ts +++ b/src/modules/item/folder/folder.controller.ts @@ -2,6 +2,7 @@ import { FastifyReply, FastifyRequest } from 'fastify'; import { ReadInput, EditInput, AddInput, DeleteInput } from './folder.schema'; import FolderService from './folder.service'; import AccessService from '../sharing/access.service'; +import Pusher from 'pusher'; export default class FolderController { private folderService: FolderService; @@ -92,6 +93,22 @@ export default class FolderController { parentId: request.body.parentId ?? null, }); + const pusher = new Pusher({ + appId: '1684269', + key: '3a4575271634ad5a09ef', + secret: '486036ded3c32d02bac3', + cluster: 'eu', + useTLS: true, + }); + + const channelName = request.body.parentId + ? `browser-folder-${request.body.parentId}` + : `browser-root-${request.user.sub}`; + + pusher.trigger(channelName, 'update', { + message: 'hello world', + }); + return reply.code(200).send(folder); } catch (e) { /* istanbul ignore next */ diff --git a/src/plugins/config.ts b/src/plugins/config.ts index ec6ed9c..36f475e 100644 --- a/src/plugins/config.ts +++ b/src/plugins/config.ts @@ -23,6 +23,10 @@ declare module 'fastify' { REDIS_URL: string; NODE_ENV: NODE_ENV; ALLOWED_ORIGINS: string[]; + PUSHER_APP_ID: string; + PUSHER_APP_KEY: string; + PUSHER_APP_SECRET: string; + PUSHER_APP_CLUSTER: string; }; } } @@ -43,6 +47,10 @@ export default fastifyPlugin( 'DATABASE_URL_NON_POOLING', 'REDIS_URL', 'BLOB_READ_WRITE_TOKEN', + 'PUSHER_APP_ID', + 'PUSHER_APP_KEY', + 'PUSHER_APP_SECRET', + 'PUSHER_APP_CLUSTER', ], properties: { SECRET: { @@ -83,6 +91,18 @@ export default fastifyPlugin( separator: ',', default: 'http://localhost:4321', }, + PUSHER_APP_ID: { + type: 'string', + }, + PUSHER_APP_KEY: { + type: 'string', + }, + PUSHER_APP_SECRET: { + type: 'string', + }, + PUSHER_APP_CLUSTER: { + type: 'string', + }, }, };