File size: 15,539 Bytes
a55ebe6
 
 
 
e36ac14
 
a55ebe6
aeeaec0
9fabca7
aeeaec0
 
 
 
f441c8d
b960f80
aeeaec0
 
f5d8ab2
f441c8d
 
 
9fabca7
a55ebe6
 
 
e36ac14
aeeaec0
 
 
 
d7db631
 
e36ac14
aeeaec0
e36ac14
aeeaec0
e36ac14
a55ebe6
e36ac14
f5d8ab2
aeeaec0
f441c8d
 
e36ac14
a55ebe6
aeeaec0
 
 
73e9b03
aeeaec0
 
73e9b03
 
 
 
b960f80
 
 
aeeaec0
 
73e9b03
f5d8ab2
 
 
 
a55ebe6
 
aeeaec0
e36ac14
 
f441c8d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
b960f80
 
 
 
f441c8d
 
 
 
 
a55ebe6
 
 
 
e36ac14
f5d8ab2
f441c8d
f5d8ab2
b960f80
9fabca7
aeeaec0
f441c8d
aeeaec0
 
 
d7db631
a55ebe6
aeeaec0
 
 
73e9b03
 
f441c8d
aeeaec0
73e9b03
aeeaec0
 
 
f5d8ab2
f441c8d
aeeaec0
f441c8d
 
aeeaec0
e36ac14
 
f441c8d
e36ac14
 
 
 
f5d8ab2
e36ac14
b960f80
e36ac14
f5d8ab2
 
 
 
 
 
aeeaec0
f441c8d
 
 
aeeaec0
 
73e9b03
aeeaec0
f441c8d
 
b960f80
 
f441c8d
a55ebe6
 
e36ac14
73e9b03
f5d8ab2
 
 
aeeaec0
 
f5d8ab2
 
 
 
e36ac14
 
a55ebe6
e36ac14
f5d8ab2
 
 
 
 
 
 
b960f80
f5d8ab2
b960f80
f5d8ab2
 
 
 
 
 
 
 
 
 
b960f80
f5d8ab2
 
 
 
 
e36ac14
aeeaec0
 
f441c8d
 
aeeaec0
 
e36ac14
 
f441c8d
 
 
 
 
 
 
 
 
 
b960f80
 
 
 
 
f441c8d
 
 
 
 
 
 
 
b960f80
 
f441c8d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
b960f80
 
 
 
f441c8d
 
 
 
b960f80
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
f441c8d
 
 
 
 
 
 
 
 
b960f80
aeeaec0
 
 
f441c8d
 
 
aeeaec0
 
f441c8d
 
e36ac14
 
73e9b03
 
 
 
a55ebe6
 
