Skip to content

Commit

Permalink
fx: add user identifier as client ip
Browse files Browse the repository at this point in the history
  • Loading branch information
shivanshs9 committed Nov 11, 2024
1 parent 63700c5 commit 337edc8
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
3 changes: 3 additions & 0 deletions backend/src/entity/note.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,7 @@ export class Note {

@CreateDateColumn({ type: columnTypeTimestamp() })
public createdAt!: Date;

@Column()
public userIdentifier?: string
}
9 changes: 8 additions & 1 deletion backend/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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, {
Expand All @@ -49,6 +52,7 @@ const NoteService: NoteServiceHandlers = {
DB.getRepository(DBNote)
.save({
transcription: transcription,
userIdentifier: userIp,
})
.then((newNote) => {
callback(null, {
Expand All @@ -73,14 +77,17 @@ const NoteService: NoteServiceHandlers = {
callback: grpc.sendUnaryData<ListNotesResponse>
) => {
console.log("fetching all notes...");
console.log(call.getPeer());
console.log(call.metadata.toJSON());
DB.getRepository(DBNote)
.find()
.then((allNotes) =>
callback(null, {
notes: allNotes.map((note) => ({
transcription: note.transcription,
id: "" + note.id,
createdAt: note.createdAt.getMilliseconds().toString(),
createdAt: note.createdAt.getTime().toString(),
userIdentifier: note.userIdentifier || "anonymous",
})),
})
);
Expand Down
1 change: 1 addition & 0 deletions protos/notes.proto
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ message Note {
string audio = 2;
string transcription = 3;
int64 createdAt = 4;
string userIdentifier = 5;
}

message CreateNoteRequest {
Expand Down

0 comments on commit 337edc8

Please sign in to comment.