wip
This commit is contained in:
15
bun.lock
15
bun.lock
@@ -14,6 +14,7 @@
|
|||||||
"@types/bcrypt": "^6.0.0",
|
"@types/bcrypt": "^6.0.0",
|
||||||
"@types/bun": "latest",
|
"@types/bun": "latest",
|
||||||
"prettier": "3.8.1",
|
"prettier": "3.8.1",
|
||||||
|
"ts-proto": "^2.11.4",
|
||||||
},
|
},
|
||||||
"peerDependencies": {
|
"peerDependencies": {
|
||||||
"typescript": "^5",
|
"typescript": "^5",
|
||||||
@@ -21,6 +22,8 @@
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
"packages": {
|
"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/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=="],
|
"@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=="],
|
"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=="],
|
"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-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=="],
|
"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=="],
|
"emoji-regex": ["emoji-regex@8.0.0", "", {}, "sha512-MSjYzcWNOA0ewAHpz0MxpYFvwg6yjy1NG3xteoqz644VCo/RPgnr1/GGt+ic3iJTzQ8Eu3TdM14SawnVUmGE6A=="],
|
||||||
|
|
||||||
"escalade": ["escalade@3.2.0", "", {}, "sha512-WUj2qlxaQtO4g6Pq5c29GTcWGDyd8itL8zTlipgECz3JesAiiOKotd8JU6otB3PACgG6xkJUyVhboMS+bje/jA=="],
|
"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=="],
|
"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=="],
|
"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=="],
|
"undici-types": ["undici-types@7.16.0", "", {}, "sha512-Zz+aZWSj8LE6zoxD+xrjh4VfkIG8Ya6LvYkZqtUQGJPZjYl53ypCaUwWqo7eI0x66KBGeRo+mlBEkMSeSZ38Nw=="],
|
||||||
|
|||||||
@@ -4,12 +4,15 @@
|
|||||||
"type": "module",
|
"type": "module",
|
||||||
"private": true,
|
"private": true,
|
||||||
"scripts": {
|
"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": {
|
"devDependencies": {
|
||||||
"@types/bcrypt": "^6.0.0",
|
"@types/bcrypt": "^6.0.0",
|
||||||
"@types/bun": "latest",
|
"@types/bun": "latest",
|
||||||
"prettier": "3.8.1"
|
"prettier": "3.8.1",
|
||||||
|
"ts-proto": "^2.11.4"
|
||||||
},
|
},
|
||||||
"peerDependencies": {
|
"peerDependencies": {
|
||||||
"typescript": "^5"
|
"typescript": "^5"
|
||||||
|
|||||||
@@ -153,6 +153,7 @@ message Chat {
|
|||||||
int32 type_id = 2;
|
int32 type_id = 2;
|
||||||
optional string name = 3;
|
optional string name = 3;
|
||||||
repeated UserForChatResponse users = 4;
|
repeated UserForChatResponse users = 4;
|
||||||
|
Message message = 5;
|
||||||
}
|
}
|
||||||
// Chat end
|
// Chat end
|
||||||
|
|
||||||
@@ -162,7 +163,7 @@ message CreateMessageRequest {
|
|||||||
uuid: true,
|
uuid: true,
|
||||||
}];
|
}];
|
||||||
int32 user_id = 3 [(validate.rules).int32.gt = 0];
|
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,
|
ignore_empty: true,
|
||||||
max_len: 200
|
max_len: 200
|
||||||
}];
|
}];
|
||||||
@@ -189,7 +190,7 @@ message UpdateMessageRequest {
|
|||||||
string chat_id = 2 [(validate.rules).string = {
|
string chat_id = 2 [(validate.rules).string = {
|
||||||
uuid: true,
|
uuid: true,
|
||||||
}];
|
}];
|
||||||
optional string text = 3 [(validate.rules).string = {
|
optional string message = 3 [(validate.rules).string = {
|
||||||
ignore_empty: true,
|
ignore_empty: true,
|
||||||
max_len: 200
|
max_len: 200
|
||||||
}];
|
}];
|
||||||
@@ -233,7 +234,7 @@ message ListMessageResponse {
|
|||||||
message Message {
|
message Message {
|
||||||
int32 id = 1;
|
int32 id = 1;
|
||||||
int32 user_id = 2;
|
int32 user_id = 2;
|
||||||
optional string text = 3;
|
optional string message = 3;
|
||||||
optional string image = 4;
|
optional string image = 4;
|
||||||
optional string video = 5;
|
optional string video = 5;
|
||||||
optional string file = 6;
|
optional string file = 6;
|
||||||
|
|||||||
@@ -147,7 +147,6 @@ class GrpcClient {
|
|||||||
const protoDescriptor = grpc.loadPackageDefinition(packageDefinition)
|
const protoDescriptor = grpc.loadPackageDefinition(packageDefinition)
|
||||||
const messageProto = protoDescriptor.message as any
|
const messageProto = protoDescriptor.message as any
|
||||||
this.messageClient = new messageProto.MessageService('localhost:8070', grpc.credentials.createInsecure())
|
this.messageClient = new messageProto.MessageService('localhost:8070', grpc.credentials.createInsecure())
|
||||||
// console.log(this.messageClient)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// User
|
// User
|
||||||
|
|||||||
@@ -23,25 +23,13 @@ export async function login(req: Request) {
|
|||||||
const accessToken = await createAccessToken(user.id, user.email)
|
const accessToken = await createAccessToken(user.id, user.email)
|
||||||
|
|
||||||
const expires = new Date(Date.now() + config.cookieExpiry * 1000)
|
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(
|
return Response.json(
|
||||||
{
|
{
|
||||||
accessToken: accessToken.token,
|
accessToken: accessToken.token,
|
||||||
tokenType: 'Bearer',
|
tokenType: 'Bearer',
|
||||||
expires: expires,
|
expires: expires,
|
||||||
},
|
},
|
||||||
{
|
{ status: HttpStatusCodes.CREATED },
|
||||||
status: HttpStatusCodes.CREATED,
|
|
||||||
// headers: { 'Set-Cookie': sessionCookie.toString() }
|
|
||||||
},
|
|
||||||
)
|
)
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.log({ error })
|
console.log({ error })
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ const server = Bun.serve({
|
|||||||
async open(ws) {
|
async open(ws) {
|
||||||
try {
|
try {
|
||||||
const ipAddr = ws.remoteAddress
|
const ipAddr = ws.remoteAddress
|
||||||
// console.log('ipAddr', ipAddr)
|
console.log('ipAddr', ipAddr)
|
||||||
|
|
||||||
const user = ws.data
|
const user = ws.data
|
||||||
|
|
||||||
@@ -69,8 +69,8 @@ const server = Bun.serve({
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (o.type === 'GET_MESSAGES') {
|
if (o.type === 'GET_MESSAGES') {
|
||||||
const messages = await client.listMessage({ user_id: ws.data.userId, chat_id: o.data.chat_id, page: 1 })
|
const messages = await client.listMessage({ user_id: ws.data.userId, chat_id: o.data.chatId, page: 1 })
|
||||||
server.publish(o.data.chat_id, JSON.stringify({ type: 'MESSAGES', ...messages }))
|
server.publish(o.data.chatId, JSON.stringify({ type: 'MESSAGES', ...messages }))
|
||||||
}
|
}
|
||||||
|
|
||||||
if (o.type === 'GET_USERS') {
|
if (o.type === 'GET_USERS') {
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ export type LoginDto = { email: string }
|
|||||||
interface ListMessages {
|
interface ListMessages {
|
||||||
type: 'GET_MESSAGES'
|
type: 'GET_MESSAGES'
|
||||||
data: {
|
data: {
|
||||||
chat_id: string
|
chatId: string
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user