9fabca7
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Admin_Control | Duochrome</title>
    <link href="https://fonts.googleapis.com/css2?family=Roboto+Mono:wght@400;700&display=swap" rel="stylesheet">
    <style>
        :root { --bg-color: #1A1A1D; --text-color: #f3f2ec; --shadow-color: #f3f2ec; }
        * { margin: 0; padding: 0; box-sizing: border-box; }
        body { font-family: "Roboto Mono", monospace; background: var(--bg-color); color: var(--text-color); padding: 40px 20px; }
        .container { max-width: 800px; margin: 0 auto; }
        .box { border: 1px solid var(--text-color); padding: 40px; box-shadow: 8px 8px 0 var(--shadow-color); margin-top: 10vh; }
        label { display: block; margin-top: 20px; font-weight: 700; font-size: 0.8rem; opacity: 0.7; }
        input, textarea, select { width: 100%; background: transparent; border: 1px solid var(--text-color); color: var(--text-color); padding: 12px; margin-top: 8px; font-family: inherit; outline: none; }
        select option { color: #000; } 
        .btn { padding: 12px 24px; font-weight: 700; cursor: pointer; border: 1px solid var(--text-color); text-transform: uppercase; font-family: inherit; margin-top: 20px; }
        .btn-main { background: var(--text-color); color: var(--bg-color); }
        .btn-alt { background: transparent; color: var(--text-color); border-color: var(--text-color); }
        .tabs { display: flex; border: 1px solid var(--text-color); margin: 30px 0; overflow-x: auto;}
        .tab { flex: 1; padding: 15px; background: none; color: var(--text-color); border: none; border-right: 1px solid var(--text-color); cursor: pointer; text-transform: uppercase; font-weight: 700; white-space: nowrap;}
        .tab:last-child { border-right: none; }
        .tab.active { background: var(--text-color); color: var(--bg-color); }
    </style>
</head>
<body>
    <div class="container">
        <div id="loginSection" class="box">
            <h2 style="margin-bottom: 20px;">SYSTEM_AUTH</h2>
            <input type="password" id="adminPass" placeholder="ENTER_SECRET_KEY">
            <button class="btn btn-main" onclick="attemptLogin()" style="width: 100%;">AUTHORIZE</button>
        </div>

        <div id="adminPanel" style="display: none;">
            <header style="display: flex; justify-content: space-between; border-bottom: 1px solid; padding-bottom: 20px;">
                <h1>ADMIN_PANEL</h1>
                <button class="btn" onclick="sessionStorage.clear(); location.reload()">EXIT</button>
            </header>

            <div class="tabs">
                <button class="tab active" id="btn-post" onclick="switchTab('post')">EDITOR</button>
                <button class="tab" id="btn-manage" onclick="switchTab('manage')">MANAGE_DATA</button>
                <button class="tab" id="btn-link" onclick="switchTab('link')">ADD_LINK</button>
                <button class="tab" id="btn-manage-links" onclick="switchTab('manage-links')">MANAGE_LINKS</button>
            </div>

            <div id="tab-post">
                <label>TITLE_HEADER</label>
                <input type="text" id="postTitle" placeholder="Post Title" oninput="autoSlug(this.value)">
                
                <label>URL_SLUG (Auto-Generated)</label>
                <input type="text" id="postSlug" placeholder="post-title">
                
                <label>EXCERPT (Preview text)</label>
                <input type="text" id="postExcerpt" placeholder="A brief summary of this log...">

                <label>TAGS (Comma-separated)</label>
                <input type="text" id="postTags" placeholder="e.g., asr, whisper, python, fastapi">

                <label>MARKDOWN_CONTENT</label>
                <textarea id="postContent" style="height: 300px;" placeholder="# Hello World..."></textarea>
                
                <div style="display: flex; gap: 10px;">
                    <button class="btn btn-main" id="submitBtn" onclick="submitArticle()">EXECUTE_UPLOAD</button>
                    <button class="btn btn-alt" id="cancelBtn" onclick="cancelEdit()" style="display: none;">CANCEL_EDIT</button>
                </div>
            </div>

            <div id="tab-manage" style="display: none;">
                <div id="articleList"></div>
            </div>

            <div id="tab-link" style="display: none;">
                <label>RESOURCE_TITLE</label>
                <input type="text" id="linkTitle" placeholder="e.g., Evaluating Whisper Medium on FLEURS">
                
                <label>TARGET_URL</label>
                <input type="url" id="linkUrl" placeholder="https://...">

                <label>CATEGORY</label>
                <select id="linkCategory">
                    <option value="Research Paper">Research Paper</option>
                    <option value="GitHub Repo">GitHub Repo</option>
                    <option value="Dataset">Dataset</option>
                    <option value="Article/Tutorial">Article/Tutorial</option>
                </select>
                
                <label>DESCRIPTION (Optional)</label>
                <input type="text" id="linkDesc" placeholder="Brief note on why this is saved...">
                
                <div style="display: flex; gap: 10px;">
                    <button class="btn btn-main" id="submitLinkBtn" onclick="submitLink()">SAVE_LINK</button>
                    <button class="btn btn-alt" id="cancelLinkBtn" onclick="cancelLinkEdit()" style="display: none;">CANCEL_EDIT</button>
                </div>
            </div>

            <div id="tab-manage-links" style="display: none;">
                <div id="linkList"></div>
            </div>
        </div>
    </div>

    <script>
        const API = '/api';
        let globalArticles = [];
        let globalLinks = [];
        let currentEditId = null;
        let currentEditLinkId = null;

        function autoSlug(val) {
            if (currentEditId) return; 
            document.getElementById('postSlug').value = val.toLowerCase().trim()
                .replace(/[^a-z0-9]+/g, '-')
                .replace(/(^-|-$)/g, '');
        }

        async function attemptLogin() {
            const pass = document.getElementById('adminPass').value;
            sessionStorage.setItem('key', pass);
            
            const res = await fetch(`${API}/auth/verify`, { 
                 headers: { 'X-Admin-Password': pass }
            });
            
            if (res.ok) {
                document.getElementById('loginSection').style.display = 'none';
                document.getElementById('adminPanel').style.display = 'block';
                loadArticles();
                loadLinks();
            } else { 
                 alert('ACCESS_DENIED: Invalid Key'); 
                 sessionStorage.clear();
            }
        }

        // --- ARTICLE LOGIC ---
        async function submitArticle() {
            const data = {
                title: document.getElementById('postTitle').value,
                slug: document.getElementById('postSlug').value,
                excerpt: document.getElementById('postExcerpt').value,
                content: document.getElementById('postContent').value,
                tags: document.getElementById('postTags').value.split(',').map(t => t.trim()).filter(Boolean)
            };

            const url = currentEditId ? `${API}/articles/${currentEditId}` : `${API}/articles`;
            const method = currentEditId ? 'PUT' : 'POST';

            const res = await fetch(url, {
                method: method,
                headers: { 
                     'Content-Type': 'application/json', 
                     'X-Admin-Password': sessionStorage.getItem('key') 
                 },
                body: JSON.stringify(data)
            });
            
            if (res.ok) { 
                 alert(currentEditId ? 'βœ“ UPDATE_SUCCESS' : 'βœ“ UPLOAD_SUCCESS'); 
                 cancelEdit();
                 loadArticles();
                 switchTab('manage');
            } else { alert('βœ— OPERATION_FAILED'); }
        }

        async function loadArticles() {
            const res = await fetch(`${API}/articles?published_only=false`);
            globalArticles = await res.json();
            
            document.getElementById('articleList').innerHTML = globalArticles.map(a => `
                <div style="border: 1px solid; padding: 20px; margin-bottom: 15px; display: flex; justify-content: space-between; align-items: center;">
                    <span style="text-transform: uppercase; font-weight: 700;">${a.title}</span>
                    <div>
                        <button class="btn btn-main" style="margin: 0; padding: 5px 15px; font-size: 0.7rem; margin-right: 10px;" onclick="editArt(${a.id})">EDIT</button>
                        <button class="btn" style="margin: 0; padding: 5px 15px; font-size: 0.7rem;" onclick="deleteArt(${a.id})">PURGE</button>
                    </div>
                </div>
            `).join('');
        }

        function editArt(id) {
            const article = globalArticles.find(a => a.id === id);
            if (!article) return;
            currentEditId = id;
            document.getElementById('postTitle').value = article.title;
            document.getElementById('postSlug').value = article.slug;
            document.getElementById('postExcerpt').value = article.excerpt || '';
            document.getElementById('postTags').value = (article.tags || []).join(', ');
            document.getElementById('postContent').value = article.content;
            
            document.getElementById('submitBtn').innerText = "UPDATE_DATA";
            document.getElementById('cancelBtn').style.display = "block";
            switchTab('post');
        }

        function cancelEdit() {
            currentEditId = null;
            document.getElementById('postTitle').value = '';
            document.getElementById('postSlug').value = '';
            document.getElementById('postExcerpt').value = '';
            document.getElementById('postTags').value = '';
            document.getElementById('postContent').value = '';
            document.getElementById('submitBtn').innerText = "EXECUTE_UPLOAD";
            document.getElementById('cancelBtn').style.display = "none";
        }

        async function deleteArt(id) {
            if (!confirm('CONFIRM_DATA_PURGE?')) return;
            await fetch(`${API}/articles/${id}`, { 
                 method: 'DELETE', 
                 headers: { 'X-Admin-Password': sessionStorage.getItem('key') }
            });
            loadArticles();
        }

        // --- LINK LOGIC ---
        async function submitLink() {
            const data = {
                title: document.getElementById('linkTitle').value,
                url: document.getElementById('linkUrl').value,
                category: document.getElementById('linkCategory').value,
                description: document.getElementById('linkDesc').value,
                tags: []
            };

            const url = currentEditLinkId ? `${API}/links/${currentEditLinkId}` : `${API}/links`;
            const method = currentEditLinkId ? 'PUT' : 'POST';

            const res = await fetch(url, {
                method: method,
                headers: { 
                     'Content-Type': 'application/json', 
                     'X-Admin-Password': sessionStorage.getItem('key') 
                 },
                body: JSON.stringify(data)
            });
            
            if (res.ok) { 
                 alert(currentEditLinkId ? 'βœ“ LINK_UPDATED' : 'βœ“ LINK_SAVED'); 
                 cancelLinkEdit();
                 loadLinks();
                 switchTab('manage-links');
            } else { alert('βœ— OPERATION_FAILED'); }
        }

        async function loadLinks() {
            const res = await fetch(`${API}/links`);
            globalLinks = await res.json();
            
            document.getElementById('linkList').innerHTML = globalLinks.map(l => `
                <div style="border: 1px solid; padding: 20px; margin-bottom: 15px; display: flex; justify-content: space-between; align-items: center;">
                    <div>
                        <span style="text-transform: uppercase; font-weight: 700; display: block;">${l.title}</span>
                        <span style="font-size: 0.8rem; opacity: 0.7;">[${l.category}] ${l.url}</span>
                    </div>
                    <div>
                        <button class="btn btn-main" style="margin: 0; padding: 5px 15px; font-size: 0.7rem; margin-right: 10px;" onclick="editLink(${l.id})">EDIT</button>
                        <button class="btn" style="margin: 0; padding: 5px 15px; font-size: 0.7rem;" onclick="deleteLink(${l.id})">PURGE</button>
                    </div>
                </div>
            `).join('');
        }

        function editLink(id) {
            const link = globalLinks.find(l => l.id === id);
            if (!link) return;
            currentEditLinkId = id;
            document.getElementById('linkTitle').value = link.title;
            document.getElementById('linkUrl').value = link.url;
            document.getElementById('linkCategory').value = link.category;
            document.getElementById('linkDesc').value = link.description || '';
            
            document.getElementById('submitLinkBtn').innerText = "UPDATE_LINK";
            document.getElementById('cancelLinkBtn').style.display = "block";
            switchTab('link');
        }

        function cancelLinkEdit() {
            currentEditLinkId = null;
            document.getElementById('linkTitle').value = '';
            document.getElementById('linkUrl').value = '';
            document.getElementById('linkCategory').value = 'Research Paper';
            document.getElementById('linkDesc').value = '';
            
            document.getElementById('submitLinkBtn').innerText = "SAVE_LINK";
            document.getElementById('cancelLinkBtn').style.display = "none";
        }

        async function deleteLink(id) {
            if (!confirm('CONFIRM_LINK_PURGE?')) return;
            await fetch(`${API}/links/${id}`, { 
                 method: 'DELETE', 
                 headers: { 'X-Admin-Password': sessionStorage.getItem('key') }
            });
            loadLinks();
        }

        // --- TAB NAVIGATION ---
        function switchTab(t) {
            document.getElementById('tab-post').style.display = t === 'post' ? 'block' : 'none';
            document.getElementById('tab-manage').style.display = t === 'manage' ? 'block' : 'none';
            document.getElementById('tab-link').style.display = t === 'link' ? 'block' : 'none';
            document.getElementById('tab-manage-links').style.display = t === 'manage-links' ? 'block' : 'none';
            
            document.getElementById('btn-post').classList.toggle('active', t === 'post');
            document.getElementById('btn-manage').classList.toggle('active', t === 'manage');
            document.getElementById('btn-link').classList.toggle('active', t === 'link');
            document.getElementById('btn-manage-links').classList.toggle('active', t === 'manage-links');
        }

        if(sessionStorage.getItem('key')) {
            document.getElementById('adminPass').value = sessionStorage.getItem('key');
            attemptLogin();
        }
    </script>
</body>
</html>