This commit is contained in:
2026-03-05 19:14:23 +03:00
parent 0cf6865b0d
commit b7bbef47eb
7 changed files with 29 additions and 23 deletions

View File

@@ -14,6 +14,7 @@
"@types/bcrypt": "^6.0.0",
"@types/bun": "latest",
"prettier": "3.8.1",
"ts-proto": "^2.11.4",
},
"peerDependencies": {
"typescript": "^5",
@@ -21,6 +22,8 @@
},
},
"packages": {
"@bufbuild/protobuf": ["@bufbuild/protobuf@2.11.0", "", {}, "sha512-sBXGT13cpmPR5BMgHE6UEEfEaShh5Ror6rfN3yEK5si7QVrtZg8LEPQb0VVhiLRUslD2yLnXtnRzG035J/mZXQ=="],
"@grpc/grpc-js": ["@grpc/grpc-js@1.14.3", "", { "dependencies": { "@grpc/proto-loader": "^0.8.0", "@js-sdsl/ordered-map": "^4.4.2" } }, "sha512-Iq8QQQ/7X3Sac15oB6p0FmUg/klxQvXLeileoqrTRGJYLV+/9tubbr9ipz0GKHjmXVsgFPo/+W+2cA8eNcR+XA=="],
"@grpc/proto-loader": ["@grpc/proto-loader@0.8.0", "", { "dependencies": { "lodash.camelcase": "^4.3.0", "long": "^5.0.0", "protobufjs": "^7.5.3", "yargs": "^17.7.2" }, "bin": { "proto-loader-gen-types": "build/bin/proto-loader-gen-types.js" } }, "sha512-rc1hOQtjIWGxcxpb9aHAfLpIctjEnsDehj0DAiVfBlmT84uvR0uUtN2hEi/ecvWVjXUGf5qPF4qEgiLOx1YIMQ=="],
@@ -61,12 +64,18 @@
"bun-types": ["bun-types@1.3.8", "", { "dependencies": { "@types/node": "*" } }, "sha512-fL99nxdOWvV4LqjmC+8Q9kW3M4QTtTR1eePs94v5ctGqU8OeceWrSUaRw3JYb7tU3FkMIAjkueehrHPPPGKi5Q=="],
"case-anything": ["case-anything@2.1.13", "", {}, "sha512-zlOQ80VrQ2Ue+ymH5OuM/DlDq64mEm+B9UTdHULv5osUMD6HalNTblf2b1u/m6QecjsnOkBpqVZ+XPwIVsy7Ng=="],
"cliui": ["cliui@8.0.1", "", { "dependencies": { "string-width": "^4.2.0", "strip-ansi": "^6.0.1", "wrap-ansi": "^7.0.0" } }, "sha512-BSeNnyus75C4//NQ9gQt1/csTXyo/8Sb+afLAkzAptFuMsod9HFokGNudZpi/oQV73hnVK+sR+5PVRMd+Dr7YQ=="],
"color-convert": ["color-convert@2.0.1", "", { "dependencies": { "color-name": "~1.1.4" } }, "sha512-RRECPsj7iu/xb5oKYcsFHSppFNnsj/52OVTRKb4zP5onXwVF3zVmmToNcOfGC+CRDpfK/U584fMg38ZHCaElKQ=="],
"color-name": ["color-name@1.1.4", "", {}, "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA=="],
"detect-libc": ["detect-libc@1.0.3", "", { "bin": { "detect-libc": "./bin/detect-libc.js" } }, "sha512-pGjwhsmsp4kL2RTz08wcOlGN83otlqHeD/Z5T8GXZB+/YcpQ/dgo+lbU8ZsGxV0HIvqqxo9l7mqYwyYMD9bKDg=="],
"dprint-node": ["dprint-node@1.0.8", "", { "dependencies": { "detect-libc": "^1.0.3" } }, "sha512-iVKnUtYfGrYcW1ZAlfR/F59cUVL8QIhWoBJoSjkkdua/dkWIgjZfiLMeTjiB06X0ZLkQ0M2C1VbUj/CxkIf1zg=="],
"emoji-regex": ["emoji-regex@8.0.0", "", {}, "sha512-MSjYzcWNOA0ewAHpz0MxpYFvwg6yjy1NG3xteoqz644VCo/RPgnr1/GGt+ic3iJTzQ8Eu3TdM14SawnVUmGE6A=="],
"escalade": ["escalade@3.2.0", "", {}, "sha512-WUj2qlxaQtO4g6Pq5c29GTcWGDyd8itL8zTlipgECz3JesAiiOKotd8JU6otB3PACgG6xkJUyVhboMS+bje/jA=="],
@@ -95,6 +104,12 @@
"strip-ansi": ["strip-ansi@6.0.1", "", { "dependencies": { "ansi-regex": "^5.0.1" } }, "sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A=="],
"ts-poet": ["ts-poet@6.12.0", "", { "dependencies": { "dprint-node": "^1.0.8" } }, "sha512-xo+iRNMWqyvXpFTaOAvLPA5QAWO6TZrSUs5s4Odaya3epqofBu/fMLHEWl8jPmjhA0s9sgj9sNvF1BmaQlmQkA=="],
"ts-proto": ["ts-proto@2.11.4", "", { "dependencies": { "@bufbuild/protobuf": "^2.10.2", "case-anything": "^2.1.13", "ts-poet": "^6.12.0", "ts-proto-descriptors": "2.1.0" }, "bin": { "protoc-gen-ts_proto": "protoc-gen-ts_proto" } }, "sha512-LGf1llYT/YsZRIzz3nzBei5mR8Sq0xmrL0cI36Pdiuok2V4PHiDuXQGP+D9i3NzChuwURPo8KAmGV1HLH0xHyw=="],
"ts-proto-descriptors": ["ts-proto-descriptors@2.1.0", "", { "dependencies": { "@bufbuild/protobuf": "^2.0.0" } }, "sha512-S5EZYEQ6L9KLFfjSRpZWDIXDV/W7tAj8uW7pLsihIxyr62EAVSiKuVPwE8iWnr849Bqa53enex1jhDUcpgquzA=="],
"typescript": ["typescript@5.9.3", "", { "bin": { "tsc": "bin/tsc", "tsserver": "bin/tsserver" } }, "sha512-jl1vZzPDinLr9eUt3J/t7V6FgNEw9QjvBPdysz9KfQDD41fQrC2Y4vKQdiaUpFT4bXlb1RHhLpp8wtm6M5TgSw=="],
"undici-types": ["undici-types@7.16.0", "", {}, "sha512-Zz+aZWSj8LE6zoxD+xrjh4VfkIG8Ya6LvYkZqtUQGJPZjYl53ypCaUwWqo7eI0x66KBGeRo+mlBEkMSeSZ38Nw=="],

View File

@@ -4,12 +4,15 @@
"type": "module",
"private": true,
"scripts": {
"dev": "bun --watch ./src/index.ts"
"dev": "bun --watch ./src/index.ts",
"proto": "protoc --plugin=node_modules/.bin/protoc-gen-ts_proto --ts_proto_opt=esModuleInterop=true --ts_proto_out=./src/grpc/types -I ./proto/ ./proto/*.proto",
"test": "protoc --plugin=node_modules/.bin/protoc-gen-ts_proto --ts_proto_opt=esModuleInterop=true --ts_proto_out=./src/grpc/types -I ./proto/ ./proto/*.proto"
},
"devDependencies": {
"@types/bcrypt": "^6.0.0",
"@types/bun": "latest",
"prettier": "3.8.1"
"prettier": "3.8.1",
"ts-proto": "^2.11.4"
},
"peerDependencies": {
"typescript": "^5"

View File

@@ -153,6 +153,7 @@ message Chat {
int32 type_id = 2;
optional string name = 3;
repeated UserForChatResponse users = 4;
Message message = 5;
}
// Chat end
@@ -162,7 +163,7 @@ message CreateMessageRequest {
uuid: true,
}];
int32 user_id = 3 [(validate.rules).int32.gt = 0];
optional string text = 4 [(validate.rules).string = {
optional string message = 4 [(validate.rules).string = {
ignore_empty: true,
max_len: 200
}];
@@ -189,7 +190,7 @@ message UpdateMessageRequest {
string chat_id = 2 [(validate.rules).string = {
uuid: true,
}];
optional string text = 3 [(validate.rules).string = {
optional string message = 3 [(validate.rules).string = {
ignore_empty: true,
max_len: 200
}];
@@ -233,7 +234,7 @@ message ListMessageResponse {
message Message {
int32 id = 1;
int32 user_id = 2;
optional string text = 3;
optional string message = 3;
optional string image = 4;
optional string video = 5;
optional string file = 6;

View File

@@ -147,7 +147,6 @@ class GrpcClient {
const protoDescriptor = grpc.loadPackageDefinition(packageDefinition)
const messageProto = protoDescriptor.message as any
this.messageClient = new messageProto.MessageService('localhost:8070', grpc.credentials.createInsecure())
// console.log(this.messageClient)
}
// User

View File

@@ -23,25 +23,13 @@ export async function login(req: Request) {
const accessToken = await createAccessToken(user.id, user.email)
const expires = new Date(Date.now() + config.cookieExpiry * 1000)
// const sessionCookie = new Bun.Cookie('token', accessToken.token, {
// path: '/',
// expires: expires,
// maxAge: config.cookieExpiry,
// httpOnly: true,
// secure: true,
// sameSite: 'strict',
// })
return Response.json(
{
accessToken: accessToken.token,
tokenType: 'Bearer',
expires: expires,
},
{
status: HttpStatusCodes.CREATED,
// headers: { 'Set-Cookie': sessionCookie.toString() }
},
{ status: HttpStatusCodes.CREATED },
)
} catch (error) {
console.log({ error })

View File

@@ -23,7 +23,7 @@ const server = Bun.serve({
async open(ws) {
try {
const ipAddr = ws.remoteAddress
// console.log('ipAddr', ipAddr)
console.log('ipAddr', ipAddr)
const user = ws.data
@@ -69,8 +69,8 @@ const server = Bun.serve({
}
if (o.type === 'GET_MESSAGES') {
const messages = await client.listMessage({ user_id: ws.data.userId, chat_id: o.data.chat_id, page: 1 })
server.publish(o.data.chat_id, JSON.stringify({ type: 'MESSAGES', ...messages }))
const messages = await client.listMessage({ user_id: ws.data.userId, chat_id: o.data.chatId, page: 1 })
server.publish(o.data.chatId, JSON.stringify({ type: 'MESSAGES', ...messages }))
}
if (o.type === 'GET_USERS') {

View File

@@ -21,7 +21,7 @@ export type LoginDto = { email: string }
interface ListMessages {
type: 'GET_MESSAGES'
data: {
chat_id: string
chatId: string
}
}