dh_ackergaul
2026-06-03 a25433795ec239654db2ef31af6d3f4e84b3b8dc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
/**
 * FurnplanNodeController.js
 */
 
const FurnviewError = require("furncloud-library").Errors.FurnviewError;
const cookieParserUtils = require("client-sessions").util;
 
const authCookieDefine = {
    cookieName: "auth_cookie",
    secret: "86ut6a6is23tijkz5fs51xugzcxcfi4v3kqobrax9wa8pmuu5emnv2pvzg8jgvqx",
    cookie: {
        maxAge: 1000 * 60 * 60 * 24 * 365 * 2, // 1000 milli seconds * 60 seconds * 60 minutes * 24 hours * 365 days * 2 years
        httpOnly: true
    }
};
 
module.exports = {
 
    get: function (req, res) {
        const user = req.user;
        const userId = req.auth_cookie.id;
        const queryParameters = req.query;
 
        FurnplanNodeManager
            .getNode(user, userId, queryParameters)
            .then((data) => {
                res.json(data);
            })
            .catch(FurnviewError.SessionAlreadyExists, (error) => {
                Winston.error("User has already a furnplan session: ", error);
                res.json(422, { error: error.code });
            })
            .catch((error) => {
                Winston.error("Unable to start a furnplan session", error);
                res.json(503, { error: "Service unavailable" });
            });
    },
 
    freeze: function (req, res) {
        const user = req.user;
        const authCookie = req.cookies.auth_cookie || req.auth_cookie.id || "";
        if (!authCookie) {
            res.json(500, { error: "Internal server error!" });
        }
        FurnplanNodeManager
            .freezeNode(user, authCookie)
            .then(function (data) {
                if (data) {
                    let authCookieEncoded = authCookie;
                    if (/([a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}){1}/.test(authCookieEncoded)) {
                        authCookieEncoded = cookieParserUtils.encode(authCookieDefine, authCookieEncoded);
                    }
                    const aToken = Buffer.from(authCookieEncoded).toString("base64");
                    let reverseExtendToken = "";
                    for (let t = aToken.length - 1; t >= 0; t--) {
                        reverseExtendToken = reverseExtendToken + aToken[t] + String.fromCharCode(Math.floor(Math.random() * (90 - 65)) + 65);
                    }
                    data.aToken = reverseExtendToken;
                }
                res.json(data);
            })
            .catch(FurnviewError.SessionAlreadyFrozen, (error) => {
                Winston.error("User has already a furnplan session: ", error);
                res.json(422, { error: error.code });
            })
            .catch(function (error) {
                Winston.error("Unable to start a furnplan session", error);
                res.json(503, { error: "Service unavailable" });
            });
    },
 
    unfreeze: function (req, res) {
        if (!req.query.arToken) {
            res.json(500, { error: "Internal server error!" });
        }
        const user = req.user;
        FurnplanNodeManager
            .unfreezeNode(user, req.query.arToken)
            .then(function (data) {
                res.json(data);
            })
            .catch(FurnviewError.SessionAlreadyFrozen, (error) => {
                Winston.error("User has already a furnplan session: ", error);
                res.json(422, { error: error.code });
            })
            .catch(function (error) {
                Winston.error("Unable to start a furnplan session", error);
                res.json(503, { error: "Service unavailable" });
            });
    },
 
    destroyAll: function (req, res) {
 
    },
 
    destroy: function (req, res) {
 
    }
};