Spaces:
Running
Running
Update index.js
Browse files
index.js
CHANGED
@@ -81,6 +81,43 @@ app.get('/user/:id/pfp', async (req, res) => {
|
|
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;
|
|
|
81 |
}
|
82 |
});
|
83 |
|
84 |
+
app.get('/user/:id/banner', async (req, res) => {
|
85 |
+
const userId = req.params.id;
|
86 |
+
const filename = 'data/user_banners.json';
|
87 |
+
|
88 |
+
const client = new MongoClient(MONGO_URI);
|
89 |
+
try {
|
90 |
+
await client.connect();
|
91 |
+
const db = client.db(DB_NAME);
|
92 |
+
const collection = db.collection(COLLECTION_NAME);
|
93 |
+
|
94 |
+
// Find the document for user_pfps
|
95 |
+
const doc = await collection.findOne({ filename });
|
96 |
+
|
97 |
+
if (!doc || !doc.data || !doc.data[userId]) {
|
98 |
+
return res.status(404).json({ status: false, message: 'User PFP not found' });
|
99 |
+
}
|
100 |
+
|
101 |
+
const { shortCode, lastUpdated } = doc.data[userId];
|
102 |
+
|
103 |
+
// Convert shortCode: "00vpom-jpg" β "00vpom.jpg"
|
104 |
+
const catboxUrl = `https://files.catbox.moe/${shortCode.replace(/-(\w+)$/, '.$1')}`;
|
105 |
+
|
106 |
+
return res.json({
|
107 |
+
status: true,
|
108 |
+
userId,
|
109 |
+
shortCode,
|
110 |
+
lastUpdated,
|
111 |
+
catboxUrl
|
112 |
+
});
|
113 |
+
|
114 |
+
} catch (err) {
|
115 |
+
return res.status(500).json({ status: false, error: err.message });
|
116 |
+
} finally {
|
117 |
+
await client.close();
|
118 |
+
}
|
119 |
+
});
|
120 |
+
|
121 |
// β
NEW: GET /user/:id/info β Get user's global info across all groups
|
122 |
app.get('/user/:id/info', async (req, res) => {
|
123 |
const userId = req.params.id;
|