Skip to content

Commit

Permalink
Fix cannot read active session (#61)
Browse files Browse the repository at this point in the history
* [fix] - チャンネルリスト取得が非同期になっていた

* [add] - セッションデータ取得時アクティブセッションも返すように
  • Loading branch information
NfoAlex committed Aug 13, 2024
1 parent 6026501 commit f3d27b2
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 7 deletions.
6 changes: 3 additions & 3 deletions src/actionHandler/Channel/fetchChannelList.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@ import type { IChannel, IChannelbeforeParsing } from "../../type/Channel";
* @param _userId
* @returns
*/
export default async function fetchChannelList(_userId: string)
:Promise<IChannel[]|null> {
export default function fetchChannelList(_userId: string)
:IChannel[]|null {
try {

//ユーザー情報を取得、ないならnull
const userInfo = fetchUser(_userId, null);
if (userInfo === null) return null;

//このユーザーがサーバー管理権限がありプラベを見られるか調べる
//このユーザーがサーバー管理権限を持っていてプラベを見られるか調べる
const roleServerManage = roleCheck(_userId, "ServerManage");

//チャンネル情報を一括取得
Expand Down
22 changes: 19 additions & 3 deletions src/actionHandler/auth/fetchSession.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,34 @@ import type { IUserSession } from "../../type/User";
* @param _indexNumber
* @returns
*/
export default function fetchSession(_userId: string, _indexNumber: number)
:IUserSession[] | null {
export default function fetchSession(
_userId: string,
_sessionId: string,
_indexNumber: number
): {
sessionData: IUserSession[],
activeSession: IUserSession
}
|
null
{
try {

//オフセットでずらすデータ数
const offsetNum = 10 * (_indexNumber-1 || 0);

//セッションデータ一覧を表示分だけ取得
const sessionData = db.prepare(
"SELECT * FROM USERS_SESSION WHERE userId=? LIMIT 10 OFFSET ?"
).all(_userId, offsetNum) as IUserSession[];

return sessionData;
//操作者のアクティブセッションを取得
const activeSession = db.prepare(
"SELECT * FROM USERS_SESSION WHERE userId=? AND sessionId=?"
).get(_userId, _sessionId) as IUserSession|undefined;
if (activeSession === undefined) return null;

return {sessionData: sessionData, activeSession: activeSession};

} catch(e) {

Expand Down
6 changes: 5 additions & 1 deletion src/socketHandler/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,11 @@ module.exports = (io:Server) => {

try {
//セッション情報を取得
const sessionData = fetchSession(dat.RequestSender.userId, dat.indexNum);
const sessionData = fetchSession(
dat.RequestSender.userId,
dat.RequestSender.sessionId,
dat.indexNum
);
//nullじゃなければ送信
if (sessionData !== null) {
socket.emit("RESULT::fetchSession", { result:"SUCCESS", data:sessionData });
Expand Down

0 comments on commit f3d27b2

Please sign in to comment.