Add cache clearing function and invoke on startup
This commit is contained in:
parent
d4b1dffd74
commit
4da4ff98ba
1 changed files with 15 additions and 3 deletions
18
api.js
18
api.js
|
|
@ -15,8 +15,20 @@ if (!fs.existsSync(CACHE_DIR)) {
|
|||
|
||||
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) {
|
||||
const configString = JSON.stringify(config);
|
||||
const normalized = normalizeConfig(config);
|
||||
const configString = JSON.stringify(normalized);
|
||||
return crypto.createHash('sha256').update(configString).digest('hex');
|
||||
}
|
||||
|
||||
|
|
@ -137,7 +149,7 @@ app.get('/generate', async (req, res) => {
|
|||
const config = {
|
||||
displayName: req.query.displayName || "Anonymous",
|
||||
username: req.query.username || "@anonymous",
|
||||
avatarUrl: req.query.avatarUrl || "",
|
||||
avatarUrl: req.query.avatarUrl || null,
|
||||
text: req.query.text || "No text provided",
|
||||
imageUrl: req.query.imageUrl || null,
|
||||
timestamp: timestamp,
|
||||
|
|
@ -172,7 +184,7 @@ app.post('/generate', async (req, res) => {
|
|||
const config = {
|
||||
displayName: req.body.displayName || "Anonymous",
|
||||
username: req.body.username || "@anonymous",
|
||||
avatarUrl: req.body.avatarUrl || "",
|
||||
avatarUrl: req.body.avatarUrl || null,
|
||||
text: req.body.text || "No text provided",
|
||||
imageUrl: req.body.imageUrl || null,
|
||||
timestamp: timestamp,
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue