From 337edc8bdf8a20bff3deb8410bc6273cd187ceb8 Mon Sep 17 00:00:00 2001 From: Shirou-kun Date: Tue, 12 Nov 2024 00:42:00 +0900 Subject: [PATCH] fx: add user identifier as client ip --- backend/src/entity/note.ts | 3 +++ backend/src/server.ts | 9 ++++++++- protos/notes.proto | 1 + 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/backend/src/entity/note.ts b/backend/src/entity/note.ts index 437d3cbc..a7f87927 100644 --- a/backend/src/entity/note.ts +++ b/backend/src/entity/note.ts @@ -14,4 +14,7 @@ export class Note { @CreateDateColumn({ type: columnTypeTimestamp() }) public createdAt!: Date; + + @Column() + public userIdentifier?: string } diff --git a/backend/src/server.ts b/backend/src/server.ts index 2cab0b53..70b8e0b4 100644 --- a/backend/src/server.ts +++ b/backend/src/server.ts @@ -36,6 +36,9 @@ const NoteService: NoteServiceHandlers = { console.log("create a new note..."); const { audio, transcription } = call.request; console.log(call.getPeer()); + console.log(call.metadata.toJSON()); + + const userIp = call.getPeer().split(":")[0]; if (!transcription) { callback(null, { @@ -49,6 +52,7 @@ const NoteService: NoteServiceHandlers = { DB.getRepository(DBNote) .save({ transcription: transcription, + userIdentifier: userIp, }) .then((newNote) => { callback(null, { @@ -73,6 +77,8 @@ const NoteService: NoteServiceHandlers = { callback: grpc.sendUnaryData ) => { console.log("fetching all notes..."); + console.log(call.getPeer()); + console.log(call.metadata.toJSON()); DB.getRepository(DBNote) .find() .then((allNotes) => @@ -80,7 +86,8 @@ const NoteService: NoteServiceHandlers = { notes: allNotes.map((note) => ({ transcription: note.transcription, id: "" + note.id, - createdAt: note.createdAt.getMilliseconds().toString(), + createdAt: note.createdAt.getTime().toString(), + userIdentifier: note.userIdentifier || "anonymous", })), }) ); diff --git a/protos/notes.proto b/protos/notes.proto index 5572eadb..c3662371 100644 --- a/protos/notes.proto +++ b/protos/notes.proto @@ -13,6 +13,7 @@ message Note { string audio = 2; string transcription = 3; int64 createdAt = 4; + string userIdentifier = 5; } message CreateNoteRequest {