const hallo = completion.choices[0].message.content; // 응답을 hallo 변수에 저장
console.log(hallo); // 응답을 콘솔에 출력
return hallo; // hallo 값을 반환
} catch (error) {
console.error("Error with OpenAI API:", error.response ? error.response.data : error.message);
throw new Error('Failed to get response from OpenAI API');
} if (rows.length === 0) {
await db.execute(
'INSERT INTO users (username, email, provider, provider_id, profile_picture) VALUES (?, ?, ?, ?, ?)',
[profile.displayName, profile.emails[0].value, 'google', profile.id, profile.photos[0]?.value]
);
}
return done(null, profile);
} catch (err) {
console.error('Google Auth Error:', err);
return done(err, null);
}
}
) if (rows.length === 0) {
await db.execute(
'INSERT INTO users (username, provider, provider_id, profile_picture) VALUES (?, ?, ?, ?)',
[profile.displayName || profile.username, 'kakao', profile.id, profile._json.properties.profile_image]
);
}
return done(null, profile);
} catch (err) {
console.error('Kakao Auth Error:', err);
return done(err, null);
}
}
) if (rows.length === 0) {
await db.execute(
'INSERT INTO users (username, email, provider, provider_id, profile_picture) VALUES (?, ?, ?, ?, ?)',
[profile.displayName, profile.emails[0]?.value, 'naver', profile.id, profile._json.profile_image]
);
}
return done(null, profile);
} catch (err) {
console.error('Naver Auth Error:', err);
return done(err, null);
}
}
)// 정적 파일 경로 설정
const frontendPath = path.join(__dirname, '../frontend');
app.use(express.static(frontendPath));
// 기본 경로에서 index.html 제공
app.get('/', (req, res) => {
res.sendFile(path.join(frontendPath, 'index.html'));
});
// OpenAI POST 요청 처리
app.post('/hallo', async (req, res) => {
const userMessage = req.body.message;
try {
const hallo = await getChatCompletion(userMessage);
res.json({ response: hallo });
} catch (error) {
res.status(500).json({ error: 'Error occurred while fetching the response.' });
}
});
// 로그인 라우트 (Google, Kakao, Naver 등 추가)
const PORT = process.env.PORT || 3000;
app.listen(PORT, () => {
console.log(`Server is running on http://localhost:${PORT}`);
});</style><main>
<!-- 탭 메뉴 -->
<nav>
<button class="tab-button active" data-tab="uploads">업로드 정보 관리</button>
<button class="tab-button" data-tab="chat-rooms">아바타 채팅방 관리</button>
<button class="tab-button" data-tab="personalization">개인화 페이지 관리</button>
</nav>
<!-- 업로드된 정보 관리 -->
<section id="uploads" class="tab-content active">
<h2>업로드된 정보 관리</h2>
<table id="uploadTable">
<thead>
<tr>
<th>ID</th>
<th>제목</th>
<th>카테고리</th>
<th>내용</th>
<th>액션</th>
</tr>
</thead>
<tbody>
<!-- 데이터가 동적으로 추가됩니다 -->
</tbody>
</table>
<button onclick="openUploadModal()">정보 추가</button>
</section>
<!-- 아바타 채팅방 관리 -->
<section id="chat-rooms" class="tab-content">
<h2>아바타 채팅방 관리</h2>
<table id="chatRoomTable">
<thead>
<tr>
<th>ID</th>
<th>채팅방 이름</th>
<th>참여자 수</th>
<th>상태</th>
<th>액션</th>
</tr>
</thead>
<tbody>
<!-- 데이터가 동적으로 추가됩니다 -->
</tbody>
</table>
</section>
<!-- 개인화 페이지 관리 -->
<section id="personalization" class="tab-content">
<h2>개인화 페이지 관리</h2>
<table id="userTable">
<thead>
<tr>
<th>ID</th>
<th>이름</th>
<th>이메일</th>
<th>상태</th>
<th>액션</th>
</tr>
</thead>
<tbody>
<!-- 데이터가 동적으로 추가됩니다 -->
</tbody>
</table>
</section>
</main>
<script>
document.addEventListener('DOMContentLoaded', () => {
const tabs = document.querySelectorAll('.tab-button');
const contents = document.querySelectorAll('.tab-content');
// 탭 전환
tabs.forEach(tab => {
tab.addEventListener('click', () => {
tabs.forEach(t => t.classList.remove('active'));
contents.forEach(c => c.classList.remove('active'));
tab.classList.add('active');
document.getElementById(tab.dataset.tab).classList.add('active');
});
});
// 데이터 가져오기 (업로드된 정보)
fetchUploads();
// 데이터 가져오기 (아바타 채팅방)
fetchChatRooms();
// 데이터 가져오기 (개인화 페이지)
fetchUsers();// 여기에 서버로부터 데이터를 가져오는 코드 추가 (더미 데이터 예제)
const uploads = [
{ id: 1, title: 'AI 혁신', category: 'AI', content: 'AI 기술 소개' },
{ id: 2, title: '취업 꿀팁', category: '취업', content: '취업 준비 가이드' }
];
uploads.forEach(upload => {
const row = document.createElement('tr');
row.innerHTML =
<td>${upload.id}</td>
<td>${upload.title}</td>
<td>${upload.category}</td>
<td>${upload.content}</td>
<td>
<button onclick="editUpload(${upload.id})">수정</button>
<button onclick="deleteUpload(${upload.id})">삭제</button>
</td>
;
uploadTable.appendChild(row);
});const chatRooms = [
{ id: 1, name: 'AI 방', participants: 10, status: '활성' },
{ id: 2, name: '취업 방', participants: 5, status: '비활성' }
];
chatRooms.forEach(room => {
const row = document.createElement('tr');
row.innerHTML =
<td>${room.id}</td>
<td>${room.name}</td>
<td>${room.participants}</td>
<td>${room.status}</td>
<td>
<button onclick="deleteChatRoom(${room.id})">삭제</button>
</td>
;
chatRoomTable.appendChild(row);
});const users = [
{ id: 1, name: '김철수', email: 'kim@example.com', status: '활성' },
{ id: 2, name: '이영희', email: 'lee@example.com', status: '비활성' }
];
users.forEach(user => {
const row = document.createElement('tr');
row.innerHTML =
<td>${user.id}</td>
<td>${user.name}</td>
<td>${user.email}</td>
<td>${user.status}</td>
<td>
<button onclick="editUser(${user.id})">수정</button>
<button onclick="deleteUser(${user.id})">삭제</button>
</td>
;
userTable.appendChild(row);
});</script>