Skip to content

Commit

Permalink
Refactor server domain variable names to use consistent casing
Browse files Browse the repository at this point in the history
  • Loading branch information
tako0614 committed Jun 16, 2024
1 parent b8551c0 commit e9d17de
Show file tree
Hide file tree
Showing 14 changed files with 36 additions and 76 deletions.
23 changes: 13 additions & 10 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
hostname=
username=
db=
password=
MONGO_URL=mongodb://localhost:27017/takos
recaptcha_site_key=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
rechapcha_seecret_key=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
recaptcha_site_key=6LewIZspAAAAAEwZ8YaDMe8dxxs6F_N8KtSsukQY
rechapcha_seecret_key=6LewIZspAAAAAGJE3RjUqM4dn8jgBCx_zdcXwkwx
smtp_host=smtp.gmail.com
smtp_port=587
smtp_username=example@gmail.com
smtp_password=xxxxxxxxxxxxxxx
origin="http://example.com,https://takos.jp,http://localhost:8000"
serverDomain=localhost:8000
REDIS_URL=redis://localhost:6379
PRIORITY_PROTOCOL=http
REDIS_CH=takos
MAX_MESSAGE_LENGTH=100
smtp_username=
smtp_password=
origin="http://localhost:8000,https://takos.jp,"
REACT_APP_RECAPTCHA_KEY=
mailDomain=http://localhost:8000
friendOrigin=http://localhost:8000?key=
REDIS_URL=redis://localhost:6379
5 changes: 0 additions & 5 deletions routes/_middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,9 @@ import csrfToken from "../models/csrftoken.ts"
import users from "../models/users.ts"
import sessionID from "../models/sessionid.ts"
import { load } from "$std/dotenv/mod.ts"
const env = await load()

export async function handler(req: Request, ctx: MiddlewareHandlerContext) {
const cookies = getCookies(req.headers)
const sessionid = cookies.sessionid
ctx.state.settings = {
maxMessageLength: env["MAX_MESSAGE_LENGTH"],
}
if (sessionid === undefined) {
ctx.state.data = { loggedIn: false }
const resp = await ctx.next()
Expand Down
3 changes: 1 addition & 2 deletions routes/api/v1/chats/friendList.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,7 @@ export const handler = {
roomID: room.uuid,
latestMessageTime: latestmessage?.timestamp,
roomIcon: `/api/v1/friends/${
friendName?.userName + "@" +
env["serverDomain"]
friendName?.userName + "@" + env["serverDomain"]
}/icon`,
type: "localfriend",
userName: friendName?.userName + "@" +
Expand Down
5 changes: 2 additions & 3 deletions routes/api/v1/chats/talkdata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,7 @@ export const handler = {
(read) => read.userid === friendId[0],
) !== -1
return {
sender: sender.userName + "@" +
env["serverDomain"],
sender: sender.userName + "@" + env["serverDomain"],
senderNickName: sender.nickName,
message: message.message,
timestamp: message.timestamp,
Expand Down Expand Up @@ -204,7 +203,7 @@ export const handler = {
).join("")
takostoken.create({
token: takosToken,
origin: friendDomain,
origin: friendDomain
})
const reuslt = await takosfetch(
`${friendDomain}/api/v1/server/talk/read`,
Expand Down
15 changes: 6 additions & 9 deletions routes/api/v1/friends/request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,10 +116,7 @@ export const handler = {
randomarray,
(byte) => byte.toString(16).padStart(2, "0"),
).join("")
takostoken.create({
token: takosToken,
origin: splitFriendName?.domain,
})
takostoken.create({ token: takosToken, origin: splitFriendName?.domain })
const requestResult = await takosfetch(
`${splitFriendName?.domain}/api/v1/server/friends/request`,
{
Expand Down Expand Up @@ -421,7 +418,7 @@ export const handler = {
},
)
}
if (friendInfo.uuid === userid) {
if(friendInfo.uuid === userid){
console.log("friendInfo.uuid === userid")
return new Response(
JSON.stringify({ status: "error" }),
Expand All @@ -432,13 +429,13 @@ export const handler = {
)
}
const myFriendInfo = await Friends.findOne({ user: userid })
if (!myFriendInfo) {
if(!myFriendInfo){
await Friends.create({ user: userid })
}
const isAlredyFriend = myFriendInfo?.friends.some((
friend: any,
) => friend.userid === friendInfo.uuid)
if (isAlredyFriend) {
if(isAlredyFriend){
console.log("isAlredyFriend")
return new Response(
JSON.stringify({ status: "error" }),
Expand Down Expand Up @@ -514,7 +511,7 @@ export const handler = {
const frienduuidres = await takosfetch(
`${serverDomain}/api/v1/server/users/${friendName}/uuid`,
)
if (!frienduuidres) {
if(!frienduuidres){
console.log("frienduuidres is null")
return new Response(
JSON.stringify({ status: "error" }),
Expand All @@ -524,7 +521,7 @@ export const handler = {
},
)
}
if (frienduuidres.status !== 200) {
if(frienduuidres.status !== 200){
console.log("frienduuidres is not 200")
return new Response(
JSON.stringify({ status: "error" }),
Expand Down
22 changes: 2 additions & 20 deletions routes/api/v1/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { takosfetch } from "../../../util/takosfetch.ts"
subClient.on("error", (err: any) => console.error("Sub Client Error", err))

await subClient.connect()
const MESSAGE_MIMIT = Number(env["MESSAGE_MIMIT"])

async function subscribeMessage(channel: string | string[]) {
await subClient.subscribe(channel, async (message) => {
const data = JSON.parse(message)
Expand Down Expand Up @@ -59,7 +59,7 @@ export const handler = {
socket.onmessage = async function (event) {
const data = JSON.parse(event.data)
const { type } = data
if (!type) return
if(!type) return
switch (type) {
case "joinRoom":
joinRoom(data.sessionid, data.roomid, socket)
Expand Down Expand Up @@ -195,15 +195,6 @@ async function sendMessage(
ws: WebSocket,
MessageType: string,
) {
if(message.length > MESSAGE_MIMIT){
ws.send(
JSON.stringify({
status: false,
explain: "Message is too long",
}),
)
return
}
const session = sessions.get(sessionid)
if (!session) {
ws.send(
Expand All @@ -224,15 +215,6 @@ async function sendMessage(
return
}
if (session.roomType === "friend") {
if(message.length > MESSAGE_MIMIT){
ws.send(
JSON.stringify({
status: false,
explain: "Message is too long",
}),
)
return
}
const result = await messages.create({
userid: session.uuid,
roomid: roomID,
Expand Down
12 changes: 5 additions & 7 deletions routes/api/v1/server/friends/[ID]/icon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,20 @@ export const handler = {
status: 400,
})
}
const userserverDomain = splitUserName(reqUser).domain
const userServerDomain = splitUserName(reqUser).domain
const userName = splitUserName(reqUser).userName
if (!userserverDomain || !userName) {
if (!userServerDomain || !userName) {
return new Response(JSON.stringify({ "status": false }), {
status: 400,
})
}
if (userserverDomain == env["serverDomain"]) {
if (userServerDomain == env["serverDomain"]) {
return new Response(JSON.stringify({ "status": false }), {
status: 400,
})
}
const isTrueToken = await takosfetch(
`${userserverDomain}/api/v1/server/token?token=${token}&origin=${
env["serverDomain"]
}`,
`${userServerDomain}/api/v1/server/token?token=${token}&origin=${env["serverDomain"]}`,
)
//userが存在するか確認
const user = await users.findOne({
Expand All @@ -42,7 +40,7 @@ export const handler = {
})
}
const serverInfo = await remoteservers.findOne({
serverDomain: userserverDomain,
serverDomain: userServerDomain,
friends: { $elemMatch: { userid: reqUser } },
})
if (!serverInfo) {
Expand Down
4 changes: 1 addition & 3 deletions routes/api/v1/server/friends/[ID]/profile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,7 @@ export const handler = {
})
}
const isTrueToken = await takosfetch(
`${serverDomain}/api/v1/server/token?token=${token}&origin=${
env["serverDomain"]
}`,
`${serverDomain}/api/v1/server/token?token=${token}&origin=${env["serverDomain"]}`,
)
if (!isTrueToken) {
return new Response(JSON.stringify({ "status": false }), {
Expand Down
6 changes: 2 additions & 4 deletions routes/api/v1/server/friends/request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,7 @@ export const handler = {
})
}
const isTrueToken = await takosfetch(
`${userDomain}/api/v1/server/token?token=` + token +
"&origin=" + env["serverDomain"],
`${userDomain}/api/v1/server/token?token=` + token + "&origin=" + env["serverDomain"],
)
if (!isTrueToken) {
console.log("isTrueToken")
Expand Down Expand Up @@ -234,8 +233,7 @@ export const handler = {
console.log(userDomain, env["serverDomain"], friendDomain)
console.log("3")
const isTrueToken = await takosfetch(
`${userDomain}/api/v1/server/token?token=` + token +
"&origin=" + env["serverDomain"],
`${userDomain}/api/v1/server/token?token=` + token + "&origin=" + env["serverDomain"],
)
if (!isTrueToken) {
return new Response(JSON.stringify({ status: false }), {
Expand Down
3 changes: 1 addition & 2 deletions routes/api/v1/server/talk/read.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@ export const handler = {
})
}
const isTrueToken = await takosfetch(
`${domain}/api/v1/server/token?token=` + token + "&origin=" +
env["serverDomain"],
`${domain}/api/v1/server/token?token=` + token + "&origin=" + env["serverDomain"],
)
if (isTrueToken === null || isTrueToken === undefined) {
return new Response(JSON.stringify({ status: false }), {
Expand Down
9 changes: 1 addition & 8 deletions routes/api/v1/server/talk/send.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { takosfetch } from "../../../../../util/takosfetch.ts"
import { load } from "$std/dotenv/mod.ts"
const env = await load()
const redisch = env["REDIS_CH"]
const MESSAGE_MIMIT = Number(env["MESSAGE_MIMIT"])
export const handler = {
async POST(req: Request, ctx: any) {
const data = await req.json()
Expand All @@ -27,8 +26,7 @@ export const handler = {
}
const { domain, userName } = splitUserName(sender)
const isTrueToken = await takosfetch(
`${domain}/api/v1/server/token?token=` + token + "&origin=" +
env["serverDomain"],
`${domain}/api/v1/server/token?token=` + token + "&origin=" + env["serverDomain"],
)
if (isTrueToken === null || isTrueToken === undefined) {
return new Response(JSON.stringify({ status: false }), {
Expand Down Expand Up @@ -64,11 +62,6 @@ export const handler = {
status: 400,
})
}
if(message.length > MESSAGE_MIMIT){
return new Response(JSON.stringify({ status: false }), {
status: 400,
})
}
const result = await messages.create({
userid: uuid,
roomid,
Expand Down
2 changes: 1 addition & 1 deletion routes/api/v1/server/token.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export const handler = {
status: 400,
})
}
const tokenInfo = await takostoken.findOne({ token, origin })
const tokenInfo = await takostoken.findOne({ token, origin})
if (tokenInfo === null || tokenInfo === undefined) {
return new Response(JSON.stringify({ "status": false }), {
status: 400,
Expand Down
2 changes: 1 addition & 1 deletion routes/api/v1/setting/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ export const handler = {
})
}
await Deno.writeFile(`./files/userIcons/${userid}.webp`, result)
}
return new Response(JSON.stringify({ status: true }), {
Expand Down
1 change: 0 additions & 1 deletion static/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -594,7 +594,6 @@ html, body {
font-size: 15px;
line-height: 20px;
width: fit-content;

}

.c-talk-chat-msg p {
Expand Down

0 comments on commit e9d17de

Please sign in to comment.