런처 관리자 바로가기 정리
This commit is contained in:
+60
-14
@@ -4,19 +4,21 @@ let failIndex = 0;
|
||||
const apiUrl = '/custom/launcher/api.php';
|
||||
const PIN_LENGTH = 4;
|
||||
|
||||
const iconItems = [
|
||||
const userIconItems = [
|
||||
{
|
||||
id: 'findmydevice',
|
||||
img: '/custom/launcher/img/find-my.svg',
|
||||
label: '나의 찾기',
|
||||
onclick: () => requireAccess(() => location.href = '/findmydevice')
|
||||
},
|
||||
/*
|
||||
{
|
||||
id: 'wakeonlan',
|
||||
img: '/custom/launcher/img/wakeonlan-svgrepo-com.svg',
|
||||
label: 'PC 켜기',
|
||||
onclick: () => requireAccess(wakeComputer)
|
||||
},
|
||||
*/
|
||||
{
|
||||
id: 'poke',
|
||||
img: '/custom/launcher/img/R1280x0.jpg',
|
||||
@@ -28,14 +30,59 @@ const iconItems = [
|
||||
img: '/custom/launcher/img/car.png',
|
||||
label: '니모',
|
||||
onclick: () => requireAccess(() => location.href = 'https://seo.chaegeon.com/car/monitor.php')
|
||||
},
|
||||
{
|
||||
id: 'git',
|
||||
img: 'https://git.chaegeon.com/assets/img/favicon.svg',
|
||||
label: 'GIT',
|
||||
onclick: () => requireAccess(() => location.href = 'https://git.chaegeon.com')
|
||||
}
|
||||
];
|
||||
|
||||
const adminIconItems = [
|
||||
userIconItems[0],
|
||||
userIconItems[1],
|
||||
userIconItems[2],
|
||||
{
|
||||
id: 'project',
|
||||
img: 'https://git.chaegeon.com/assets/img/favicon.svg',
|
||||
label: '프로젝트',
|
||||
onclick: () => requireAccess(() => location.href = 'https://git.chaegeon.com')
|
||||
},
|
||||
{
|
||||
id: 'block',
|
||||
img: '/admin/favicon/block/favicon.svg',
|
||||
label: 'Block',
|
||||
onclick: () => requireAccess(() => location.href = 'https://chaegeon.com/admin/index.php')
|
||||
},
|
||||
{
|
||||
id: 'notice',
|
||||
img: '/admin/favicon/notice/favicon.svg',
|
||||
label: 'Notice',
|
||||
onclick: () => requireAccess(() => location.href = 'https://chaegeon.com/admin/notice.php')
|
||||
},
|
||||
{
|
||||
id: 'weblog',
|
||||
img: '/weblog/favicon.svg',
|
||||
label: 'Weblog',
|
||||
onclick: () => requireAccess(() => location.href = 'https://chaegeon.com/weblog/index.php')
|
||||
},
|
||||
{
|
||||
id: 'speedstats',
|
||||
img: '/custom/speedtest/favicon.ico',
|
||||
label: 'Speed Stats',
|
||||
onclick: () => requireAccess(() => location.href = 'https://chaegeon.com/custom/speedtest/results/stats.php')
|
||||
}
|
||||
];
|
||||
|
||||
async function renderIcons() {
|
||||
shortcut.className = 'find-container';
|
||||
const session = await getSession();
|
||||
const isAdmin = !!session.admin;
|
||||
const items = isAdmin ? adminIconItems : userIconItems;
|
||||
shortcut.className = `find-container ${isAdmin ? 'launcher-admin-grid' : ''}`;
|
||||
shortcut.innerHTML = '';
|
||||
|
||||
iconItems.forEach(item => {
|
||||
items.forEach(item => {
|
||||
const div = document.createElement('div');
|
||||
div.className = 'iconContainer';
|
||||
div.id = item.id;
|
||||
@@ -54,7 +101,7 @@ async function renderIcons() {
|
||||
shortcut.appendChild(div);
|
||||
});
|
||||
|
||||
if (!await hasAdminSession()) {
|
||||
if (!isAdmin) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -67,23 +114,22 @@ async function renderIcons() {
|
||||
}
|
||||
|
||||
async function hasAdminSession() {
|
||||
const session = await getSession();
|
||||
return !!session.admin;
|
||||
}
|
||||
|
||||
async function getSession() {
|
||||
try {
|
||||
const session = await fetch(`${apiUrl}?adminSession=1`, { credentials: 'same-origin' }).then(res => res.json());
|
||||
return !!session.admin;
|
||||
return await fetch(`${apiUrl}?session=1`, { credentials: 'same-origin' }).then(res => res.json());
|
||||
} catch (_) {
|
||||
return false;
|
||||
return { authenticated: false, admin: false };
|
||||
}
|
||||
}
|
||||
|
||||
async function requireAccess(nextAction) {
|
||||
try {
|
||||
if (await hasAdminSession()) {
|
||||
nextAction && nextAction();
|
||||
return;
|
||||
}
|
||||
|
||||
const session = await fetch(`${apiUrl}?session=1`, { credentials: 'same-origin' }).then(res => res.json());
|
||||
if (session.authenticated) {
|
||||
const session = await getSession();
|
||||
if (session.admin || session.authenticated) {
|
||||
nextAction && nextAction();
|
||||
return;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user