
- Complete NestJS TypeScript implementation with WebSocket support - Direct messaging (DM) and group chat functionality - End-to-end encryption with AES encryption and key pairs - Media file support (images, videos, audio, documents) up to 100MB - Push notifications with Firebase Cloud Messaging integration - Mention alerts and real-time typing indicators - User authentication with JWT and Passport - SQLite database with TypeORM entities and relationships - Comprehensive API documentation with Swagger/OpenAPI - File upload handling with secure access control - Online/offline status tracking and presence management - Message editing, deletion, and reply functionality - Notification management with automatic cleanup - Health check endpoint for monitoring - CORS configuration for cross-origin requests - Environment-based configuration management - Structured for Flutter SDK integration Features implemented: ✅ Real-time messaging with Socket.IO ✅ User registration and authentication ✅ Direct messages and group chats ✅ Media file uploads and management ✅ End-to-end encryption ✅ Push notifications ✅ Mention alerts ✅ Typing indicators ✅ Message read receipts ✅ Online status tracking ✅ File access control ✅ Comprehensive API documentation Ready for Flutter SDK development and production deployment.
68 lines
1.7 KiB
JavaScript
68 lines
1.7 KiB
JavaScript
const Minipass = require('minipass')
|
|
|
|
class SizeError extends Error {
|
|
constructor (found, expect) {
|
|
super(`Bad data size: expected ${expect} bytes, but got ${found}`)
|
|
this.expect = expect
|
|
this.found = found
|
|
this.code = 'EBADSIZE'
|
|
Error.captureStackTrace(this, this.constructor)
|
|
}
|
|
get name () {
|
|
return 'SizeError'
|
|
}
|
|
}
|
|
|
|
class MinipassSized extends Minipass {
|
|
constructor (options = {}) {
|
|
super(options)
|
|
|
|
if (options.objectMode)
|
|
throw new TypeError(`${
|
|
this.constructor.name
|
|
} streams only work with string and buffer data`)
|
|
|
|
this.found = 0
|
|
this.expect = options.size
|
|
if (typeof this.expect !== 'number' ||
|
|
this.expect > Number.MAX_SAFE_INTEGER ||
|
|
isNaN(this.expect) ||
|
|
this.expect < 0 ||
|
|
!isFinite(this.expect) ||
|
|
this.expect !== Math.floor(this.expect))
|
|
throw new Error('invalid expected size: ' + this.expect)
|
|
}
|
|
|
|
write (chunk, encoding, cb) {
|
|
const buffer = Buffer.isBuffer(chunk) ? chunk
|
|
: typeof chunk === 'string' ?
|
|
Buffer.from(chunk, typeof encoding === 'string' ? encoding : 'utf8')
|
|
: chunk
|
|
|
|
if (!Buffer.isBuffer(buffer)) {
|
|
this.emit('error', new TypeError(`${
|
|
this.constructor.name
|
|
} streams only work with string and buffer data`))
|
|
return false
|
|
}
|
|
|
|
this.found += buffer.length
|
|
if (this.found > this.expect)
|
|
this.emit('error', new SizeError(this.found, this.expect))
|
|
|
|
return super.write(chunk, encoding, cb)
|
|
}
|
|
|
|
emit (ev, ...data) {
|
|
if (ev === 'end') {
|
|
if (this.found !== this.expect)
|
|
this.emit('error', new SizeError(this.found, this.expect))
|
|
}
|
|
return super.emit(ev, ...data)
|
|
}
|
|
}
|
|
|
|
MinipassSized.SizeError = SizeError
|
|
|
|
module.exports = MinipassSized
|