...
This commit is contained in:
@@ -0,0 +1,186 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="ko">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Synology Photos Random Slideshow</title>
|
||||
<style>
|
||||
/* 기본 스타일링 */
|
||||
body, html {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
background-color: #000;
|
||||
color: #fff;
|
||||
font-family: sans-serif;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
overflow: hidden;
|
||||
}
|
||||
/* 로그인 화면 스타일 */
|
||||
#login-form {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 15px;
|
||||
padding: 30px;
|
||||
background: #222;
|
||||
border-radius: 8px;
|
||||
}
|
||||
#login-form input {
|
||||
padding: 10px;
|
||||
border: 1px solid #444;
|
||||
background: #333;
|
||||
color: #fff;
|
||||
border-radius: 4px;
|
||||
}
|
||||
#login-form button {
|
||||
padding: 10px;
|
||||
background: #007bff;
|
||||
border: none;
|
||||
color: white;
|
||||
cursor: pointer;
|
||||
border-radius: 4px;
|
||||
}
|
||||
/* 사진이 표시될 컨테이너 */
|
||||
#photo-container {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
display: none; /* 처음에는 숨김 */
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
}
|
||||
/* 이미지 스타일 */
|
||||
#slideshow-image {
|
||||
max-width: 100%;
|
||||
max-height: 100%;
|
||||
object-fit: contain; /* 이미지 비율 유지 */
|
||||
/* 부드러운 전환 효과 */
|
||||
opacity: 0;
|
||||
transition: opacity 1.5s ease-in-out;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<div id="login-form">
|
||||
<h2>시놀로지 포토 로그인</h2>
|
||||
<input type="text" id="nas-address" placeholder="NAS 주소 (예: 192.168.0.100)">
|
||||
<input type="text" id="username" placeholder="사용자 ID">
|
||||
<input type="password" id="password" placeholder="비밀번호">
|
||||
<button onclick="startSlideshow()">슬라이드쇼 시작</button>
|
||||
<p id="message" style="color: #ffdddd; text-align: center;"></p>
|
||||
</div>
|
||||
|
||||
<div id="photo-container">
|
||||
<img id="slideshow-image" alt="Loading photo...">
|
||||
</div>
|
||||
|
||||
<script>
|
||||
// 전역 변수 설정
|
||||
let sid = '';
|
||||
let nasAddress = '';
|
||||
const allPhotoIds = [];
|
||||
let slideshowInterval;
|
||||
|
||||
// 메시지 표시 함수
|
||||
function showMessage(msg) {
|
||||
document.getElementById('message').innerText = msg;
|
||||
}
|
||||
|
||||
// 슬라이드쇼 시작 함수
|
||||
async function startSlideshow() {
|
||||
nasAddress = document.getElementById('nas-address').value.trim();
|
||||
const username = document.getElementById('username').value.trim();
|
||||
const password = document.getElementById('password').value;
|
||||
|
||||
if (!nasAddress || !username || !password) {
|
||||
showMessage('모든 정보를 입력해주세요.');
|
||||
return;
|
||||
}
|
||||
showMessage('로그인 중...');
|
||||
|
||||
try {
|
||||
// 1. 로그인하여 세션 ID (sid) 얻기
|
||||
const loginUrl = `https://${nasAddress}/webapi/auth.cgi?api=SYNO.API.Auth&version=7&method=login&account=${username}&passwd=${password}&session=SynologyPhotos&format=sid`;
|
||||
const loginResponse = await fetch(loginUrl,{
|
||||
mode: 'no-cors'
|
||||
});
|
||||
const loginData = await loginResponse.json();
|
||||
|
||||
if (loginData.success && loginData.data.sid) {
|
||||
sid = loginData.data.sid;
|
||||
showMessage('로그인 성공! 사진 목록을 가져옵니다...');
|
||||
|
||||
// 2. 전체 사진 목록 가져오기
|
||||
await fetchAllPhotos(0);
|
||||
|
||||
} else {
|
||||
showMessage('로그인 실패. 정보를 확인하세요.');
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Error:', error);
|
||||
showMessage('오류 발생. NAS 주소를 확인하세요.');
|
||||
}
|
||||
}
|
||||
|
||||
// 재귀적으로 모든 사진 ID를 가져오는 함수
|
||||
async function fetchAllPhotos(offset) {
|
||||
const limit = 5000; // 한 번에 5000개씩 요청
|
||||
const listUrl = `https://${nasAddress}/webapi/entry.cgi?api=SYNO.Foto.Browse.Item&version=1&method=list&limit=${limit}&offset=${offset}&_sid=${sid}`;
|
||||
const response = await fetch(listUrl);
|
||||
const data = await response.json();
|
||||
|
||||
if (data.success) {
|
||||
data.data.list.forEach(item => allPhotoIds.push(item.id));
|
||||
const total = data.data.total;
|
||||
|
||||
if (offset + limit < total) {
|
||||
// 받아올 사진이 더 있다면 다음 페이지 요청
|
||||
showMessage(`${allPhotoIds.length} / ${total} 장 로딩...`);
|
||||
await fetchAllPhotos(offset + limit);
|
||||
} else {
|
||||
// 모든 사진을 다 받아왔다면 슬라이드쇼 시작
|
||||
showMessage('사진 로딩 완료! 슬라이드쇼를 시작합니다.');
|
||||
document.getElementById('login-form').style.display = 'none';
|
||||
document.getElementById('photo-container').style.display = 'flex';
|
||||
|
||||
displayRandomPhoto(); // 첫 사진 표시
|
||||
// 10초마다 사진 변경
|
||||
slideshowInterval = setInterval(displayRandomPhoto, 10000);
|
||||
}
|
||||
} else {
|
||||
showMessage('사진 목록 가져오기 실패.');
|
||||
}
|
||||
}
|
||||
|
||||
// 랜덤 사진을 화면에 표시하는 함수
|
||||
function displayRandomPhoto() {
|
||||
if (allPhotoIds.length === 0) return;
|
||||
|
||||
// 랜덤하게 사진 ID 하나 선택
|
||||
const randomIndex = Math.floor(Math.random() * allPhotoIds.length);
|
||||
const photoId = allPhotoIds[randomIndex];
|
||||
|
||||
// 이미지 다운로드 URL 생성
|
||||
const imageUrl = `https://${nasAddress}/webapi/entry.cgi?api=SYNO.Foto.Download&version=1&method=download&force_download=true&item_id=%5B${photoId}%5D&_sid=${sid}`;
|
||||
|
||||
const imageElement = document.getElementById('slideshow-image');
|
||||
|
||||
// 이미지 Fade out
|
||||
imageElement.style.opacity = 0;
|
||||
|
||||
// 이미지가 완전히 사라진 후 새 이미지 로딩
|
||||
setTimeout(() => {
|
||||
imageElement.src = imageUrl;
|
||||
|
||||
// 새 이미지 로딩이 완료되면 Fade in
|
||||
imageElement.onload = () => {
|
||||
imageElement.style.opacity = 1;
|
||||
};
|
||||
}, 1500); // transition 시간과 동일하게 설정
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user