Skip to content
This repository has been archived by the owner on Jan 15, 2024. It is now read-only.

Commit

Permalink
fix #14 ファイルに必須項目がない場合は例外を発生させるように修正
Browse files Browse the repository at this point in the history
  • Loading branch information
yogarasu committed Aug 19, 2022
1 parent c5fbd50 commit f34aa3d
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 14 deletions.
25 changes: 16 additions & 9 deletions libs/channel.mts
Original file line number Diff line number Diff line change
Expand Up @@ -111,28 +111,35 @@ export const buildChannelFile = async (
messageFilePath.replace(srcMessageDirPath, distMessageDirPath)
)

newChannels.push({
// チャンネルの必須項目がない場合は例外を投げる
if (channel.id === undefined || channel.is_archived === undefined) {
throw new Error("Channel is missing a required parameter")
}

const newChannel: Channel = {
slack: {
channel_id: channel.id || "",
channel_name: channel.name || "",
is_archived: channel.is_archived || false,
purpose: channel.purpose?.value ? channel.purpose.value : "",
channel_id: channel.id,
channel_name: channel.name,
is_archived: channel.is_archived,
purpose: channel.purpose?.value || "",
message_file_paths: srcMessageFilePaths,
},
discord: {
channel_id: "",
channel_name: channel.name || "",
is_archived: channel.is_archived || false,
channel_name: channel.name,
is_archived: channel.is_archived,
is_deleted: false,
guild: {
boost_level: 0,
boost_count: 0,
max_file_size: 8000000,
},
topic: channel.purpose?.value ? channel.purpose.value : "",
topic: channel.purpose?.value || "",
message_file_paths: distMessageFilePaths,
},
})
}

newChannels.push(newChannel)
}
}

Expand Down
7 changes: 6 additions & 1 deletion libs/message.mts
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,12 @@ export const buildMessageFile = async (
const messages = JSON.parse(messageFile) as SlackMessage[]
let isMaxFileSizeOver = false
for (const message of messages) {
let content = message.text || ""
// メッセージの必須項目がない場合は例外を投げる
if (message.text === undefined) {
throw new Error("Message is missing a required parameter")
}

let content = message.text

// メッセージ内のユーザー名もしくはBot名のメンションを、Discordでメンションされない形式に置換
const matchMention = content.match(/<@U[A-Z0-9]{10}>/g)
Expand Down
8 changes: 4 additions & 4 deletions libs/user.mts
Original file line number Diff line number Diff line change
Expand Up @@ -133,12 +133,12 @@ export const buildUser = async (

// ユーザーの必須項目がない場合は例外を投げる
if (
!user.id ||
!name ||
user.id === undefined ||
name === undefined ||
user.deleted === undefined ||
user.is_bot === undefined ||
!user.color ||
!user.profile?.image_512
user.color === undefined ||
user.profile?.image_512 === undefined
) {
throw new Error("User is missing a required parameter")
}
Expand Down

0 comments on commit f34aa3d

Please sign in to comment.