File size: 3,661 Bytes
872af5e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Sri Office — Editor</title>
<style>
  * { box-sizing: border-box; font-family: -apple-system, Segoe UI, Roboto, sans-serif; }
  html, body { margin: 0; height: 100%; }
  /* Flex column so the top bar always keeps its height and can never be clipped. */
  body { display: flex; flex-direction: column; height: 100vh; overflow: hidden; }
  header { flex: 0 0 50px; display: flex; align-items: center; gap: 14px; padding: 0 14px;
           background: #fff; border-bottom: 1px solid #e1dfdd; }
  .back { display: inline-flex; align-items: center; gap: 6px; padding: 7px 12px; border: 1px solid #e1dfdd;
          border-radius: 6px; color: #201f1e; text-decoration: none; font-size: 13px; font-weight: 500;
          white-space: nowrap; flex: 0 0 auto; }
  .back:hover { background: #f3f2f1; }
  .title { font-size: 14px; color: #201f1e; font-weight: 600; white-space: nowrap; overflow: hidden;
           text-overflow: ellipsis; flex: 0 1 auto; max-width: 30vw; }
  /* Advertisement slot — fills the remaining bar space. Drop your ad markup
     (image/<a>/<iframe>/ad-network script) inside #ad-slot. */
  .ad { flex: 1 1 auto; height: 100%; display: flex; align-items: center; justify-content: center;
        min-width: 0; overflow: hidden; }
  #ad-slot { height: 38px; width: 100%; max-width: 728px; background: #faf9f8; border: 1px dashed #d2d0ce;
             border-radius: 6px; display: flex; align-items: center; justify-content: center;
             color: #a19f9d; font-size: 12px; }
  #ad-slot a { display: block; }
  #ad-slot img { max-height: 38px; }
  #editor { flex: 1 1 auto; min-height: 0; }
  #placeholder { width: 100%; height: 100%; }
  #msg { padding: 40px; color: #b30b00; font-size: 15px; }
</style>
</head>
<body>
  <header>
    <a class="back" href="/dashboard">← Back</a>
    <span class="title" id="title"></span>
    <div class="ad"><div id="ad-slot">Advertisement</div></div>
  </header>
  <div id="editor"><div id="placeholder"></div></div>
  <div id="msg"></div>
<script>
const params = new URLSearchParams(location.search);
const filename = params.get('file');
document.getElementById('title').textContent = filename || '';

const token = localStorage.getItem('token');
if (!token) location.href = '/';

async function init() {
  if (!filename) { document.getElementById('msg').textContent = 'No file specified.'; return; }
  let data;
  try {
    const res = await fetch('/api/editor-config?filename=' + encodeURIComponent(filename),
                            { headers: { 'Authorization': 'Bearer ' + token } });
    if (res.status === 401) { localStorage.clear(); location.href = '/'; return; }
    if (!res.ok) { document.getElementById('msg').textContent = 'File not found.'; return; }
    data = await res.json();
  } catch (e) {
    document.getElementById('msg').textContent = 'Could not load editor config.'; return;
  }
  // Point the editor logo at our own app (not onlyoffice.com) using the real origin.
  try {
    const c = data.config.editorConfig.customization;
    c.logo = c.logo || {};
    c.logo.url = location.origin + '/dashboard';
  } catch (e) {}
  // Load the Document Server API script, then mount the editor.
  const s = document.createElement('script');
  s.src = data.ds_api_url;
  s.onload = () => new DocsAPI.DocEditor('placeholder', data.config);
  s.onerror = () => { document.getElementById('msg').textContent =
    'Could not reach the editor service. Please try again.'; };
  document.body.appendChild(s);
}
init();
</script>
</body>
</html>