mirror of
https://github.com/Crazyco-xyz/48hr.email.git
synced 2026-01-10 03:29: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 {*} data - Data to return
|
||||||
* @param {number} statusCode - HTTP status code (default: 200)
|
* @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) {
|
res.apiSuccess = function(data = null, statusCode = 200, templateContext = null) {
|
||||||
const response = {
|
const response = {
|
||||||
success: true,
|
success: true,
|
||||||
|
mode: mode,
|
||||||
data: data
|
data: data
|
||||||
};
|
};
|
||||||
if (templateContext) response.templateContext = templateContext;
|
if (templateContext) response.templateContext = templateContext;
|
||||||
|
|
@ -25,6 +35,7 @@ function responseFormatter(req, res, next) {
|
||||||
res.apiError = function(message, code = 'ERROR', statusCode = 400, templateContext = null) {
|
res.apiError = function(message, code = 'ERROR', statusCode = 400, templateContext = null) {
|
||||||
const response = {
|
const response = {
|
||||||
success: false,
|
success: false,
|
||||||
|
mode: mode,
|
||||||
error: message,
|
error: message,
|
||||||
code: code
|
code: code
|
||||||
};
|
};
|
||||||
|
|
@ -44,6 +55,7 @@ function responseFormatter(req, res, next) {
|
||||||
}
|
}
|
||||||
const response = {
|
const response = {
|
||||||
success: true,
|
success: true,
|
||||||
|
mode: mode,
|
||||||
data: items,
|
data: items,
|
||||||
count: items.length,
|
count: items.length,
|
||||||
total: total !== null ? total : items.length
|
total: total !== null ? total : items.length
|
||||||
|
|
@ -45,8 +45,8 @@ function createAccountRouter(dependencies) {
|
||||||
try {
|
try {
|
||||||
const userId = req.user.id
|
const userId = req.user.id
|
||||||
|
|
||||||
// Get user stats
|
// Get user stats (pass config.user for mock repo compatibility)
|
||||||
const stats = userRepository.getUserStats(userId)
|
const stats = userRepository.getUserStats(userId, config.user)
|
||||||
|
|
||||||
// Get verified emails
|
// Get verified emails
|
||||||
const verifiedEmails = userRepository.getForwardEmails(userId)
|
const verifiedEmails = userRepository.getForwardEmails(userId)
|
||||||
|
|
@ -59,8 +59,7 @@ function createConfigRouter(dependencies) {
|
||||||
res.apiSuccess({
|
res.apiSuccess({
|
||||||
authentication: config.user.authEnabled,
|
authentication: config.user.authEnabled,
|
||||||
forwarding: config.smtp.enabled,
|
forwarding: config.smtp.enabled,
|
||||||
statistics: config.http.statisticsEnabled,
|
statistics: config.http.features.statistics
|
||||||
inboxLocking: config.user.authEnabled
|
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
@ -13,9 +13,10 @@ const createAuthenticator = require('../middleware/authenticator')
|
||||||
function createLocksRouter(dependencies) {
|
function createLocksRouter(dependencies) {
|
||||||
const { inboxLock, userRepository, apiTokenRepository, config } = dependencies
|
const { inboxLock, userRepository, apiTokenRepository, config } = dependencies
|
||||||
|
|
||||||
|
// Inbox locking is always enabled if authentication is enabled
|
||||||
if (!inboxLock || !config.user.authEnabled) {
|
if (!inboxLock || !config.user.authEnabled) {
|
||||||
router.all('*', (req, res) => {
|
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
|
return router
|
||||||
}
|
}
|
||||||
|
|
@ -11,7 +11,7 @@ function createStatsRouter(dependencies) {
|
||||||
// Ensure router is declared before any usage
|
// Ensure router is declared before any usage
|
||||||
const { statisticsStore, mailProcessingService, imapService, config } = dependencies
|
const { statisticsStore, mailProcessingService, imapService, config } = dependencies
|
||||||
|
|
||||||
if (!config.http.statisticsEnabled) {
|
if (!config.http.features.statistics) {
|
||||||
router.all('*', (req, res) => {
|
router.all('*', (req, res) => {
|
||||||
res.apiError('Statistics are disabled', 'FEATURE_DISABLED', 503)
|
res.apiError('Statistics are disabled', 'FEATURE_DISABLED', 503)
|
||||||
})
|
})
|
||||||
|
|
@ -11,7 +11,7 @@ const helmet = require('helmet')
|
||||||
const socketio = require('socket.io')
|
const socketio = require('socket.io')
|
||||||
|
|
||||||
const config = require('../../application/config')
|
const config = require('../../application/config')
|
||||||
const createApiRouter = require('../../api/router')
|
const createApiRouter = require('./api/router')
|
||||||
const inboxRouter = require('./routes/inbox')
|
const inboxRouter = require('./routes/inbox')
|
||||||
const loginRouter = require('./routes/login')
|
const loginRouter = require('./routes/login')
|
||||||
const errorRouter = require('./routes/error')
|
const errorRouter = require('./routes/error')
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue