Skip to content

Commit

Permalink
chore: 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 869a192 commit 67e9eea
Show file tree
Hide file tree
Showing 25 changed files with 79 additions and 76 deletions.
2 changes: 1 addition & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ smtp_port=587
smtp_username=[email protected]
smtp_password=xxxxxxxxxxxxxxx
origin="http://example.com,https://takos.jp,http://localhost:8000"
SERVER_DOMAIN=localhost:8000
serverDomain=localhost:8000
REDIS_URL=redis://localhost:6379
PRIORITY_PROTOCOL=http
REDIS_CH=takos
Expand Down
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({
SERVER_DOMAIN: {
serverDomain: {
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["SERVER_DOMAIN"]}
userName={data.userName + "@" + env["serverDomain"]}
>
</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["SERVER_DOMAIN"]}
userName={data.userName + "@" + env["serverDomain"]}
>
</Chat>
</>
Expand Down
12 changes: 7 additions & 5 deletions routes/api/v1/chats/friendList.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,11 +120,11 @@ export const handler = {
latestMessageTime: latestmessage?.timestamp,
roomIcon: `/api/v1/friends/${
friendName?.userName + "@" +
env["SERVER_DOMAIN"]
env["serverDomain"]
}/icon`,
type: "localfriend",
userName: friendName?.userName + "@" +
env["SERVER_DOMAIN"],
env["serverDomain"],
isNewMessage: isNewMessage === undefined,
}
return friendResult
Expand Down Expand Up @@ -156,10 +156,12 @@ export const handler = {
const OtherServerUserInfo = await takosfetch(
`${OtherServerUserDomain}/api/v1/server/friends/${
OtherServerUser[0].userid
}/profile?token=${takosToken}&SERVER_DOMAIN=${
env["SERVER_DOMAIN"]
}&type=id&requser&reqUser=${ctx.state.data.userid}`,
}/profile?token=${takosToken}&serverDomain=${
env["serverDomain"]
}&type=id&reqUser=${ctx.state.data.userid}`,
)
console.log(OtherServerUserInfo.url)
console.log("")
if (!OtherServerUserInfo) {
const remoteErrorResult = {
roomName: "remote server error",
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 @@ -118,7 +118,7 @@ export const handler = {
) !== -1
return {
sender: sender.userName + "@" +
env["SERVER_DOMAIN"],
env["serverDomain"],
senderNickName: sender.nickName,
message: message.message,
timestamp: message.timestamp,
Expand Down Expand Up @@ -264,8 +264,8 @@ export const handler = {
const OtherServerUserInfo = await takosfetch(
`${OtherServerUserDomain}/api/v1/server/friends/${
friendId[0]
}/profile?token=${takosToken}&SERVER_DOMAIN=${
env["SERVER_DOMAIN"]
}/profile?token=${takosToken}&serverDomain=${
env["serverDomain"]
}&type=id&reqUser=${ctx.state.data.userid}`,
)
if (!OtherServerUserInfo) {
Expand Down Expand Up @@ -310,7 +310,7 @@ export const handler = {
if (message.userid === ctx.state.data.userid) {
sender = {
userName: userName.userName + "@" +
env["SERVER_DOMAIN"],
env["serverDomain"],
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["SERVER_DOMAIN"]) {
if (friendDomain === env["serverDomain"]) {
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["SERVER_DOMAIN"],
env["serverDomain"],
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["SERVER_DOMAIN"]
splitFriendName.domain !== env["serverDomain"]
) {
const ApplientedUserInfo = await requestAddFriend.findOne({
userID: ctx.state.data.userid,
Expand Down Expand Up @@ -129,7 +129,7 @@ export const handler = {
},
body: JSON.stringify({
requesterUserName: ctx.state.data.userName + "@" +
env["SERVER_DOMAIN"],
env["serverDomain"],
requesterUserUUID: ctx.state.data.userid,
requirement: "acceptReqFriend",
recipientUserName: friendName,
Expand Down Expand Up @@ -171,9 +171,9 @@ export const handler = {
{
username: ctx.state.data.userName,
userid: userid,
host: env["SERVER_DOMAIN"],
host: env["serverDomain"],
type: "local",
domain: env["SERVER_DOMAIN"],
domain: env["serverDomain"],
},
{
username: splitFriendName?.name,
Expand Down Expand Up @@ -287,7 +287,7 @@ export const handler = {
userid: userid,
host: "local",
type: "local",
domain: env["SERVER_DOMAIN"],
domain: env["serverDomain"],
},
{
username: friendInfo.userName,
Expand Down Expand Up @@ -353,7 +353,7 @@ export const handler = {
Applicant: [{
userID: userid,
userName: ApplcienterInfo.userName,
host: env["SERVER_DOMAIN"],
host: env["serverDomain"],
type: "local",
}],
})
Expand All @@ -363,7 +363,7 @@ export const handler = {
AppliedUser: [{
userID: addFriendUserInfo.uuid,
userName: addFriendUserInfo.userName,
host: env["SERVER_DOMAIN"],
host: env["serverDomain"],
type: "local",
}],
})
Expand Down Expand Up @@ -408,7 +408,7 @@ export const handler = {
})
}
try {
if (friendDomain == env["SERVER_DOMAIN"]) {
if (friendDomain == env["serverDomain"]) {
const friendInfo = await users.findOne({
userName: splitUserName(friendName)?.name,
})
Expand Down Expand Up @@ -506,13 +506,13 @@ export const handler = {
})
} else {
//外部サーバーにリクエストを送る
const SERVER_DOMAIN = splitUserName(friendName)?.domain
const serverDomain = splitUserName(friendName)?.domain
const myFriendInfo = await Friends.findOne({ user: userid })
if (myFriendInfo == null) {
await Friends.create({ user: userid })
}
const frienduuidres = await takosfetch(
`${SERVER_DOMAIN}/api/v1/server/users/${friendName}/uuid`,
`${serverDomain}/api/v1/server/users/${friendName}/uuid`,
)
if (!frienduuidres) {
console.log("frienduuidres is null")
Expand Down Expand Up @@ -570,10 +570,10 @@ export const handler = {
const takosToken = crypto.randomUUID()
takostoken.create({
token: takosToken,
origin: SERVER_DOMAIN,
origin: serverDomain,
})
const requestResult = await takosfetch(
`${SERVER_DOMAIN}/api/v1/server/friends/request`,
`${serverDomain}/api/v1/server/friends/request`,
{
method: "POST",
headers: {
Expand All @@ -582,7 +582,7 @@ export const handler = {
body: JSON.stringify({
requesterUserName: ctx.state.data.userName +
"@" +
env["SERVER_DOMAIN"],
env["serverDomain"],
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["SERVER_DOMAIN"]
const uuid = crypto.randomUUID() + "@" + env["serverDomain"]
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 @@ -393,7 +393,7 @@ async function sendConecctingUserMessage(
sessions.forEach(async (session, key) => {
if (session.talkingRoom === roomid) {
isFindUser = true
if (splitUserName(sender).domain !== env["SERVER_DOMAIN"]) {
if (splitUserName(sender).domain !== env["serverDomain"]) {
const takosTokenArray = new Uint8Array(16)
const randomarray = crypto.getRandomValues(takosTokenArray)
const takosToken = Array.from(
Expand All @@ -403,8 +403,8 @@ async function sendConecctingUserMessage(
const remoteFriendInfo = await takosfetch(
`${
splitUserName(sender).domain
}/api/v1/server/friends/${sender}/profile?token=${takosToken}&SERVER_DOMAIN=${
env["SERVER_DOMAIN"]
}/api/v1/server/friends/${sender}/profile?token=${takosToken}&serverDomain=${
env["serverDomain"]
}&type=id&reqUser=${session.uuid}`,
)
if (!remoteFriendInfo) {
Expand Down Expand Up @@ -473,7 +473,7 @@ async function sendConecctingUserMessage(
JSON.stringify({
type: "message",
message: message,
sender: userInfo?.userName + "@" + env["SERVER_DOMAIN"] ||
sender: userInfo?.userName + "@" + env["serverDomain"] ||
"unknown",
senderNickName: userInfo?.nickName || "unknown",
time: time,
Expand Down Expand Up @@ -562,7 +562,7 @@ async function readMessage(messageids: [string], sender: string) {
}),
)
//送信元サーバーにreadしたことを送信
if (splitUserName(sender).domain !== env["SERVER_DOMAIN"]) {
if (splitUserName(sender).domain !== env["serverDomain"]) {
const takosTokenArray = new Uint8Array(16)
const randomarray = crypto.getRandomValues(takosTokenArray)
const takosToken = Array.from(
Expand Down
12 changes: 6 additions & 6 deletions routes/api/v1/server/friends/[ID]/icon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,21 @@ export const handler = {
status: 400,
})
}
const userSERVER_DOMAIN = splitUserName(reqUser).domain
const userserverDomain = splitUserName(reqUser).domain
const userName = splitUserName(reqUser).userName
if (!userSERVER_DOMAIN || !userName) {
if (!userserverDomain || !userName) {
return new Response(JSON.stringify({ "status": false }), {
status: 400,
})
}
if (userSERVER_DOMAIN == env["SERVER_DOMAIN"]) {
if (userserverDomain == env["serverDomain"]) {
return new Response(JSON.stringify({ "status": false }), {
status: 400,
})
}
const isTrueToken = await takosfetch(
`${userSERVER_DOMAIN}/api/v1/server/token?token=${token}&origin=${
env["SERVER_DOMAIN"]
`${userserverDomain}/api/v1/server/token?token=${token}&origin=${
env["serverDomain"]
}`,
)
//userが存在するか確認
Expand All @@ -42,7 +42,7 @@ export const handler = {
})
}
const serverInfo = await remoteservers.findOne({
SERVER_DOMAIN: userSERVER_DOMAIN,
serverDomain: userserverDomain,
friends: { $elemMatch: { userid: reqUser } },
})
if (!serverInfo) {
Expand Down
23 changes: 12 additions & 11 deletions routes/api/v1/server/friends/[ID]/profile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,15 @@ export const handler = {
const { ID } = ctx.params
const requrl = new URL(req.url)
const type = requrl.searchParams.get("type") || ""
const SERVER_DOMAIN = requrl.searchParams.get("SERVER_DOMAIN") || ""
const serverDomain = requrl.searchParams.get("serverDomain") || ""
const token = requrl.searchParams.get("token") || false
if (
ID === undefined || type === "" || type === null ||
type === undefined || SERVER_DOMAIN === "" ||
SERVER_DOMAIN === null ||
SERVER_DOMAIN === undefined
type === undefined || serverDomain === "" ||
serverDomain === null ||
serverDomain === undefined
) {
console.log("ID: ", ID)
return new Response(JSON.stringify({ "status": false }), {
status: 400,
})
Expand All @@ -29,19 +30,19 @@ export const handler = {
status: 400,
})
}
if (SERVER_DOMAIN == env["SERVER_DOMAIN"]) {
if (serverDomain == env["serverDomain"]) {
return new Response(JSON.stringify({ "status": false }), {
status: 400,
})
}
if (splitUserName(reqUser).domain !== SERVER_DOMAIN) {
if (splitUserName(reqUser).domain !== serverDomain) {
return new Response(JSON.stringify({ "status": false }), {
status: 400,
})
}
const isTrueToken = await takosfetch(
`${SERVER_DOMAIN}/api/v1/server/token?token=${token}&origin=${
env["SERVER_DOMAIN"]
`${serverDomain}/api/v1/server/token?token=${token}&origin=${
env["serverDomain"]
}`,
)
if (!isTrueToken) {
Expand All @@ -50,7 +51,7 @@ export const handler = {
})
}
const serverInfo = await remoteservers.findOne({
SERVER_DOMAIN: SERVER_DOMAIN,
serverDomain: serverDomain,
friends: { $elemMatch: { userid: reqUser } },
})
if (!serverInfo) {
Expand Down Expand Up @@ -82,7 +83,7 @@ export const handler = {
}
const result = {
userName: friendUserInfo.userName + "@" +
env["SERVER_DOMAIN"],
env["serverDomain"],
nickName: friendUserInfo.nickName,
}
return new Response(
Expand All @@ -97,7 +98,7 @@ export const handler = {
})
}
const result = {
userName: userInfo.userName + "@" + env["SERVER_DOMAIN"],
userName: userInfo.userName + "@" + env["serverDomain"],
nickName: userInfo.nickName,
}
return new Response(
Expand Down
Loading

0 comments on commit 67e9eea

Please sign in to comment.