Spaces:
Running
Running
Update index.js
Browse files
index.js
CHANGED
@@ -43,6 +43,44 @@ app.get('/group/:id/users', async (req, res) => {
|
|
43 |
}
|
44 |
});
|
45 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
46 |
// β
NEW: GET /user/:id/info β Get user's global info across all groups
|
47 |
app.get('/user/:id/info', async (req, res) => {
|
48 |
const userId = req.params.id;
|
|
|
43 |
}
|
44 |
});
|
45 |
|
46 |
+
// GET /user/:id/pfp β fetch user PFP info from MongoDB (data/user_pfps.json)
|
47 |
+
app.get('/user/:id/pfp', async (req, res) => {
|
48 |
+
const userId = req.params.id;
|
49 |
+
const filename = 'data/user_pfps.json';
|
50 |
+
|
51 |
+
const client = new MongoClient(MONGO_URI);
|
52 |
+
try {
|
53 |
+
await client.connect();
|
54 |
+
const db = client.db(DB_NAME);
|
55 |
+
const collection = db.collection(COLLECTION_NAME);
|
56 |
+
|
57 |
+
// Find the document for user_pfps
|
58 |
+
const doc = await collection.findOne({ filename });
|
59 |
+
|
60 |
+
if (!doc || !doc.data || !doc.data[userId]) {
|
61 |
+
return res.status(404).json({ status: false, message: 'User PFP not found' });
|
62 |
+
}
|
63 |
+
|
64 |
+
const { shortCode, lastUpdated } = doc.data[userId];
|
65 |
+
|
66 |
+
// Convert shortCode: "00vpom-jpg" β "00vpom.jpg"
|
67 |
+
const catboxUrl = `https://files.catbox.moe/${shortCode.replace(/-(\w+)$/, '.$1')}`;
|
68 |
+
|
69 |
+
return res.json({
|
70 |
+
status: true,
|
71 |
+
userId,
|
72 |
+
shortCode,
|
73 |
+
lastUpdated,
|
74 |
+
catboxUrl
|
75 |
+
});
|
76 |
+
|
77 |
+
} catch (err) {
|
78 |
+
return res.status(500).json({ status: false, error: err.message });
|
79 |
+
} finally {
|
80 |
+
await client.close();
|
81 |
+
}
|
82 |
+
});
|
83 |
+
|
84 |
// β
NEW: GET /user/:id/info β Get user's global info across all groups
|
85 |
app.get('/user/:id/info', async (req, res) => {
|
86 |
const userId = req.params.id;
|