Skip to content

Commit

Permalink
#28 - POC for Pusher updates on changes
Browse files Browse the repository at this point in the history
  • Loading branch information
kristianbinau committed Oct 11, 2023
1 parent 3a6b0c2 commit df59f40
Show file tree
Hide file tree
Showing 5 changed files with 92 additions and 3 deletions.
8 changes: 7 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -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
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"
47 changes: 46 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
17 changes: 17 additions & 0 deletions src/modules/item/folder/folder.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 */
Expand Down
20 changes: 20 additions & 0 deletions src/plugins/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
}
}
Expand All @@ -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: {
Expand Down Expand Up @@ -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',
},
},
};

Expand Down

0 comments on commit df59f40

Please sign in to comment.