add booru image search
This commit is contained in:
parent
2a98b55b8d
commit
f8051314cc
17 changed files with 1161 additions and 75 deletions
43
booru-api/index.js
Normal file
43
booru-api/index.js
Normal file
|
@ -0,0 +1,43 @@
|
|||
const express = require('express');
|
||||
const Booru = require('booru');
|
||||
|
||||
const app = express();
|
||||
|
||||
app.use(express.json());
|
||||
|
||||
app.post('/booru', (req, res) => {
|
||||
|
||||
const { booru, tags, random, limit } = req.body;
|
||||
|
||||
// Validate input
|
||||
if (!booru || typeof booru !== 'string') {
|
||||
return res.status(400).json({ error: 'Invalid or missing "booru"' });
|
||||
}
|
||||
|
||||
if (!tags || !Array.isArray(tags)) {
|
||||
return res.status(400).json({ error: 'Invalid or missing "tags"' });
|
||||
}
|
||||
|
||||
if (!limit || typeof limit !== 'number') {
|
||||
return res.status(400).json({ error: 'Invalid or missing "limit"' });
|
||||
}
|
||||
|
||||
if (typeof random !== 'boolean') {
|
||||
return res.status(400).json({ error: 'Invalid or missing "random"' });
|
||||
}
|
||||
|
||||
Booru.search(booru, tags, { limit: limit, random: random })
|
||||
.then(posts => {
|
||||
res.json(posts);
|
||||
}).catch(function(rej) {
|
||||
console.log(rej);
|
||||
res.status(400).json({ error: 'Booru returned an error' });
|
||||
});
|
||||
});
|
||||
|
||||
// Start the server
|
||||
const PORT = 3456;
|
||||
const HOST = '0.0.0.0'
|
||||
app.listen(PORT, HOST, () => {
|
||||
console.log(`Server is running on http://${HOST}:${PORT}`);
|
||||
});
|
Loading…
Add table
Add a link
Reference in a new issue