Untitled

mail@pastecode.io avatar
unknown
plain_text
7 months ago
2.3 kB
1
Indexable
Never
 app.post('/api/v1/settings', uploadForm.none(), verifyApiKey, async (req, res, next) => {
        try {
            const platform = req.body.platform;
            const publicIP =
                req.headers['cf-connecting-ip'] ||
                req.headers['x-real-ip'] ||
                req.headers['x-forwarded-for'] ||
                req.socket.remoteAddress ||
                '';

            const data = await GetAllSettings();

            if (!platform) {
                // No platform provided, return all settings data
                res.json({
                    status: true,
                    ip: publicIP,
                    data: data
                });
            } else if (platform.toLowerCase() === 'ios') {
                // Platform is ios, exclude android_settings
                const settingData = Exclude(data, ['android_settings']);

                const iosSettings = { settings: settingData.ios_settings, ...settingData };
                delete iosSettings.ios_settings;

                res.json({
                    status: true,
                    ip: publicIP,
                    message: 'Settings fetched successfully for Ios',
                    data: iosSettings
                });
            } else if (platform.toLowerCase() === 'android') {
                // Platform is android, exclude ios_settings
                const settingData = Exclude(data, ['ios_settings']);

                const androidSettings = { settings: settingData.android_settings, ...settingData };
                delete androidSettings.android_settings;

                res.json({
                    status: true,
                    ip: publicIP,
                    message: 'Settings fetched successfully for Android',
                    data: androidSettings
                });
            } else {
                // Invalid platform provided
                res.json({
                    status: false,
                    ip: publicIP,
                    message: 'Invalid platform key',
                    data: null
                });
            }
        } catch (error) {
            res.status(500).json({ status: false, message: 'Something went wrong or invalid request, Try again', error: error });
        }
    });