Automated Action 545563e776 Implement comprehensive real-time chat API with NestJS
- 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.
2025-06-21 17:13:05 +00:00

72 lines
1.7 KiB
JavaScript

const cache = new Map()
const fs = require('fs')
const { dirname, resolve } = require('path')
const lstat = path => new Promise((res, rej) =>
fs.lstat(path, (er, st) => er ? rej(er) : res(st)))
const inferOwner = path => {
path = resolve(path)
if (cache.has(path))
return Promise.resolve(cache.get(path))
const statThen = st => {
const { uid, gid } = st
cache.set(path, { uid, gid })
return { uid, gid }
}
const parent = dirname(path)
const parentTrap = parent === path ? null : er => {
return inferOwner(parent).then((owner) => {
cache.set(path, owner)
return owner
})
}
return lstat(path).then(statThen, parentTrap)
}
const inferOwnerSync = path => {
path = resolve(path)
if (cache.has(path))
return cache.get(path)
const parent = dirname(path)
// avoid obscuring call site by re-throwing
// "catch" the error by returning from a finally,
// only if we're not at the root, and the parent call works.
let threw = true
try {
const st = fs.lstatSync(path)
threw = false
const { uid, gid } = st
cache.set(path, { uid, gid })
return { uid, gid }
} finally {
if (threw && parent !== path) {
const owner = inferOwnerSync(parent)
cache.set(path, owner)
return owner // eslint-disable-line no-unsafe-finally
}
}
}
const inflight = new Map()
module.exports = path => {
path = resolve(path)
if (inflight.has(path))
return Promise.resolve(inflight.get(path))
const p = inferOwner(path).then(owner => {
inflight.delete(path)
return owner
})
inflight.set(path, p)
return p
}
module.exports.sync = inferOwnerSync
module.exports.clearCache = () => {
cache.clear()
inflight.clear()
}