-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: setup listener on input bucket
- Loading branch information
Showing
4 changed files
with
48 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export async function onFileOnInput(rec: any, pipeline: any) { | ||
console.log('Received file on input', rec); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import * as Minio from 'minio'; | ||
|
||
export async function setupListener( | ||
bucketName: string, | ||
endpoint: URL, | ||
accessKeyId: string, | ||
secretAccessKey: string, | ||
pipeline: any, | ||
onNotification: (r: any, pipeline: any) => Promise<void> | ||
) { | ||
const client = new Minio.Client({ | ||
endPoint: endpoint.hostname, | ||
accessKey: accessKeyId, | ||
secretKey: secretAccessKey, | ||
useSSL: endpoint.protocol === 'https:' | ||
}); | ||
const poller = client.listenBucketNotification(bucketName, '', '.mp4', [ | ||
's3:ObjectCreated:*' | ||
]); | ||
if (!poller) { | ||
console.error('Failed to setup listener for bucket notifications'); | ||
} | ||
console.log('Listening for notifications'); | ||
poller.on('notification', async (record) => { | ||
await onNotification(record, pipeline); | ||
poller.stop(); | ||
}); | ||
} |