Add cache clearing function and invoke on startup

This commit is contained in:
ImBenji
2025-12-31 10:53:25 +00:00
parent d4b1dffd74
commit 4da4ff98ba

18
api.js
View File

@@ -15,8 +15,20 @@ if (!fs.existsSync(CACHE_DIR)) {
app.use(express.json()); app.use(express.json());
function normalizeConfig(config) {
// Remove null, undefined, and empty string values
const normalized = {};
for (const [key, value] of Object.entries(config)) {
if (value !== null && value !== undefined && value !== '') {
normalized[key] = value;
}
}
return normalized;
}
function hashConfig(config) { function hashConfig(config) {
const configString = JSON.stringify(config); const normalized = normalizeConfig(config);
const configString = JSON.stringify(normalized);
return crypto.createHash('sha256').update(configString).digest('hex'); return crypto.createHash('sha256').update(configString).digest('hex');
} }
@@ -137,7 +149,7 @@ app.get('/generate', async (req, res) => {
const config = { const config = {
displayName: req.query.displayName || "Anonymous", displayName: req.query.displayName || "Anonymous",
username: req.query.username || "@anonymous", username: req.query.username || "@anonymous",
avatarUrl: req.query.avatarUrl || "", avatarUrl: req.query.avatarUrl || null,
text: req.query.text || "No text provided", text: req.query.text || "No text provided",
imageUrl: req.query.imageUrl || null, imageUrl: req.query.imageUrl || null,
timestamp: timestamp, timestamp: timestamp,
@@ -172,7 +184,7 @@ app.post('/generate', async (req, res) => {
const config = { const config = {
displayName: req.body.displayName || "Anonymous", displayName: req.body.displayName || "Anonymous",
username: req.body.username || "@anonymous", username: req.body.username || "@anonymous",
avatarUrl: req.body.avatarUrl || "", avatarUrl: req.body.avatarUrl || null,
text: req.body.text || "No text provided", text: req.body.text || "No text provided",
imageUrl: req.body.imageUrl || null, imageUrl: req.body.imageUrl || null,
timestamp: timestamp, timestamp: timestamp,