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"; ...@@ -3,7 +3,7 @@ import knex from "knex";
export const connection = knex({ export const connection = knex({
client: "sqlite3", // or 'better-sqlite3' client: "sqlite3", // or 'better-sqlite3'
connection: { connection: {
filename: "./mydb.sqlite", filename: "./dev.sqlite3",
// filename: ":memory:", // filename: ":memory:",
}, },
}); });
import fastify from "fastify"; import fastify from "fastify";
import fastifyCors from "fastify-cors"; import fastifyCors from "fastify-cors";
import { connection } from "./db";
const server = fastify({ const server = fastify({
logger: false, logger: false,
...@@ -37,11 +38,15 @@ server.route({ ...@@ -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({ reply.send({
id: 0, id: image.id,
image: image: image.image,
"iVBORw0KGgoAAAANSUhEUgAAAAgAAAAICAIAAABLbSncAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAAFiUAABYlAUlSJPAAAAA3SURBVBhXYyAXeHh43AeDhIQEqBAEAIX+g8H379+hQhAAlwACqBAEVFRUQESnT58OFSIRMDAAABZDJ2qjC6hLAAAAAElFTkSuQmCC",
}); });
}, },
}); });
......
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