Compare commits

...

2 Commits

Author SHA1 Message Date
Lamp 42566713cf add r18 only 2021-11-25 16:32:42 -08:00
Lamp 9d8d5c078e rewrite readme 2021-11-25 16:12:55 -08:00
2 changed files with 42 additions and 6 deletions

30
README.md Normal file
View File

@ -0,0 +1,30 @@
A simple no-HTML random Hatsune Miku image server: https://random-miku.owo39.me/
Click reload to get a different one. Delete left half of URL to get to source.
Include pornographic results: https://random-miku.owo39.me/?allow_r18
If you're a pervert: https://random-miku.owo39.me/?allow_r18=only
Get different sizes (original, regular, small, or thumb_mini): https://random-miku.owo39.me/?size=thumb_mini
Auto-refresh using HTTP Refresh header: https://random-miku.owo39.me/?auto=3
kek: https://random-miku.owo39.me/?allow_r18&size=thumb_mini&auto=0
See your history: https://random-miku.owo39.me/log
Load image by id without redirect thing: https://random-miku.owo39.me/img/51586149
Load random image without redirect thing: https://random-miku.owo39.me/img/random
## Issues
- Browser back button is not useful
- HTTP Refresh does not save to browser history
## todo
- Proper HTML site that's more user-friendly

View File

@ -11,19 +11,25 @@ app.use(serveFavicon("ミク.png"));
app.use((req,res,next)=>{req.rawQuery = req.url.includes('?') && req.url.substr(req.url.indexOf('?')+1);next();});
var list = require("./list.json");
var list_r18_indices = [], list_safe_indices = [];
for (let i = 0, h = list.length; i < h; i++) if (list[i][2]) list_r18_indices.push(i); else list_safe_indices.push(i);
var ipa_lastload_map = {};
function getRandomId(allow_r18) {
var i = list[Math.floor(Math.random() * list.length)];
if (i[2] && !allow_r18) return getRandomId();
return i[0];
if (allow_r18?.toLowerCase() == "only") {
return list[list_r18_indices[Math.floor(Math.random() * list_r18_indices.length)]][0];
} else if (allow_r18 != null) {
return list[Math.floor(Math.random() * list.length)][0];
} else {
return list[list_safe_indices[Math.floor(Math.random() * list_safe_indices.length)]][0];
}
};
function getRandomUrl(req) {
var s = req?.params.settings ? `/${req?.params.settings}` : '';
var d = getRandomId(req?.query.allow_r18!=null);
var d = getRandomId(req?.query.allow_r18);
return `${s}/https://www.pixiv.net/en/artworks/${d}`;
}
@ -96,7 +102,7 @@ app.get('/', (req, res) => {
// direct random image without redirects
app.get("/img/random", (req, res, next) => {
serveId(getRandomId(req.query.allow_r18!=null), req, res, next);
serveId(getRandomId(req.query.allow_r18), req, res, next);
});
// simple serve id without redirects
@ -106,7 +112,7 @@ app.get("/img/:id", (req, res, next) => {
// plaintext random id for scripts
app.get("/randomid", function (req, res) {
res.type("text/plain").send(getRandomId(req.query.allow_r18!=null));
res.type("text/plain").send(getRandomId(req.query.allow_r18));
});