Add cache clearing function and invoke on startup
This commit is contained in:
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,
|
||||
|
||||
Reference in New Issue
Block a user