2024-01-20 22:14:18 -06:00
const express = require ( 'express' ) ,
path = require ( "path" ) ,
fs = require ( "fs" )
2024-01-19 18:39:24 -06:00
const PORT = process . env . PORT || 8080
var app = express ( )
2024-01-20 22:14:18 -06:00
function randomFileInDir ( directory ) {
var dir = fs . readdirSync ( directory )
return path . join ( directory , dir [ Math . floor ( Math . random ( ) * dir . length ) ] )
}
2024-01-19 18:44:51 -06:00
app . get ( "/" , ( req , res ) => {
res . send ( {
info : "Welcome to the API! It's still a work in process, so there's not much here yet. I don't really know how to do APIs yet so expect it to suck if I add anything." ,
documentation : "https://codeberg.org/Bingus_Violet/api.violets-purgatory.dev" ,
current _commands : {
"/v1/pfp" : {
description : "Generates a random PFP. For use on the main page & with UserPFP on Discord."
}
}
} )
} )
2024-01-19 18:39:24 -06:00
2024-01-20 22:14:18 -06:00
app . get ( "/v1/pfp" , ( req , res ) => {
res . sendFile ( randomFileInDir ( path . join ( _ _dirname , 'pfps' ) ) )
} )
2024-01-19 18:39:24 -06:00
app . listen ( PORT , ( ) => {
console . log ( "API is now listening on port 8080!" )
} )