Skip to content

Commit

Permalink
add chat related api
Browse files Browse the repository at this point in the history
  • Loading branch information
feruzm committed Jan 10, 2024
1 parent 698e599 commit aedfc71
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
26 changes: 25 additions & 1 deletion src/server/handlers/private-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -464,7 +464,7 @@ export const activities = async (req: express.Request, res: express.Response) =>
if (ty === 10) {
const vip = req.headers['x-real-ip'] || req.connection.remoteAddress || req.headers['x-forwarded-for'] || '';
let identifier = `${vip}`;

let rec;
try {
rec = cache.get(identifier);
Expand Down Expand Up @@ -577,3 +577,27 @@ export const purchaseOrder = async (req: express.Request, res: express.Response)
const data = {platform, product, receipt, user};
pipe(apiRequest(`purchase-order`, "POST", {}, data), res);
};

export const chats = async (req: express.Request, res: express.Response) => {
const username = await validateCode(req, res);
if (!username) return;
pipe(apiRequest(`chats/${username}`, "GET"), res);
}

export const chatsAdd = async (req: express.Request, res: express.Response) => {
const username = await validateCode(req, res);
if (!username) return;
const {key, pubkey, iv, meta} = req.body;
const data = {username, key, pubkey, iv, meta};
pipe(apiRequest(`chats`, "POST", {}, data), res);
}

export const chatsUpdate = async (req: express.Request, res: express.Response) => {
const username = await validateCode(req, res);
if (!username) return;
const {id, key, pubkey, iv, meta} = req.body;
const data = {key, pubkey, iv, meta};
pipe(apiRequest(`chats/${username}/${id}`, "PUT", {}, data), res);
}


6 changes: 5 additions & 1 deletion src/server/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -107,12 +107,16 @@ server
.post("^/private-api/get-game$", privateApi.gameGet)
.post("^/private-api/post-game$", privateApi.gamePost)
.post("^/private-api/purchase-order$", privateApi.purchaseOrder)
.post("^/private-api/chats$", privateApi.chats)
.post("^/private-api/chats-add$", privateApi.chatsAdd)
.post("^/private-api/chats-update$", privateApi.chatsUpdate)


// Health check script for docker swarm
.get("^/healthcheck.json$", healthCheck)

// For all others paths
.get("*", fallbackHandler);


export default server;

0 comments on commit aedfc71

Please sign in to comment.