mirror of
https://github.com/Crazyco-xyz/48hr.email.git
synced 2026-01-09 11:19:36 +01:00
[Chore]: Update API code location and fix routes
This commit is contained in:
parent
8401310062
commit
80bea65c2f
20 changed files with 21 additions and 9 deletions
|
|
@ -7,9 +7,19 @@ function responseFormatter(req, res, next) {
|
|||
* @param {*} data - Data to return
|
||||
* @param {number} statusCode - HTTP status code (default: 200)
|
||||
*/
|
||||
// Determine mode: 'normal', 'debug', or 'ux-debug'
|
||||
let mode = 'normal';
|
||||
const config = req.app && req.app.get ? req.app.get('config') : null;
|
||||
if (config && config.uxDebugMode) {
|
||||
mode = 'ux-debug';
|
||||
} else if (process.env.DEBUG && process.env.DEBUG.includes('48hr-email')) {
|
||||
mode = 'debug';
|
||||
}
|
||||
|
||||
res.apiSuccess = function(data = null, statusCode = 200, templateContext = null) {
|
||||
const response = {
|
||||
success: true,
|
||||
mode: mode,
|
||||
data: data
|
||||
};
|
||||
if (templateContext) response.templateContext = templateContext;
|
||||
|
|
@ -25,6 +35,7 @@ function responseFormatter(req, res, next) {
|
|||
res.apiError = function(message, code = 'ERROR', statusCode = 400, templateContext = null) {
|
||||
const response = {
|
||||
success: false,
|
||||
mode: mode,
|
||||
error: message,
|
||||
code: code
|
||||
};
|
||||
|
|
@ -44,6 +55,7 @@ function responseFormatter(req, res, next) {
|
|||
}
|
||||
const response = {
|
||||
success: true,
|
||||
mode: mode,
|
||||
data: items,
|
||||
count: items.length,
|
||||
total: total !== null ? total : items.length
|
||||
|
|
@ -55,4 +55,4 @@ function createApiRouter(dependencies) {
|
|||
return router
|
||||
}
|
||||
|
||||
module.exports = createApiRouter
|
||||
module.exports = createApiRouter
|
||||
|
|
@ -45,8 +45,8 @@ function createAccountRouter(dependencies) {
|
|||
try {
|
||||
const userId = req.user.id
|
||||
|
||||
// Get user stats
|
||||
const stats = userRepository.getUserStats(userId)
|
||||
// Get user stats (pass config.user for mock repo compatibility)
|
||||
const stats = userRepository.getUserStats(userId, config.user)
|
||||
|
||||
// Get verified emails
|
||||
const verifiedEmails = userRepository.getForwardEmails(userId)
|
||||
|
|
@ -59,8 +59,7 @@ function createConfigRouter(dependencies) {
|
|||
res.apiSuccess({
|
||||
authentication: config.user.authEnabled,
|
||||
forwarding: config.smtp.enabled,
|
||||
statistics: config.http.statisticsEnabled,
|
||||
inboxLocking: config.user.authEnabled
|
||||
statistics: config.http.features.statistics
|
||||
})
|
||||
})
|
||||
|
||||
|
|
@ -13,9 +13,10 @@ const createAuthenticator = require('../middleware/authenticator')
|
|||
function createLocksRouter(dependencies) {
|
||||
const { inboxLock, userRepository, apiTokenRepository, config } = dependencies
|
||||
|
||||
// Inbox locking is always enabled if authentication is enabled
|
||||
if (!inboxLock || !config.user.authEnabled) {
|
||||
router.all('*', (req, res) => {
|
||||
res.apiError('Inbox locking is disabled', 'FEATURE_DISABLED', 503)
|
||||
res.apiError('Authentication is required for inbox locking', 'AUTH_REQUIRED', 401)
|
||||
})
|
||||
return router
|
||||
}
|
||||
|
|
@ -11,7 +11,7 @@ function createStatsRouter(dependencies) {
|
|||
// Ensure router is declared before any usage
|
||||
const { statisticsStore, mailProcessingService, imapService, config } = dependencies
|
||||
|
||||
if (!config.http.statisticsEnabled) {
|
||||
if (!config.http.features.statistics) {
|
||||
router.all('*', (req, res) => {
|
||||
res.apiError('Statistics are disabled', 'FEATURE_DISABLED', 503)
|
||||
})
|
||||
|
|
@ -11,7 +11,7 @@ const helmet = require('helmet')
|
|||
const socketio = require('socket.io')
|
||||
|
||||
const config = require('../../application/config')
|
||||
const createApiRouter = require('../../api/router')
|
||||
const createApiRouter = require('./api/router')
|
||||
const inboxRouter = require('./routes/inbox')
|
||||
const loginRouter = require('./routes/login')
|
||||
const errorRouter = require('./routes/error')
|
||||
|
|
@ -231,4 +231,4 @@ server.on('listening', () => {
|
|||
server.emit('ready')
|
||||
})
|
||||
|
||||
module.exports = { app, io, server }
|
||||
module.exports = { app, io, server }
|
||||
Loading…
Add table
Reference in a new issue