Spaces:
Running
Running
Update index.js
Browse files
index.js
CHANGED
@@ -107,6 +107,41 @@ app.get('/user/:id/info', async (req, res) => {
|
|
107 |
}
|
108 |
});
|
109 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
110 |
app.listen(PORT, () => {
|
111 |
console.log(`Express server running at http://localhost:${PORT}`);
|
112 |
});
|
|
|
107 |
}
|
108 |
});
|
109 |
|
110 |
+
// GET /group/:id/meta → returns group metadata from MongoDB (names.json)
|
111 |
+
app.get('/group/:id/meta', async (req, res) => {
|
112 |
+
const groupId = req.params.id;
|
113 |
+
if (!groupId) {
|
114 |
+
return res.status(400).json({ status: false, message: 'Group ID required' });
|
115 |
+
}
|
116 |
+
|
117 |
+
const client = new MongoClient(MONGO_URI);
|
118 |
+
try {
|
119 |
+
await client.connect();
|
120 |
+
const db = client.db(DB_NAME);
|
121 |
+
const collection = db.collection(COLLECTION_NAME);
|
122 |
+
|
123 |
+
const doc = await collection.findOne({ filename: 'data/names.json' });
|
124 |
+
if (!doc || !doc.data || !doc.data[groupId]) {
|
125 |
+
return res.status(404).json({ status: false, message: 'Group metadata not found' });
|
126 |
+
}
|
127 |
+
|
128 |
+
const group = doc.data[groupId];
|
129 |
+
return res.json({
|
130 |
+
status: true,
|
131 |
+
groupId,
|
132 |
+
groupName: group.groupName,
|
133 |
+
groupPic: group.groupPic || null,
|
134 |
+
inviteLink: group.inviteLink || null,
|
135 |
+
memberCount: group.memberCount || null,
|
136 |
+
admins: group.admins || []
|
137 |
+
});
|
138 |
+
} catch (err) {
|
139 |
+
return res.status(500).json({ status: false, error: err.message });
|
140 |
+
} finally {
|
141 |
+
await client.close();
|
142 |
+
}
|
143 |
+
});
|
144 |
+
|
145 |
app.listen(PORT, () => {
|
146 |
console.log(`Express server running at http://localhost:${PORT}`);
|
147 |
});
|