feat: compulsory save guid + db dir cleanup
This commit is contained in:
@@ -48,7 +48,7 @@ const PostLogRequestParamsSchema = z.object({
|
||||
description: "Version of the game that generated this log",
|
||||
example: "1.7.0",
|
||||
}),
|
||||
saveGuid: z.string().uuid().optional().openapi({
|
||||
saveGuid: z.string().uuid().openapi({
|
||||
title: "Save GUID",
|
||||
description:
|
||||
"A unique identifier for a whole game, which can be part of a multi-session game",
|
||||
@@ -185,7 +185,7 @@ export const contract = c.router(
|
||||
{
|
||||
postLog: {
|
||||
method: "POST",
|
||||
path: "/logs/:gameName/:version/:saveGuid?/:sessionGuid",
|
||||
path: "/logs/:gameName/:version/:saveGuid/:sessionGuid",
|
||||
body: PostLogRequestBodySchema,
|
||||
pathParams: PostLogRequestParamsSchema,
|
||||
responses: {
|
||||
|
||||
@@ -1,46 +0,0 @@
|
||||
import { db } from "./init";
|
||||
|
||||
export async function addEntry(
|
||||
saveGuid: string,
|
||||
sessionGuid: string,
|
||||
gameName: string,
|
||||
version: string,
|
||||
message: string,
|
||||
metadata: [string, string][]
|
||||
) {
|
||||
await db.transaction().execute(async (trx) => {
|
||||
// upsert the session info
|
||||
await trx
|
||||
.insertInto("session_info")
|
||||
.ignore()
|
||||
.values({
|
||||
id: sessionGuid,
|
||||
game_name: gameName,
|
||||
save_id: saveGuid,
|
||||
version,
|
||||
})
|
||||
.execute();
|
||||
// add the main log line
|
||||
const insertResult = await trx
|
||||
.insertInto("log_entries")
|
||||
.values({
|
||||
session_info_id: sessionGuid,
|
||||
message: message,
|
||||
timestamp: new Date(),
|
||||
})
|
||||
.executeTakeFirstOrThrow();
|
||||
// add all the metadata
|
||||
if (metadata.length > 0) {
|
||||
await trx
|
||||
.insertInto("log_metadata")
|
||||
.values(
|
||||
metadata.map(([key, value]) => ({
|
||||
log_entry_id: Number(insertResult.insertId),
|
||||
key,
|
||||
value,
|
||||
}))
|
||||
)
|
||||
.execute();
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -1 +1,3 @@
|
||||
export { addEntry } from "./add-entry";
|
||||
export { postLog } from "./post-log";
|
||||
export { getSession } from "./get-session";
|
||||
export { getSessions } from "./get-sessions";
|
||||
|
||||
@@ -5,7 +5,7 @@ import { db } from "./init";
|
||||
export async function postLog(
|
||||
gameName: string,
|
||||
version: string,
|
||||
saveGuid: string | undefined,
|
||||
saveGuid: string,
|
||||
sessionGuid: string,
|
||||
message: string,
|
||||
metadata: SingleMetadata[]
|
||||
@@ -27,7 +27,7 @@ export async function postLog(
|
||||
.values({
|
||||
id: sessionGuid,
|
||||
game_name: gameName,
|
||||
save_id: saveGuid || "",
|
||||
save_id: saveGuid,
|
||||
version,
|
||||
})
|
||||
.execute();
|
||||
|
||||
@@ -1,11 +1,9 @@
|
||||
import { createExpressEndpoints, initServer } from "@ts-rest/express";
|
||||
import type { Express } from "express";
|
||||
import { contract } from "../common/contract";
|
||||
import { getSessions } from "./db/get-sessions";
|
||||
import { getSession } from "./db/get-session";
|
||||
import { postLog } from "./db/post-log";
|
||||
import { HttpError } from "./http-error";
|
||||
import { OpenAPIObject } from "openapi3-ts/oas31";
|
||||
import { getSession, getSessions, postLog } from "./db";
|
||||
|
||||
export function installRouter(app: Express, openAPIObject: OpenAPIObject) {
|
||||
const s = initServer();
|
||||
|
||||
Reference in New Issue
Block a user