Skip to content

Commit

Permalink
chore: Update room types enum to include "community" option
Browse files Browse the repository at this point in the history
  • Loading branch information
tako0614 committed Jul 6, 2024
1 parent 0382e1a commit 39c8922
Show file tree
Hide file tree
Showing 24 changed files with 223 additions and 90 deletions.
4 changes: 2 additions & 2 deletions fresh.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ import * as $api_v2_client_talks_sending_update from "./routes/api/v2/client/tal
import * as $api_v2_client_talks_sending_video from "./routes/api/v2/client/talks/sending/video.ts"
import * as $api_v2_client_unblock_server from "./routes/api/v2/client/unblock/server.ts"
import * as $api_v2_client_unblock_user from "./routes/api/v2/client/unblock/user.ts"
import * as $api_v2_client_users_icon from "./routes/api/v2/client/users/icon.ts"
import * as $api_v2_client_users_profile from "./routes/api/v2/client/users/profile.ts"
import * as $api_v2_client_users_icon from "./routes/api/v2/client/users/[uuid]/icon.ts"
import * as $api_v2_client_users_profile from "./routes/api/v2/client/users/[uuid]/index.ts"
import * as $api_v2_client_users_settings from "./routes/api/v2/client/users/settings.ts"
import * as $api_v2_client_welcome from "./routes/api/v2/client/welcome.ts"
import * as $api_v2_server_activity_accept_community from "./routes/api/v2/server/activity/accept/community.ts"
Expand Down
Empty file added models/invite.ts
Empty file.
Empty file added models/request.ts
Empty file.
2 changes: 1 addition & 1 deletion models/rooms.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export const roomsSchema = new mongoose.Schema({
types: {
type: String,
required: true,
enum: ["group", "friend", "public", "remotefriend"],
enum: ["group", "friend", "community", "remotefriend"],
},
users: {
type: [
Expand Down
10 changes: 10 additions & 0 deletions models/serverInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,16 @@ export const serverInfoSchema = new mongoose.Schema({
type: Date,
default: Date.now,
},
privatekey: {
type: String,
},
publickey: {
type: String,
},
lastupdatekey: {
type: Date,
default: Date.now,
},
})
const ssessionID = mongoose.model("serverInfo", serverInfoSchema)
export default ssessionID
20 changes: 10 additions & 10 deletions models/userConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,23 @@ export const friendConfigSchama = new mongoose.Schema({
type: [String],
required: true,
validate: {
validator: function(v: string[]) {
const unique = new Set(v);
return unique.size === v.length;
validator: function (v: string[]) {
const unique = new Set(v)
return unique.size === v.length
},
message: (props: { value: any }) => `${props.value} contains duplicate entries!`
}
message: (props: { value: any }) => `${props.value} contains duplicate entries!`,
},
},
blockServers: {
type: [String],
required: true,
validate: {
validator: function(v: string[]) {
const unique = new Set(v);
return unique.size === v.length;
validator: function (v: string[]) {
const unique = new Set(v)
return unique.size === v.length
},
message: (props: { value: any }) => `${props.value} contains duplicate entries!`
}
message: (props: { value: any }) => `${props.value} contains duplicate entries!`,
},
},
allowOtherServerUsers: {
type: Boolean,
Expand Down
2 changes: 1 addition & 1 deletion routes/addFriend/[roomid].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,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["DOMAIN"]}
wsSSL={wsSSL}
>
</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 @@ -86,7 +86,7 @@ export default function Home({ data }: { data: any }) {
page={2}
isAddFriendForm={false}
userNickName={data.nickName}
userName={data.userName + "@" + env["serverDomain"]}
userName={data.userName + "@" + env["DOMAIN"]}
wsSSL={wsSSL}
>
</Chat>
Expand Down
10 changes: 5 additions & 5 deletions routes/api/v2/client/block/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ export const handler = {
}
const body = await req.json()
const domain = body.domain
if(await takos.checkCsrfToken(body.csrftoken) === false) {
return new Response(JSON.stringify({ status: false, message: "Invalid CSRF token" }), {
headers: { "Content-Type": "application/json" },
status: 400,
})
if (await takos.checkCsrfToken(body.csrftoken) === false) {
return new Response(JSON.stringify({ status: false, message: "Invalid CSRF token" }), {
headers: { "Content-Type": "application/json" },
status: 400,
})
}
if (typeof domain !== "string") {
return new Response(JSON.stringify({ status: false, message: "Invalid domain" }), {
Expand Down
100 changes: 59 additions & 41 deletions routes/api/v2/client/block/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,45 +8,63 @@ import userConfig from "../../../../../models/userConfig.ts"
import users from "../../../../../models/users.ts"
const env = await load()
export const handler = {
async POST(req: Request, ctx: any) {
if (!ctx.state.data.loggedIn) {
return new Response(JSON.stringify({ status: "Please Login" }), {
headers: { "Content-Type": "application/json" },
status: 401,
})
}
const body = await req.json()
const userid = body.userid
if (typeof userid !== "string") {
return new Response(JSON.stringify({ status: false, message: "Invalid user ID" }), {
headers: { "Content-Type": "application/json" },
status: 400,
})
}
const userName = takos.splitUserName(userid).userName
const userDomain = takos.splitUserName(userid).domain
if(await takos.checkCsrfToken(body.csrftoken) === false) {
return new Response(JSON.stringify({ status: false, message: "Invalid CSRF token" }), {
headers: { "Content-Type": "application/json" },
status: 400,
})
}
if(userName === ctx.state.data.username) {
return new Response(JSON.stringify({ status: false, message: "Cannot block yourself" }), {
headers: { "Content-Type": "application/json" },
status: 400,
})
}
const user = await users.findOne({ username: userName })
if (user === null) {
return new Response(JSON.stringify({ status: false, message: "User not found" }), {
headers: { "Content-Type": "application/json" },
status: 404,
})
}
await userConfig.updateOne({ userID: ctx.state.data.userid }, { $push: { blockedUsers: userid } })
if(userDomain !== env["DOMAIN"]) {
await fetch("https://" + userDomain + "/api/v2/client/block/server",)
}
async POST(req: Request, ctx: any) {
if (!ctx.state.data.loggedIn) {
return new Response(JSON.stringify({ status: "Please Login" }), {
headers: { "Content-Type": "application/json" },
status: 401,
})
}
}
const body = await req.json()
const userid = body.userid
if (typeof userid !== "string") {
return new Response(JSON.stringify({ status: false, message: "Invalid user ID" }), {
headers: { "Content-Type": "application/json" },
status: 400,
})
}
const userName = takos.splitUserName(userid).userName
const userDomain = takos.splitUserName(userid).domain
if (await takos.checkCsrfToken(body.csrftoken) === false) {
return new Response(JSON.stringify({ status: false, message: "Invalid CSRF token" }), {
headers: { "Content-Type": "application/json" },
status: 400,
})
}
if (userName === ctx.state.data.username) {
return new Response(JSON.stringify({ status: false, message: "Cannot block yourself" }), {
headers: { "Content-Type": "application/json" },
status: 400,
})
}
const user = await users.findOne({ username: userName })
if (user === null) {
return new Response(JSON.stringify({ status: false, message: "User not found" }), {
headers: { "Content-Type": "application/json" },
status: 404,
})
}
await userConfig.updateOne({ userID: ctx.state.data.userid }, { $push: { blockedUsers: userid } })
if (userDomain !== env["DOMAIN"]) {
const privateKey = await takos.getPrivateKey()
const signature = await takos.signData(JSON.stringify({ userid: ctx.state.data.userid, blockedUser: userid }), privateKey)
const remoteServer = await fetch(`https://${userDomain}/api/v2/server/block/user`, {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({ userid: ctx.state.data.userid, blockedUser: userid, signature: new Uint8Array(signature) }),
})
if(remoteServer.status !== 200) {
return new Response(JSON.stringify({ status: false, message: "Failed to block user on remote server" }), {
headers: { "Content-Type": "application/json" },
status: 200,
})
}
}
//useridとfriendidが入っているfriendroomを削除
return new Response(JSON.stringify({ status: true }), {
headers: { "Content-Type": "application/json" },
})
},
}
4 changes: 4 additions & 0 deletions routes/api/v2/client/create/community.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
//communityを作成する
// POST /api/v2/client/create/community
// { name: string, description: string, csrftoken: string, icon: file }
// -> { status: boolean, message: string }
4 changes: 4 additions & 0 deletions routes/api/v2/client/create/group.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
//グループを作成する
// POST /api/v2/client/create/group
// { name: string, description: string, csrftoken: string, icon: file, inviteUsers: string[] }
// -> { status: boolean, message: string }
2 changes: 1 addition & 1 deletion routes/api/v2/client/settings/privacy.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//設定を変更するapi
//POST /api/v2/client/settings/privacy
// { setting: { ... }, csrftoken: string }
// -> { status: boolean, message: string }
// -> { status: boolean, message: string }
3 changes: 3 additions & 0 deletions routes/api/v2/client/users/[uuid]/icon.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
//iconを取得
// GET /api/v2/client/users/icon
// -> { status: boolean, message: string, icon: file }
2 changes: 1 addition & 1 deletion routes/api/v2/client/welcome.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import remoteServers from "../../../../models/remoteServers.ts"
import serverInfo from "../../../../models/serverInfo.ts"
import { load } from "$std/dotenv/mod.ts"
const env = await load()
const serverDomain = env["serverDomain"]
const serverDomain = env["DOMAIN"]
// Denoの標準ライブラリから必要な関数をインポート

async function loadDenoConfig() {
Expand Down
2 changes: 1 addition & 1 deletion routes/api/v2/server/activity/block/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
// POST /api/v2/server/activity/block/user
// { host: string, body: string }
// bodyは秘密鍵で署名されたJSON
// body: { userid: string, username: string }
// body: { userid: string, friendid: string }
2 changes: 1 addition & 1 deletion routes/home/[roomid].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,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["DOMAIN"]}
wsSSL={wsSSL}
>
</Chat>
Expand Down
2 changes: 1 addition & 1 deletion routes/home/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={0}
isAddFriendForm={false}
userNickName={data.nickName}
userName={data.userName + "@" + env["serverDomain"]}
userName={data.userName + "@" + env["DOMAIN"]}
wsSSL={wsSSL}
>
</Chat>
Expand Down
4 changes: 2 additions & 2 deletions routes/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ export default function Home({ data }: { data: any }) {
isAddFriendForm={true}
AddFriendKey={data.key}
userNickName={data.nickName}
userName={data.userName + "@" + env["serverDomain"]}
userName={data.userName + "@" + env["DOMAIN"]}
wsSSL={wsSSL}
>
</Chat>
Expand All @@ -95,7 +95,7 @@ export default function Home({ data }: { data: any }) {
isAddFriendForm={false}
index={true}
userNickName={data.nickName}
userName={data.userName + "@" + env["serverDomain"]}
userName={data.userName + "@" + env["DOMAIN"]}
>
</Chat>
)}
Expand Down
2 changes: 1 addition & 1 deletion routes/setting/[roomid].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,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["DOMAIN"]}
wsSSL={wsSSL}
>
</Chat>
Expand Down
2 changes: 1 addition & 1 deletion routes/setting/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ export default function Home({ data }: { data: any }) {
page={3}
isAddFriendForm={false}
userNickName={data.nickName}
userName={data.userName + "@" + env["serverDomain"]}
userName={data.userName + "@" + env["DOMAIN"]}
wsSSL={wsSSL}
>
</Chat>
Expand Down
2 changes: 1 addition & 1 deletion routes/talk/[roomid].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,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["DOMAIN"]}
wsSSL={wsSSL}
>
</Chat>
Expand Down
2 changes: 1 addition & 1 deletion routes/talk/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,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["DOMAIN"]}
wsSSL={wsSSL}
>
</Chat>
Expand Down
Loading

0 comments on commit 39c8922

Please sign in to comment.