File size: 2,293 Bytes
8b7b432
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
document.addEventListener('DOMContentLoaded', function() {
    const diaryForm = document.querySelector('form');
    const keywordsInput = document.querySelector('textarea');
    const resultDiv = document.querySelector('#result');
    const generateButton = document.querySelector('button');
    const loadingContainer = document.querySelector('#loading-container');
    const progressBar = document.querySelector('.progress-bar');

    diaryForm.addEventListener('submit', async function(e) {
        e.preventDefault();
        
        const keywords = keywordsInput.value.trim();
        if (!keywords) {
            resultDiv.textContent = "ν‚€μ›Œλ“œλ₯Ό μž…λ ₯ν•΄μ£Όμ„Έμš”";
            return;
        }

        try {
            generateButton.disabled = true;
            resultDiv.textContent = "";
            loadingContainer.style.display = 'block';
            progressBar.style.width = '0%';
            
            // ν”„λ‘œκ·Έλ ˆμŠ€ λ°” μ• λ‹ˆλ©”μ΄μ…˜ μ‹œμž‘ (60μ΄ˆμ—μ„œ 30초둜 λ³€κ²½)
            progressBar.style.animation = 'progress 30s linear';
            
            const API_URL = 'http://your-ec2-instance-ip:5000';

            const response = await fetch(`${API_URL}/api/generate-diary`, {
                method: 'POST',
                headers: {
                    'Content-Type': 'application/json',
                    'Accept': 'application/json'
                },
                body: JSON.stringify({
                    keywords: keywords
                })
            });

            if (!response.ok) {
                const errorText = await response.text();
                throw new Error(`μ„œλ²„ 응닡 였λ₯˜: ${response.status}`);
            }

            const data = await response.json();
            
            if (data.error) {
                resultDiv.textContent = `였λ₯˜: ${data.error}`;
            } else {
                resultDiv.textContent = data.diary || '일기 생성에 μ‹€νŒ¨ν–ˆμŠ΅λ‹ˆλ‹€.';
            }
        } catch (error) {
            resultDiv.textContent = `였λ₯˜κ°€ λ°œμƒν–ˆμŠ΅λ‹ˆλ‹€: ${error.message}`;
        } finally {
            generateButton.disabled = false;
            loadingContainer.style.display = 'none';
            progressBar.style.animation = 'none';
        }
    });
});