Compare commits
2 Commits
7fa2724e66
...
d4b1dffd74
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d4b1dffd74 | ||
|
|
084130feb7 |
@@ -28,7 +28,6 @@ curl -X POST https://quotes.imbenji.net/generate \
|
||||
"username": "@geofftech",
|
||||
"avatarUrl": "https://example.com/avatar.jpg",
|
||||
"text": "Does anyone else find it immensely satisfying when you turn a pocket inside out and get rid of the crumbs and fluff stuck in the bottom.",
|
||||
"imageUrl": null,
|
||||
"timestamp": 1499766270
|
||||
}' --output quote.png
|
||||
```
|
||||
|
||||
22
api.js
22
api.js
@@ -44,6 +44,20 @@ function cacheImage(config, imageBuffer) {
|
||||
fs.writeFileSync(cachePath, imageBuffer);
|
||||
}
|
||||
|
||||
function clearCache() {
|
||||
if (!fs.existsSync(CACHE_DIR)) {
|
||||
return;
|
||||
}
|
||||
|
||||
const files = fs.readdirSync(CACHE_DIR);
|
||||
files.forEach(file => {
|
||||
const filePath = path.join(CACHE_DIR, file);
|
||||
fs.unlinkSync(filePath);
|
||||
});
|
||||
|
||||
console.log(`Cleared ${files.length} cached image(s)`);
|
||||
}
|
||||
|
||||
function cleanupOldCache() {
|
||||
const ONE_DAY = 24 * 60 * 60 * 1000; // 24 hours in milliseconds
|
||||
const now = Date.now();
|
||||
@@ -190,17 +204,17 @@ app.get('/health', (req, res) => {
|
||||
res.status(200).json({ status: 'ok' });
|
||||
});
|
||||
|
||||
// Clear all cache on startup
|
||||
clearCache();
|
||||
|
||||
// Run cleanup every hour
|
||||
setInterval(() => {
|
||||
cleanupOldCache();
|
||||
}, 60 * 60 * 1000);
|
||||
|
||||
// Run cleanup on startup
|
||||
cleanupOldCache();
|
||||
|
||||
app.listen(PORT, () => {
|
||||
console.log(`Quote generator API running on http://localhost:${PORT}`);
|
||||
console.log(`GET: http://localhost:${PORT}/generate?text=Hello&displayName=Test&username=@test×tamp=1735574400`);
|
||||
console.log(`POST: http://localhost:${PORT}/generate`);
|
||||
console.log(`Cache cleanup runs every hour, images older than 24h are removed`);
|
||||
console.log(`Cache cleared on startup, cleanup runs every hour`);
|
||||
});
|
||||
|
||||
@@ -197,8 +197,8 @@
|
||||
|
||||
<div class="tweet-text" id="tweetText">omg i brought these watches home because none of them worked but i thought id hang onto them and my dad fixed and polished them all for me 😭 i love him so much</div>
|
||||
|
||||
<div class="tweet-image-container" id="imageContainer">
|
||||
<img src="https://pbs.twimg.com/media/G9Wtk1xWcAA-WMZ?format=jpg&name=large" alt="Image" class="tweet-image" id="tweetImage">
|
||||
<div class="tweet-image-container" id="imageContainer" style="display: none;">
|
||||
<img src="" alt="Image" class="tweet-image" id="tweetImage">
|
||||
</div>
|
||||
|
||||
<div class="tweet-metadata">
|
||||
@@ -254,7 +254,7 @@
|
||||
username: "@katiopolis",
|
||||
avatarUrl: "https://pbs.twimg.com/profile_images/2004569144893554688/KaYjqylC_x96.jpg",
|
||||
text: "omg i brought these watches home because none of them worked but i thought id hang onto them and my dad fixed and polished them all for me 😭 i love him so much",
|
||||
imageUrl: "https://pbs.twimg.com/media/G9Wtk1xWcAA-WMZ?format=jpg&name=large",
|
||||
imageUrl: null,
|
||||
timestamp: "5:58 PM · Dec 29, 2025",
|
||||
viewsCount: "1.1M"
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user