Start simple translation approach
This commit is contained in:
46
index.js
46
index.js
@@ -65,13 +65,21 @@ DB.getDB.then((DB) => {
|
||||
|
||||
// route for Home-Page
|
||||
app.get('/', sessionChecker, async (req, res) => {
|
||||
if (req.userInfo) return res.json({
|
||||
status: "ok",
|
||||
userInfo: req.userInfo,
|
||||
profileInfo: req.profileInfo
|
||||
});
|
||||
// This should not happend, since the sessionChecker should redirect to login
|
||||
res.json({ status: "ok" });
|
||||
try {
|
||||
const userInfo = req.userInfo;
|
||||
if(!userInfo) {
|
||||
// This should not happend, since the sessionChecker should redirect to login
|
||||
return res.status(401).json({ status: "Unauthorized" });
|
||||
}
|
||||
return res.json({
|
||||
status: "ok",
|
||||
userInfo: req.userInfo,
|
||||
profileInfo: req.profileInfo
|
||||
});
|
||||
} catch (error) {
|
||||
console.error("Error processing / path", error);
|
||||
return res.status(500).json({ status: "Internal server error" });
|
||||
}
|
||||
});
|
||||
|
||||
// Check for an invitation for an email
|
||||
@@ -136,12 +144,24 @@ DB.getDB.then((DB) => {
|
||||
|
||||
// This is the endpoint to refresh the push notification token
|
||||
app.post('/token/', sessionChecker, async (req, res) => {
|
||||
const profileid = getProfileId(req);
|
||||
let token = req.body.token
|
||||
DB.setProfileToken(profileid, token);
|
||||
return res.json({
|
||||
status: "ok"
|
||||
});
|
||||
try {
|
||||
const profileid = getProfileId(req);
|
||||
const { token } = req.body;
|
||||
// Validate token presence
|
||||
if (!token) {
|
||||
return res.status(400).json({ status: 'Token is required' });
|
||||
}
|
||||
// Set the token in the database and wait for completion
|
||||
const result = await DB.setProfileToken(profileid, token);
|
||||
// Assuming DB.setProfileToken() could fail, handle it appropriately
|
||||
if (!result) {
|
||||
return res.status(500).json({ status: 'Failed to update token' });
|
||||
}
|
||||
return res.json({ status: 'ok' });
|
||||
} catch (error) {
|
||||
console.error('Error setting profile token:', error);
|
||||
return res.status(500).json({ status: 'Internal server error' });
|
||||
}
|
||||
});
|
||||
|
||||
// Used for webpush notifications
|
||||
|
||||
Reference in New Issue
Block a user