Skip to content
Snippets Groups Projects
Commit 89a16ce2 authored by Paolo.Brasolin's avatar Paolo.Brasolin
Browse files

feat: get images at random from db

parent 22f23b40
No related branches found
No related tags found
No related merge requests found
......@@ -3,7 +3,7 @@ import knex from "knex";
export const connection = knex({
client: "sqlite3", // or 'better-sqlite3'
connection: {
filename: "./mydb.sqlite",
filename: "./dev.sqlite3",
// filename: ":memory:",
},
});
import fastify from "fastify";
import fastifyCors from "fastify-cors";
import { connection } from "./db";
const server = fastify({
logger: false,
......@@ -37,11 +38,15 @@ server.route({
},
},
},
handler: function (request, reply) {
handler: async function (request, reply) {
// TODO: skip images already used in current game
const image = await connection
.table("images")
.orderByRaw("RANDOM()")
.first();
reply.send({
id: 0,
image:
"iVBORw0KGgoAAAANSUhEUgAAAAgAAAAICAIAAABLbSncAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAAFiUAABYlAUlSJPAAAAA3SURBVBhXYyAXeHh43AeDhIQEqBAEAIX+g8H379+hQhAAlwACqBAEVFRUQESnT58OFSIRMDAAABZDJ2qjC6hLAAAAAElFTkSuQmCC",
id: image.id,
image: image.image,
});
},
});
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment