Skip to content

Commit

Permalink
Refactor server domain variable names to use uppercase convention
Browse files Browse the repository at this point in the history
  • Loading branch information
tako0614 committed Jun 16, 2024
1 parent 7b42d0d commit fa6ddaf
Show file tree
Hide file tree
Showing 25 changed files with 82 additions and 85 deletions.
23 changes: 10 additions & 13 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
hostname=
username=
db=
password=
MONGO_URL=mongodb://localhost:27017/takos
recaptcha_site_key=6LewIZspAAAAAEwZ8YaDMe8dxxs6F_N8KtSsukQY
rechapcha_seecret_key=6LewIZspAAAAAGJE3RjUqM4dn8jgBCx_zdcXwkwx
recaptcha_site_key=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
rechapcha_seecret_key=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
smtp_host=smtp.gmail.com
smtp_port=587
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
smtp_username=[email protected]
smtp_password=xxxxxxxxxxxxxxx
origin="http://example.com,https://takos.jp,http://localhost:8000"
SERVER_DOMAIN=localhost:8000
REDIS_URL=redis://localhost:6379
PRIORITY_PROTOCOL=http
REDIS_CH=takos
MAX_MESSAGE=100
2 changes: 1 addition & 1 deletion models/remoteServers.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import mongoose from "mongoose"

export const friendsSchema = new mongoose.Schema({
serverDomain: {
SERVER_DOMAIN: {
type: String,
required: true,
},
Expand Down
2 changes: 1 addition & 1 deletion routes/addFriend/[roomid].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ export default function Home({ data }: { data: any }) {
roomid={data.roomid}
settings={settings}
userNickName={data.nickName}
userName={data.userName + "@" + env["serverDomain"]}
userName={data.userName + "@" + env["SERVER_DOMAIN"]}
>
</Chat>
</>
Expand Down
2 changes: 1 addition & 1 deletion routes/addFriend/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ export default function Home({ data }: { data: any }) {
page={2}
isAddFriendForm={false}
userNickName={data.nickName}
userName={data.userName + "@" + env["serverDomain"]}
userName={data.userName + "@" + env["SERVER_DOMAIN"]}
>
</Chat>
</>
Expand Down
8 changes: 4 additions & 4 deletions routes/api/v1/chats/friendList.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,11 +119,11 @@ export const handler = {
roomID: room.uuid,
latestMessageTime: latestmessage?.timestamp,
roomIcon: `/api/v1/friends/${
friendName?.userName + "@" + env["serverDomain"]
friendName?.userName + "@" + env["SERVER_DOMAIN"]
}/icon`,
type: "localfriend",
userName: friendName?.userName + "@" +
env["serverDomain"],
env["SERVER_DOMAIN"],
isNewMessage: isNewMessage === undefined,
}
return friendResult
Expand Down Expand Up @@ -155,8 +155,8 @@ export const handler = {
const OtherServerUserInfo = await takosfetch(
`${OtherServerUserDomain}/api/v1/server/friends/${
OtherServerUser[0].userid
}/profile?token=${takosToken}&serverDomain=${
env["serverDomain"]
}/profile?token=${takosToken}&SERVER_DOMAIN=${
env["SERVER_DOMAIN"]
}&type=id&requser&reqUser=${ctx.state.data.userid}`,
)
if (!OtherServerUserInfo) {
Expand Down
8 changes: 4 additions & 4 deletions routes/api/v1/chats/talkdata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ export const handler = {
(read) => read.userid === friendId[0],
) !== -1
return {
sender: sender.userName + "@" + env["serverDomain"],
sender: sender.userName + "@" + env["SERVER_DOMAIN"],
senderNickName: sender.nickName,
message: message.message,
timestamp: message.timestamp,
Expand Down Expand Up @@ -263,8 +263,8 @@ export const handler = {
const OtherServerUserInfo = await takosfetch(
`${OtherServerUserDomain}/api/v1/server/friends/${
friendId[0]
}/profile?token=${takosToken}&serverDomain=${
env["serverDomain"]
}/profile?token=${takosToken}&SERVER_DOMAIN=${
env["SERVER_DOMAIN"]
}&type=id&reqUser=${ctx.state.data.userid}`,
)
if (!OtherServerUserInfo) {
Expand Down Expand Up @@ -309,7 +309,7 @@ export const handler = {
if (message.userid === ctx.state.data.userid) {
sender = {
userName: userName.userName + "@" +
env["serverDomain"],
env["SERVER_DOMAIN"],
nickName: userName.nickName,
}
} else {
Expand Down
2 changes: 1 addition & 1 deletion routes/api/v1/friends/[ID]/icon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ export const handler = {
})
}

if (friendDomain === env["serverDomain"]) {
if (friendDomain === env["SERVER_DOMAIN"]) {
const friend: Friend | null = await friends.findOne({
user: ctx.state.data.userid,
})
Expand Down
2 changes: 1 addition & 1 deletion routes/api/v1/friends/reqLists.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export const handler = {
}
return {
userName: userInfo.userName + "@" +
env["serverDomain"],
env["SERVER_DOMAIN"],
icon:
`/api/v1/friends/${userInfo.userName}/icon?isRequestList=true`,
timestamp: obj.timestamp,
Expand Down
26 changes: 13 additions & 13 deletions routes/api/v1/friends/request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ export const handler = {
const splitFriendName = splitUserName(friendName)
if (
!splitFriendName ||
splitFriendName.domain !== env["serverDomain"]
splitFriendName.domain !== env["SERVER_DOMAIN"]
) {
const ApplientedUserInfo = await requestAddFriend.findOne({
userID: ctx.state.data.userid,
Expand Down Expand Up @@ -126,7 +126,7 @@ export const handler = {
},
body: JSON.stringify({
requesterUserName: ctx.state.data.userName + "@" +
env["serverDomain"],
env["SERVER_DOMAIN"],
requesterUserUUID: ctx.state.data.userid,
requirement: "acceptReqFriend",
recipientUserName: friendName,
Expand Down Expand Up @@ -168,9 +168,9 @@ export const handler = {
{
username: ctx.state.data.userName,
userid: userid,
host: env["serverDomain"],
host: env["SERVER_DOMAIN"],
type: "local",
domain: env["serverDomain"],
domain: env["SERVER_DOMAIN"],
},
{
username: splitFriendName?.name,
Expand Down Expand Up @@ -284,7 +284,7 @@ export const handler = {
userid: userid,
host: "local",
type: "local",
domain: env["serverDomain"],
domain: env["SERVER_DOMAIN"],
},
{
username: friendInfo.userName,
Expand Down Expand Up @@ -350,7 +350,7 @@ export const handler = {
Applicant: [{
userID: userid,
userName: ApplcienterInfo.userName,
host: env["serverDomain"],
host: env["SERVER_DOMAIN"],
type: "local",
}],
})
Expand All @@ -360,7 +360,7 @@ export const handler = {
AppliedUser: [{
userID: addFriendUserInfo.uuid,
userName: addFriendUserInfo.userName,
host: env["serverDomain"],
host: env["SERVER_DOMAIN"],
type: "local",
}],
})
Expand Down Expand Up @@ -405,7 +405,7 @@ export const handler = {
})
}
try {
if (friendDomain == env["serverDomain"]) {
if (friendDomain == env["SERVER_DOMAIN"]) {
const friendInfo = await users.findOne({
userName: splitUserName(friendName)?.name,
})
Expand Down Expand Up @@ -503,13 +503,13 @@ export const handler = {
})
} else {
//外部サーバーにリクエストを送る
const serverDomain = splitUserName(friendName)?.domain
const SERVER_DOMAIN = splitUserName(friendName)?.domain
const myFriendInfo = await Friends.findOne({ user: userid })
if (myFriendInfo == null) {
await Friends.create({ user: userid })
}
const frienduuidres = await takosfetch(
`${serverDomain}/api/v1/server/users/${friendName}/uuid`,
`${SERVER_DOMAIN}/api/v1/server/users/${friendName}/uuid`,
)
if(!frienduuidres){
console.log("frienduuidres is null")
Expand Down Expand Up @@ -567,10 +567,10 @@ export const handler = {
const takosToken = crypto.randomUUID()
takostoken.create({
token: takosToken,
origin: serverDomain,
origin: SERVER_DOMAIN,
})
const requestResult = await takosfetch(
`${serverDomain}/api/v1/server/friends/request`,
`${SERVER_DOMAIN}/api/v1/server/friends/request`,
{
method: "POST",
headers: {
Expand All @@ -579,7 +579,7 @@ export const handler = {
body: JSON.stringify({
requesterUserName: ctx.state.data.userName +
"@" +
env["serverDomain"],
env["SERVER_DOMAIN"],
requesterUserUUID: ctx.state.data.userid,
requirement: "reqFriend",
recipientUserName: friendName,
Expand Down
2 changes: 1 addition & 1 deletion routes/api/v1/logins/register.js
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ export const handler = {
(byte) => byte.toString(16).padStart(2, "0"),
).join("")
//ユーザーを登録
const uuid = crypto.randomUUID() + "@" + env["serverDomain"]
const uuid = crypto.randomUUID() + "@" + env["SERVER_DOMAIN"]
const result = await users.create({
uuid: uuid,
userName,
Expand Down
10 changes: 5 additions & 5 deletions routes/api/v1/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,7 @@ async function sendConecctingUserMessage(
sessions.forEach(async (session, key) => {
if (session.talkingRoom === roomid) {
isFindUser = true
if (splitUserName(sender).domain !== env["serverDomain"]) {
if (splitUserName(sender).domain !== env["SERVER_DOMAIN"]) {
const takosTokenArray = new Uint8Array(16)
const randomarray = crypto.getRandomValues(takosTokenArray)
const takosToken = Array.from(
Expand All @@ -385,8 +385,8 @@ async function sendConecctingUserMessage(
const remoteFriendInfo = await takosfetch(
`${
splitUserName(sender).domain
}/api/v1/server/friends/${sender}/profile?token=${takosToken}&serverDomain=${
env["serverDomain"]
}/api/v1/server/friends/${sender}/profile?token=${takosToken}&SERVER_DOMAIN=${
env["SERVER_DOMAIN"]
}&type=id&reqUser=${session.uuid}`,
)
if (!remoteFriendInfo) {
Expand Down Expand Up @@ -455,7 +455,7 @@ async function sendConecctingUserMessage(
JSON.stringify({
type: "message",
message: message,
sender: userInfo?.userName + "@" + env["serverDomain"] ||
sender: userInfo?.userName + "@" + env["SERVER_DOMAIN"] ||
"unknown",
senderNickName: userInfo?.nickName || "unknown",
time: time,
Expand Down Expand Up @@ -544,7 +544,7 @@ async function readMessage(messageids: [string], sender: string) {
}),
)
//送信元サーバーにreadしたことを送信
if (splitUserName(sender).domain !== env["serverDomain"]) {
if (splitUserName(sender).domain !== env["SERVER_DOMAIN"]) {
const takosTokenArray = new Uint8Array(16)
const randomarray = crypto.getRandomValues(takosTokenArray)
const takosToken = Array.from(
Expand Down
10 changes: 5 additions & 5 deletions routes/api/v1/server/friends/[ID]/icon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,20 @@ export const handler = {
status: 400,
})
}
const userServerDomain = splitUserName(reqUser).domain
const userSERVER_DOMAIN = splitUserName(reqUser).domain
const userName = splitUserName(reqUser).userName
if (!userServerDomain || !userName) {
if (!userSERVER_DOMAIN || !userName) {
return new Response(JSON.stringify({ "status": false }), {
status: 400,
})
}
if (userServerDomain == env["serverDomain"]) {
if (userSERVER_DOMAIN == env["SERVER_DOMAIN"]) {
return new Response(JSON.stringify({ "status": false }), {
status: 400,
})
}
const isTrueToken = await takosfetch(
`${userServerDomain}/api/v1/server/token?token=${token}&origin=${env["serverDomain"]}`,
`${userSERVER_DOMAIN}/api/v1/server/token?token=${token}&origin=${env["SERVER_DOMAIN"]}`,
)
//userが存在するか確認
const user = await users.findOne({
Expand All @@ -40,7 +40,7 @@ export const handler = {
})
}
const serverInfo = await remoteservers.findOne({
serverDomain: userServerDomain,
SERVER_DOMAIN: userSERVER_DOMAIN,
friends: { $elemMatch: { userid: reqUser } },
})
if (!serverInfo) {
Expand Down
20 changes: 10 additions & 10 deletions routes/api/v1/server/friends/[ID]/profile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ export const handler = {
const { ID } = ctx.params
const requrl = new URL(req.url)
const type = requrl.searchParams.get("type") || ""
const serverDomain = requrl.searchParams.get("serverDomain") || ""
const SERVER_DOMAIN = requrl.searchParams.get("SERVER_DOMAIN") || ""
const token = requrl.searchParams.get("token") || false
if (
ID === undefined || type === "" || type === null ||
type === undefined || serverDomain === "" ||
serverDomain === null ||
serverDomain === undefined
type === undefined || SERVER_DOMAIN === "" ||
SERVER_DOMAIN === null ||
SERVER_DOMAIN === undefined
) {
return new Response(JSON.stringify({ "status": false }), {
status: 400,
Expand All @@ -29,26 +29,26 @@ export const handler = {
status: 400,
})
}
if (serverDomain == env["serverDomain"]) {
if (SERVER_DOMAIN == env["SERVER_DOMAIN"]) {
return new Response(JSON.stringify({ "status": false }), {
status: 400,
})
}
if (splitUserName(reqUser).domain !== serverDomain) {
if (splitUserName(reqUser).domain !== SERVER_DOMAIN) {
return new Response(JSON.stringify({ "status": false }), {
status: 400,
})
}
const isTrueToken = await takosfetch(
`${serverDomain}/api/v1/server/token?token=${token}&origin=${env["serverDomain"]}`,
`${SERVER_DOMAIN}/api/v1/server/token?token=${token}&origin=${env["SERVER_DOMAIN"]}`,
)
if (!isTrueToken) {
return new Response(JSON.stringify({ "status": false }), {
status: 400,
})
}
const serverInfo = await remoteservers.findOne({
serverDomain: serverDomain,
SERVER_DOMAIN: SERVER_DOMAIN,
friends: { $elemMatch: { userid: reqUser } },
})
if (!serverInfo) {
Expand Down Expand Up @@ -80,7 +80,7 @@ export const handler = {
}
const result = {
userName: friendUserInfo.userName + "@" +
env["serverDomain"],
env["SERVER_DOMAIN"],
nickName: friendUserInfo.nickName,
}
return new Response(
Expand All @@ -95,7 +95,7 @@ export const handler = {
})
}
const result = {
userName: userInfo.userName + "@" + env["serverDomain"],
userName: userInfo.userName + "@" + env["SERVER_DOMAIN"],
nickName: userInfo.nickName,
}
return new Response(
Expand Down
Loading

0 comments on commit fa6ddaf

Please sign in to comment.