index.html 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474
  1. <!doctype html>
  2. <!-- Generated by scripts/sitegen. Edit the files there and run `go run .`; changes made here are overwritten. -->
  3. <html lang="zh-Hant" data-theme="light" class="accent-makers">
  4. <head>
  5. <meta charset="utf-8">
  6. <meta name="viewport" content="width=device-width, initial-scale=1, viewport-fit=cover">
  7. <title>子服務(已棄用)— ArozOS</title>
  8. <meta name="description" content="ArozOS 子服務的運作方式:以任何語言撰寫的執行檔,由 ArozOS 啟動、反向代理並放上桌面。子服務架構已棄用,不再維護。">
  9. <link rel="canonical" href="https://os.aroz.org/zh-tw/subservice/">
  10. <link rel="alternate" hreflang="en" href="https://os.aroz.org/subservice/" data-href="../../subservice/">
  11. <link rel="alternate" hreflang="zh-Hant" href="https://os.aroz.org/zh-tw/subservice/" data-href="./">
  12. <link rel="alternate" hreflang="zh-Hans" href="https://os.aroz.org/zh-cn/subservice/" data-href="../../zh-cn/subservice/">
  13. <link rel="alternate" hreflang="ja" href="https://os.aroz.org/ja/subservice/" data-href="../../ja/subservice/">
  14. <link rel="alternate" hreflang="x-default" href="https://os.aroz.org/subservice/">
  15. <script>
  16. (function () {
  17. var d = document.documentElement, s = null, l = null;
  18. d.className += " js";
  19. try { s = localStorage.getItem("aroz-theme"); l = localStorage.getItem("aroz-lang"); } catch (e) {}
  20. var p = s === "light" || s === "dark" ? s : "auto";
  21. d.setAttribute("data-theme-pref", p);
  22. d.setAttribute("data-theme", p === "auto" ? (matchMedia("(prefers-color-scheme: dark)").matches ? "dark" : "light") : p);
  23. if (l || d.lang !== "en" || /bot|crawl|spider/i.test(navigator.userAgent)) return;
  24. var want = "", list = navigator.languages || [navigator.language || ""];
  25. for (var i = 0; i < list.length && !want; i++) {
  26. var c = (list[i] || "").toLowerCase();
  27. if (c.indexOf("zh") === 0) want = /hant|tw|hk|mo/.test(c) ? "zh-Hant" : "zh-Hans";
  28. else if (c.indexOf("ja") === 0) want = "ja";
  29. else if (c.indexOf("en") === 0) want = "en";
  30. }
  31. try { localStorage.setItem("aroz-lang", want || "en"); } catch (e) { return; }
  32. if (!want || want === "en") return;
  33. var alt = document.querySelector('link[rel="alternate"][hreflang="' + want + '"]');
  34. if (alt) location.replace(alt.getAttribute("data-href") + location.hash);
  35. })();
  36. </script>
  37. <meta name="color-scheme" content="light dark">
  38. <meta name="theme-color" content="#ffffff" media="(prefers-color-scheme: light)">
  39. <meta name="theme-color" content="#000000" media="(prefers-color-scheme: dark)">
  40. <meta property="og:type" content="website">
  41. <meta property="og:site_name" content="ArozOS">
  42. <meta property="og:title" content="子服務(已棄用)— ArozOS">
  43. <meta property="og:description" content="ArozOS 子服務的運作方式:以任何語言撰寫的執行檔,由 ArozOS 啟動、反向代理並放上桌面。子服務架構已棄用,不再維護。">
  44. <meta property="og:url" content="https://os.aroz.org/zh-tw/subservice/">
  45. <meta property="og:image" content="https://os.aroz.org/img/og.png">
  46. <meta property="og:locale" content="zh_TW">
  47. <meta name="twitter:card" content="summary_large_image">
  48. <link rel="icon" href="../../img/favicon.png">
  49. <link rel="apple-touch-icon" href="../../img/apple-touch-icon.png">
  50. <link rel="stylesheet" href="../../assets/site.css?v=0b27a21e">
  51. <script src="../../assets/site.js?v=0b27a21e" defer></script>
  52. </head>
  53. <body>
  54. <a class="skip" href="#main">跳至主要內容</a>
  55. <header class="nav" id="nav">
  56. <div class="nav-in">
  57. <a class="brand" href="../" aria-label="ArozOS"><svg class="logo" viewBox="0 0 256 256" aria-hidden="true"><rect class="logo-bg" width="256" height="256" rx="58"/><path class="logo-fg" d="M70 58h116l-58 70zM128 128l58 70H70z"/></svg><span>ArozOS</span></a>
  58. <nav class="nav-links" aria-label="主選單">
  59. <a href="../desktop.html">桌面</a>
  60. <a href="../media.html">影音</a>
  61. <a href="../office.html">辦公</a>
  62. <a href="../ai.html">AI</a>
  63. <a href="../makers.html">創客</a>
  64. <a href="../storage.html">儲存</a>
  65. <a href="../server.html">伺服器</a>
  66. </nav>
  67. <div class="nav-tools">
  68. <div class="pop" data-pop>
  69. <button type="button" class="icon-btn" aria-haspopup="menu" aria-expanded="false" aria-label="語言" title="語言"><svg class="i" viewBox="0 0 24 24" aria-hidden="true" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="9"/><path d="M3 12h18M12 3c2.5 2.7 3.8 5.7 3.8 9s-1.3 6.3-3.8 9c-2.5-2.7-3.8-5.7-3.8-9S9.5 5.7 12 3z"/></svg></button>
  70. <div class="pop-menu" role="menu"><a role="menuitemradio" href="../../subservice/" hreflang="en" lang="en" data-lang="en" aria-checked="false">English</a><a role="menuitemradio" href="./" hreflang="zh-Hant" lang="zh-Hant" data-lang="zh-Hant" aria-checked="true">繁體中文</a><a role="menuitemradio" href="../../zh-cn/subservice/" hreflang="zh-Hans" lang="zh-Hans" data-lang="zh-Hans" aria-checked="false">简体中文</a><a role="menuitemradio" href="../../ja/subservice/" hreflang="ja" lang="ja" data-lang="ja" aria-checked="false">日本語</a></div>
  71. </div>
  72. <div class="pop" data-pop>
  73. <button type="button" class="icon-btn theme-btn" aria-haspopup="menu" aria-expanded="false" aria-label="外觀" title="外觀"><span class="ti-light"><svg class="i" viewBox="0 0 24 24" aria-hidden="true" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="4"/><path d="M12 2.5v2M12 19.5v2M5.3 5.3l1.4 1.4M17.3 17.3l1.4 1.4M2.5 12h2M19.5 12h2M5.3 18.7l1.4-1.4M17.3 6.7l1.4-1.4"/></svg></span><span class="ti-dark"><svg class="i" viewBox="0 0 24 24" aria-hidden="true" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><path d="M20.5 14.5A8.5 8.5 0 0 1 9.5 3.5a8.5 8.5 0 1 0 11 11z"/></svg></span><span class="ti-auto"><svg class="i" viewBox="0 0 24 24" aria-hidden="true" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="8.5"/><path d="M12 3.5a8.5 8.5 0 0 1 0 17z" fill="currentColor"/></svg></span></button>
  74. <div class="pop-menu" role="menu"><button type="button" role="menuitemradio" data-theme-set="light" aria-checked="false"><svg class="i" viewBox="0 0 24 24" aria-hidden="true" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="4"/><path d="M12 2.5v2M12 19.5v2M5.3 5.3l1.4 1.4M17.3 17.3l1.4 1.4M2.5 12h2M19.5 12h2M5.3 18.7l1.4-1.4M17.3 6.7l1.4-1.4"/></svg><span>淺色</span></button><button type="button" role="menuitemradio" data-theme-set="dark" aria-checked="false"><svg class="i" viewBox="0 0 24 24" aria-hidden="true" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><path d="M20.5 14.5A8.5 8.5 0 0 1 9.5 3.5a8.5 8.5 0 1 0 11 11z"/></svg><span>深色</span></button><button type="button" role="menuitemradio" data-theme-set="auto" aria-checked="false"><svg class="i" viewBox="0 0 24 24" aria-hidden="true" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="8.5"/><path d="M12 3.5a8.5 8.5 0 0 1 0 17z" fill="currentColor"/></svg><span>自動</span></button></div>
  75. </div>
  76. <a class="btn primary sm nav-dl" href="../download.html">下載</a>
  77. <button type="button" class="icon-btn menu-btn" aria-expanded="false" aria-controls="sheet" aria-label="選單"><span class="mi-open"><svg class="i" viewBox="0 0 24 24" aria-hidden="true" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><path d="M4 9h16M4 15h16"/></svg></span><span class="mi-close"><svg class="i" viewBox="0 0 24 24" aria-hidden="true" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><path d="M6 6l12 12M18 6L6 18"/></svg></span></button>
  78. </div>
  79. </div>
  80. <div class="sheet" id="sheet">
  81. <nav class="sheet-links" aria-label="主選單">
  82. <a href="../">總覽</a>
  83. <a href="../desktop.html">桌面</a>
  84. <a href="../media.html">影音</a>
  85. <a href="../office.html">辦公</a>
  86. <a href="../ai.html">AI</a>
  87. <a href="../makers.html">創客</a>
  88. <a href="../storage.html">儲存</a>
  89. <a href="../server.html">伺服器</a>
  90. <a href="../download.html">下載</a>
  91. </nav>
  92. <div class="sheet-ctl">
  93. <p class="ctl-label">語言</p>
  94. <div class="seg lang-seg" role="menu"><a role="menuitemradio" href="../../subservice/" hreflang="en" lang="en" data-lang="en" aria-checked="false">English</a><a role="menuitemradio" href="./" hreflang="zh-Hant" lang="zh-Hant" data-lang="zh-Hant" aria-checked="true">繁體中文</a><a role="menuitemradio" href="../../zh-cn/subservice/" hreflang="zh-Hans" lang="zh-Hans" data-lang="zh-Hans" aria-checked="false">简体中文</a><a role="menuitemradio" href="../../ja/subservice/" hreflang="ja" lang="ja" data-lang="ja" aria-checked="false">日本語</a></div>
  95. <p class="ctl-label">外觀</p>
  96. <div class="seg" role="menu"><button type="button" role="menuitemradio" data-theme-set="light" aria-checked="false"><svg class="i" viewBox="0 0 24 24" aria-hidden="true" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="4"/><path d="M12 2.5v2M12 19.5v2M5.3 5.3l1.4 1.4M17.3 17.3l1.4 1.4M2.5 12h2M19.5 12h2M5.3 18.7l1.4-1.4M17.3 6.7l1.4-1.4"/></svg><span>淺色</span></button><button type="button" role="menuitemradio" data-theme-set="dark" aria-checked="false"><svg class="i" viewBox="0 0 24 24" aria-hidden="true" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><path d="M20.5 14.5A8.5 8.5 0 0 1 9.5 3.5a8.5 8.5 0 1 0 11 11z"/></svg><span>深色</span></button><button type="button" role="menuitemradio" data-theme-set="auto" aria-checked="false"><svg class="i" viewBox="0 0 24 24" aria-hidden="true" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="8.5"/><path d="M12 3.5a8.5 8.5 0 0 1 0 17z" fill="currentColor"/></svg><span>自動</span></button></div>
  97. </div>
  98. </div>
  99. </header>
  100. <main id="main">
  101. <section class="hero">
  102. <div class="wrap hero-head">
  103. <p class="eyebrow rv">開發者文件</p>
  104. <h1 class="hero-title rv" style="--d:1"><span class="grad">子服務</span></h1>
  105. <p class="hero-sub rv" style="--d:2">用任何語言撰寫的執行檔,由 ArozOS 啟動、以同一組登入反向代理,並放上桌面。</p>
  106. </div>
  107. </section>
  108. <section class="notice-sec">
  109. <div class="wrap narrow">
  110. <div class="notice rv" role="note">
  111. <div class="notice-ic"><svg class="i" viewBox="0 0 24 24" aria-hidden="true" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><path d="M10.3 4.2L2.8 17.5A2 2 0 0 0 4.5 20.5h15a2 2 0 0 0 1.7-3L13.7 4.2a2 2 0 0 0-3.4 0z"/><path d="M12 9.5v4.2"/><path d="M12 17h.01"/></svg></div>
  112. <div class="notice-body">
  113. <p class="notice-tag">已棄用</p>
  114. <h2>子服務架構不再維護</h2>
  115. <p>子服務仍可依本頁所述運作,但不會再有新功能或修正,並可能在日後版本中移除。請勿以子服務開始新專案;本頁僅為已在使用的人保留。新的開發請改用以下方式:</p>
  116. <ul><li><strong>WebApp</strong>:資料夾內的 HTML 與 JavaScript,搭配伺服器端 AGI 腳本存取檔案、資料庫與 ArozOS 的其他功能。</li><li><strong>Container App</strong>:把 Docker 或其他地方執行的任何網頁伺服器,透過 ArozOS 的連接埠發佈並釘選到桌面。</li></ul>
  117. <div class="btns"><a class="btn primary" href="../makers.html"><span>WebApp 與 AGI</span></a><a class="btn secondary" href="../server.html"><span>Container Apps</span></a></div>
  118. </div>
  119. </div>
  120. </div>
  121. </section>
  122. <section class="doc-sec" id="overview">
  123. <div class="wrap narrow">
  124. <div class="doc-head rv">
  125. <p class="eyebrow">概觀</p>
  126. <h2 class="doc-title">由 ArozOS 為您執行的程式</h2>
  127. </div>
  128. <div class="doc-item rv">
  129. <div class="doc-text">子服務是一支獨立的程式,通常是小型網頁伺服器。ArozOS 會把它當作子行程啟動,並在自己的位址下做反向代理。它在核心之外執行,因此可以用 Go、Rust、Python 或任何能提供 HTTP 的語言撰寫,也能使用沙盒化的 AGI JavaScript 執行環境做不到的原生程式碼。</div>
  130. </div>
  131. <div class="doc-item rv">
  132. <div class="doc-text">載入後,它會註冊為一般模組:出現在桌面與開始選單,每位使用者都需要取得權限,與內建的 WebApp 相同。</div>
  133. <p class="note"><strong>小知識:</strong>為子服務而寫的、帶身分驗證的反向代理,後來長成了獨立的反向代理 <a href="https://zoraxy.aroz.org">Zoraxy</a>。</p>
  134. </div>
  135. </div>
  136. </section>
  137. <section class="doc-sec" id="layout">
  138. <div class="wrap narrow">
  139. <div class="doc-head rv">
  140. <h2 class="doc-title">資料夾結構</h2>
  141. <p class="lead">每個子服務都放在 ArozOS 執行檔旁 <code>subservice/</code> 之下自己的資料夾中。執行檔以資料夾命名,並加上平台名稱。</p>
  142. </div>
  143. <div class="doc-item rv">
  144. <div class="cmd"><pre><code>subservice/
  145. demo/
  146. demo.exe Windows
  147. demo_linux_amd64 Linux, x86-64
  148. demo_linux_arm64 Linux, ARM64
  149. demo_darwin_amd64 macOS, Intel
  150. moduleInfo.json optional, see &#34;Describing the module&#34;
  151. web/ anything the service serves</code></pre><button type="button" class="copy" data-copy aria-label="複製" title="複製"><span class="c-copy"><svg class="i" viewBox="0 0 24 24" aria-hidden="true" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><rect x="9" y="9" width="11" height="11" rx="2.5"/><path d="M5.5 15H5a1.5 1.5 0 0 1-1.5-1.5V5A1.5 1.5 0 0 1 5 3.5h8.5A1.5 1.5 0 0 1 15 5v.5"/></svg></span><span class="c-done"><svg class="i" viewBox="0 0 24 24" aria-hidden="true" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><path d="M5 12.5l4.5 4.5L19 7.5"/></svg></span></button></div>
  152. <p class="note">Windows 上為 <code>&lt;資料夾&gt;.exe</code>,其他平台為 <code>&lt;資料夾&gt;_&lt;GOOS&gt;_&lt;GOARCH&gt;</code>。ArozOS 在該服務的資料夾內啟動行程,因此 <code>./web</code> 這類相對路徑可以直接使用。</p>
  153. </div>
  154. </div>
  155. </section>
  156. <section class="doc-sec" id="startup">
  157. <div class="wrap narrow">
  158. <div class="doc-head rv">
  159. <h2 class="doc-title">啟動時會發生什麼事</h2>
  160. </div>
  161. <div class="doc-item rv">
  162. <ul class="doc-list"><li>ArozOS 尋找目前平台的執行檔;沒有的服務會被略過。</li><li>從 <code>moduleInfo.json</code> 讀取模組資訊;若沒有該檔案,則執行 <code>&lt;執行檔&gt; -info</code>,它必須印出下方所述的 JSON 物件後結束。</li><li>再次以下列兩個參數啟動該執行檔,作為持續運行的伺服器,並開始對它做代理。</li></ul>
  163. </div>
  164. <div class="doc-item rv">
  165. <div class="doc-text"><code>-port</code> 是從 <code>12810</code> 起算的下一個可用連接埠。<code>-rpt</code> 是這個 ArozOS 的 AGI 閘道,子服務透過它呼叫回 ArozOS(見下文)。</div>
  166. <div class="cmd"><pre><code>demo_linux_amd64 -port :12810 -rpt http://localhost:8080/api/ajgi/interface</code></pre><button type="button" class="copy" data-copy aria-label="複製" title="複製"><span class="c-copy"><svg class="i" viewBox="0 0 24 24" aria-hidden="true" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><rect x="9" y="9" width="11" height="11" rx="2.5"/><path d="M5.5 15H5a1.5 1.5 0 0 1-1.5-1.5V5A1.5 1.5 0 0 1 5 3.5h8.5A1.5 1.5 0 0 1 15 5v.5"/></svg></span><span class="c-done"><svg class="i" viewBox="0 0 24 24" aria-hidden="true" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><path d="M5 12.5l4.5 4.5L19 7.5"/></svg></span></button></div>
  167. <p class="note">開機時,若某個子服務的模組資訊無法讀取,或要求使用保留路徑,ArozOS 將無法啟動。管理員之後再手動啟動服務時,同樣的問題只會顯示錯誤。</p>
  168. </div>
  169. </div>
  170. </section>
  171. <section class="doc-sec" id="module-info">
  172. <div class="wrap narrow">
  173. <div class="doc-head rv">
  174. <h2 class="doc-title">描述模組</h2>
  175. <p class="lead">模組資訊是一個 JSON 物件,與每個 WebApp 註冊時使用的 <code>ModuleInfo</code> 相同,因此子服務會像其他應用程式一樣出現在桌面上。</p>
  176. </div>
  177. <div class="doc-item rv">
  178. <div class="cmd"><pre><code>{
  179. &#34;Name&#34;: &#34;Demo Subservice&#34;,
  180. &#34;Desc&#34;: &#34;A simple subservice showing how subservices work in ArozOS&#34;,
  181. &#34;Group&#34;: &#34;Development&#34;,
  182. &#34;IconPath&#34;: &#34;demo/icon.png&#34;,
  183. &#34;Version&#34;: &#34;0.0.1&#34;,
  184. &#34;StartDir&#34;: &#34;demo/home.html&#34;,
  185. &#34;SupportFW&#34;: true,
  186. &#34;LaunchFWDir&#34;: &#34;demo/home.html&#34;,
  187. &#34;SupportEmb&#34;: true,
  188. &#34;LaunchEmb&#34;: &#34;demo/embedded.html&#34;,
  189. &#34;InitFWSize&#34;: [720, 480],
  190. &#34;InitEmbSize&#34;: [720, 480],
  191. &#34;SupportedExt&#34;: [&#34;.txt&#34;, &#34;.md&#34;]
  192. }</code></pre><button type="button" class="copy" data-copy aria-label="複製" title="複製"><span class="c-copy"><svg class="i" viewBox="0 0 24 24" aria-hidden="true" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><rect x="9" y="9" width="11" height="11" rx="2.5"/><path d="M5.5 15H5a1.5 1.5 0 0 1-1.5-1.5V5A1.5 1.5 0 0 1 5 3.5h8.5A1.5 1.5 0 0 1 15 5v.5"/></svg></span><span class="c-done"><svg class="i" viewBox="0 0 24 24" aria-hidden="true" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><path d="M5 12.5l4.5 4.5L19 7.5"/></svg></span></button></div>
  193. <p class="note"><code>StartDir</code> 的資料夾部分(此處為 <code>demo</code>)就是代理端點。它不可為空,也不可是保留路徑 <code>web</code>、<code>system</code>、<code>SystemAO</code>、<code>img</code>、<code>STDIN</code>、<code>STDOUT</code>、<code>STDERR</code>、<code>COM</code>、<code>ws</code>、<code>cluster</code> 與 <code>app</code>。</p>
  194. </div>
  195. </div>
  196. </section>
  197. <section class="specs-sec tone-alt">
  198. <div class="wrap narrow">
  199. <div class="sec-head rv">
  200. <h2 class="title">模組欄位</h2>
  201. </div>
  202. <dl class="specs"><div class="spec rv">
  203. <dt>Name</dt>
  204. <dd><p>顯示在桌面上。權限依此名稱授予,請確保它不重複。</p></dd>
  205. </div><div class="spec rv">
  206. <dt>Desc</dt>
  207. <dd><p>簡短說明。</p></dd>
  208. </div><div class="spec rv">
  209. <dt>Group</dt>
  210. <dd><p>開始選單分類:<code>Media</code>、<code>Office</code>、<code>Internet</code>、<code>Engineering</code>、<code>Development</code>、<code>System Tools</code> 或 <code>Utilities</code>;其他值會列在「其他」。<code>Utilities</code> 與 <code>System Tools</code> 對所有使用者開放,其他分類需由權限群組授權。</p></dd>
  211. </div><div class="spec rv">
  212. <dt>IconPath</dt>
  213. <dd><p>圖示,為服務所提供的路徑,例如 <code>demo/icon.png</code>。</p></dd>
  214. </div><div class="spec rv">
  215. <dt>Version</dt>
  216. <dd><p>版本字串,例如 <code>0.0.1</code>。</p></dd>
  217. </div><div class="spec rv">
  218. <dt>StartDir</dt>
  219. <dd><p>以整頁視窗開啟的頁面。其資料夾即為代理端點。</p></dd>
  220. </div><div class="spec rv">
  221. <dt>SupportFW, LaunchFWDir, InitFWSize</dt>
  222. <dd><p>以浮動視窗開啟:是否支援、要載入的頁面,以及起始大小 <code>[寬, 高]</code>。</p></dd>
  223. </div><div class="spec rv">
  224. <dt>SupportEmb, LaunchEmb, InitEmbSize</dt>
  225. <dd><p>嵌入模式,也就是以此模組開啟檔案時載入的模式。設定項目相同。</p></dd>
  226. </div><div class="spec rv">
  227. <dt>SupportedExt</dt>
  228. <dd><p>模組可開啟的副檔名,例如 <code>[".txt", ".md"]</code>,讓它能成為預設開啟程式。</p></dd>
  229. </div></dl>
  230. </div>
  231. </section>
  232. <section class="doc-sec" id="proxy">
  233. <div class="wrap narrow">
  234. <div class="doc-head rv">
  235. <h2 class="doc-title">請求如何送達服務</h2>
  236. </div>
  237. <div class="doc-item rv">
  238. <ul class="doc-list"><li>只有已登入且擁有該模組權限的使用者能通過,其他人會收到 404。</li><li>代理端點資料夾會從路徑中移除:<code>/demo/api/list?a=1</code> 送達服務時是 <code>/api/list?a=1</code>,<code>/demo/</code> 則是 <code>/</code>。因此頁面應使用相對連結,或以端點資料夾開頭的連結;指向 <code>/api/list</code> 的連結會打到 ArozOS 本身。</li><li>ArozOS 會加上三個請求標頭:<code>aouser</code>(使用者名稱)、<code>aotoken</code>(該使用者的權杖)與 <code>X-Forwarded-Host</code>(瀏覽器使用的主機)。</li><li>WebSocket 連線同樣會被代理,這類請求還會帶有 <code>A-Upgrade: websocket</code>。</li><li>若服務停止回應,ArozOS 會記錄下來、終止該行程,並在 10 秒後重新啟動。</li></ul>
  239. <p class="note">這些標頭的可信度取決於連接埠。若服務監聽所有網路介面,任何連得到該連接埠的人都能自行送出 <code>aouser</code>,因此請綁定到 <code>127.0.0.1</code>,或從外部封鎖 <code>12810</code> 起的連接埠。</p>
  240. </div>
  241. </div>
  242. </section>
  243. <section class="doc-sec" id="agi">
  244. <div class="wrap narrow">
  245. <div class="doc-head rv">
  246. <h2 class="doc-title">回呼 ArozOS</h2>
  247. <p class="lead">子服務透過 AGI 閘道(即 <code>-rpt</code> 收到的位址)使用 ArozOS 的功能。以 POST 送出使用者的權杖與一段腳本,腳本會以該使用者的權限在 AGI 執行環境中執行,並將 <code>sendJSONResp</code> 送出的內容作為回應。</p>
  248. </div>
  249. <div class="doc-item rv">
  250. <div class="cmd"><pre><code>func listDesktop(w http.ResponseWriter, r *http.Request) {
  251. token := r.Header.Get(&#34;aotoken&#34;)
  252. script := `
  253. requirelib(&#34;filelib&#34;);
  254. var list = filelib.glob(&#34;user:/Desktop/*&#34;);
  255. sendJSONResp(JSON.stringify(list));
  256. `
  257. // rpt is the value of the -rpt flag
  258. resp, err := http.PostForm(rpt, url.Values{
  259. &#34;token&#34;: {token},
  260. &#34;script&#34;: {script},
  261. })
  262. if err != nil {
  263. http.Error(w, err.Error(), http.StatusBadGateway)
  264. return
  265. }
  266. defer resp.Body.Close()
  267. w.Header().Set(&#34;Content-Type&#34;, &#34;application/json&#34;)
  268. io.Copy(w, resp.Body)
  269. }</code></pre><button type="button" class="copy" data-copy aria-label="複製" title="複製"><span class="c-copy"><svg class="i" viewBox="0 0 24 24" aria-hidden="true" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><rect x="9" y="9" width="11" height="11" rx="2.5"/><path d="M5.5 15H5a1.5 1.5 0 0 1-1.5-1.5V5A1.5 1.5 0 0 1 5 3.5h8.5A1.5 1.5 0 0 1 15 5v.5"/></svg></span><span class="c-done"><svg class="i" viewBox="0 0 24 24" aria-hidden="true" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><path d="M5 12.5l4.5 4.5L19 7.5"/></svg></span></button></div>
  270. <p class="note">表單欄位為 <code>token</code>(請求中的 <code>aotoken</code> 標頭)與 <code>script</code>。僅憑回應的狀態碼無法確定腳本是否成功,請檢查它回傳的內容。</p>
  271. </div>
  272. </div>
  273. </section>
  274. <section class="doc-sec" id="example">
  275. <div class="wrap narrow">
  276. <div class="doc-head rv">
  277. <h2 class="doc-title">最精簡的服務</h2>
  278. <p class="lead">這支 Go 程式會回應 <code>-info</code>、提供 <code>web/</code> 資料夾的內容,並有一個向已登入使用者問好的 API。</p>
  279. </div>
  280. <div class="doc-item rv">
  281. <div class="doc-text">完整的範例包含網頁、AGI 呼叫、圖示,以及各平台的建置腳本,放在範例儲存庫中。</div>
  282. <div class="cmd"><pre><code>package main
  283. import (
  284. &#34;encoding/json&#34;
  285. &#34;flag&#34;
  286. &#34;fmt&#34;
  287. &#34;log&#34;
  288. &#34;net/http&#34;
  289. )
  290. func main() {
  291. info := flag.Bool(&#34;info&#34;, false, &#34;print the module information and exit&#34;)
  292. port := flag.String(&#34;port&#34;, &#34;:8000&#34;, &#34;listen address chosen by ArozOS&#34;)
  293. flag.String(&#34;rpt&#34;, &#34;&#34;, &#34;AGI gateway of ArozOS&#34;)
  294. flag.Parse()
  295. if *info {
  296. b, _ := json.Marshal(map[string]any{
  297. &#34;Name&#34;: &#34;Demo Subservice&#34;,
  298. &#34;Desc&#34;: &#34;A simple subservice&#34;,
  299. &#34;Group&#34;: &#34;Development&#34;,
  300. &#34;IconPath&#34;: &#34;demo/icon.png&#34;,
  301. &#34;Version&#34;: &#34;0.0.1&#34;,
  302. &#34;StartDir&#34;: &#34;demo/home.html&#34;,
  303. &#34;SupportFW&#34;: true,
  304. &#34;LaunchFWDir&#34;: &#34;demo/home.html&#34;,
  305. &#34;InitFWSize&#34;: []int{720, 480},
  306. })
  307. fmt.Println(string(b))
  308. return
  309. }
  310. http.HandleFunc(&#34;/whoami&#34;, func(w http.ResponseWriter, r *http.Request) {
  311. fmt.Fprintln(w, &#34;Hello&#34;, r.Header.Get(&#34;aouser&#34;))
  312. })
  313. http.Handle(&#34;/&#34;, http.FileServer(http.Dir(&#34;./web&#34;)))
  314. log.Println(&#34;demo listening on&#34;, *port)
  315. log.Fatal(http.ListenAndServe(*port, nil))
  316. }</code></pre><button type="button" class="copy" data-copy aria-label="複製" title="複製"><span class="c-copy"><svg class="i" viewBox="0 0 24 24" aria-hidden="true" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><rect x="9" y="9" width="11" height="11" rx="2.5"/><path d="M5.5 15H5a1.5 1.5 0 0 1-1.5-1.5V5A1.5 1.5 0 0 1 5 3.5h8.5A1.5 1.5 0 0 1 15 5v.5"/></svg></span><span class="c-done"><svg class="i" viewBox="0 0 24 24" aria-hidden="true" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><path d="M5 12.5l4.5 4.5L19 7.5"/></svg></span></button></div>
  317. <div class="btns"><a class="btn secondary" href="https://github.com/aroz-online/ArozOS-Subservice-Example" target="_blank" rel="noopener"><svg class="i" viewBox="0 0 16 16" aria-hidden="true" fill="currentColor"><path d="M8 0C3.58 0 0 3.58 0 8c0 3.54 2.29 6.53 5.47 7.59.4.07.55-.17.55-.38 0-.19-.01-.82-.01-1.49-2.01.37-2.53-.49-2.69-.94-.09-.23-.48-.94-.82-1.13-.28-.15-.68-.52-.01-.53.63-.01 1.08.58 1.23.82.72 1.21 1.87.87 2.33.66.07-.52.28-.87.51-1.07-1.78-.2-3.64-.89-3.64-3.95 0-.87.31-1.59.82-2.15-.08-.2-.36-1.02.08-2.12 0 0 .67-.21 2.2.82.64-.18 1.32-.27 2-.27.68 0 1.36.09 2 .27 1.53-1.04 2.2-.82 2.2-.82.44 1.1.16 1.92.08 2.12.51.56.82 1.27.82 2.15 0 3.07-1.87 3.75-3.65 3.95.29.25.54.73.54 1.48 0 1.07-.01 1.93-.01 2.2 0 .21.15.46.55.38A8.013 8.013 0 0016 8c0-4.42-3.58-8-8-8z"/></svg><span>子服務範例</span></a></div>
  318. </div>
  319. </div>
  320. </section>
  321. <section class="specs-sec tone-alt" id="marker-files">
  322. <div class="wrap narrow">
  323. <div class="sec-head rv">
  324. <h2 class="title">標記檔案</h2>
  325. <p class="lead">放在服務資料夾中的空檔案會改變它的啟動方式,每次服務啟動時都會讀取。</p>
  326. </div>
  327. <dl class="specs"><div class="spec rv">
  328. <dt>.disabled</dt>
  329. <dd><p>開機時略過此服務。管理員停止服務時 ArozOS 會自行寫入此檔,再次啟動服務時則會移除。</p></dd>
  330. </div><div class="spec rv">
  331. <dt>.noproxy</dt>
  332. <dd><p>相容模式。程式不帶參數啟動,也不建立代理,適用於並非為 ArozOS 而寫的軟體。</p></dd>
  333. </div><div class="spec rv">
  334. <dt>.startscript</dt>
  335. <dd><p>改為啟動服務資料夾中的 <code>start.sh</code>(Windows 為 <code>start.bat</code>),而不是執行檔,例如用來包裝需要更多參數的程式。腳本會像執行檔一樣收到 <code>-port</code> 與 <code>-rpt</code>。</p></dd>
  336. </div><div class="spec rv">
  337. <dt>.intport</dt>
  338. <dd><p>以 <code>12810</code> 而非 <code>:12810</code> 傳遞連接埠,適用於不接受前置冒號的程式。</p></dd>
  339. </div><div class="spec rv">
  340. <dt>moduleInfo.json</dt>
  341. <dd><p>以檔案提供的模組資訊。存在時,ArozOS 不會以 <code>-info</code> 執行該執行檔。</p></dd>
  342. </div></dl>
  343. </div>
  344. </section>
  345. <section class="doc-sec" id="runtime">
  346. <div class="wrap narrow">
  347. <div class="doc-head rv">
  348. <h2 class="doc-title">管理服務</h2>
  349. <p class="lead">管理員可在系統設定中啟動與停止服務,該頁面使用以下端點:</p>
  350. </div>
  351. <div class="doc-item rv">
  352. <ul class="doc-list"><li><code>/system/subservice/list</code> 列出執行中與已停用的服務。</li><li><code>/system/subservice/kill</code> 停止服務。僅限管理員,表單欄位 <code>serviceDir</code> 為其資料夾名稱。</li><li><code>/system/subservice/start</code> 啟動服務。僅限管理員,欄位相同。</li></ul>
  353. <p class="note">以 <code>-disable_subservice</code> 啟動 ArozOS 即可完全關閉此功能。</p>
  354. </div>
  355. </div>
  356. </section>
  357. <section class="cta">
  358. <div class="wrap narrow rv">
  359. <div class="cta-logo"><svg class="logo" viewBox="0 0 256 256" aria-hidden="true"><rect class="logo-bg" width="256" height="256" rx="58"/><path class="logo-fg" d="M70 58h116l-58 70zM128 128l58 70H70z"/></svg></div>
  360. <h2 class="title">已經在使用子服務?</h2>
  361. <p class="lead">範例儲存庫是了解子服務如何建置的最佳參考。請記得,此架構已不再維護。</p>
  362. <div class="btns center"><a class="btn primary" href="https://github.com/aroz-online/ArozOS-Subservice-Example" target="_blank" rel="noopener"><svg class="i" viewBox="0 0 16 16" aria-hidden="true" fill="currentColor"><path d="M8 0C3.58 0 0 3.58 0 8c0 3.54 2.29 6.53 5.47 7.59.4.07.55-.17.55-.38 0-.19-.01-.82-.01-1.49-2.01.37-2.53-.49-2.69-.94-.09-.23-.48-.94-.82-1.13-.28-.15-.68-.52-.01-.53.63-.01 1.08.58 1.23.82.72 1.21 1.87.87 2.33.66.07-.52.28-.87.51-1.07-1.78-.2-3.64-.89-3.64-3.95 0-.87.31-1.59.82-2.15-.08-.2-.36-1.02.08-2.12 0 0 .67-.21 2.2.82.64-.18 1.32-.27 2-.27.68 0 1.36.09 2 .27 1.53-1.04 2.2-.82 2.2-.82.44 1.1.16 1.92.08 2.12.51.56.82 1.27.82 2.15 0 3.07-1.87 3.75-3.65 3.95.29.25.54.73.54 1.48 0 1.07-.01 1.93-.01 2.2 0 .21.15.46.55.38A8.013 8.013 0 0016 8c0-4.42-3.58-8-8-8z"/></svg><span>子服務範例</span></a><a class="btn secondary" href="../makers.html"><span>改為開發 WebApp</span></a></div>
  363. </div>
  364. </section>
  365. </main>
  366. <footer class="foot">
  367. <div class="wrap">
  368. <div class="foot-top">
  369. <div class="foot-brand">
  370. <a class="brand" href="../" aria-label="ArozOS"><svg class="logo" viewBox="0 0 256 256" aria-hidden="true"><rect class="logo-bg" width="256" height="256" rx="58"/><path class="logo-fg" d="M70 58h116l-58 70zM128 128l58 70H70z"/></svg><span>ArozOS</span></a>
  371. <p>為您自己的伺服器而生的網頁桌面。</p>
  372. </div>
  373. <div class="foot-col">
  374. <h2>探索</h2>
  375. <ul><li><a href="../desktop.html">桌面</a></li><li><a href="../media.html">影音</a></li><li><a href="../office.html">辦公</a></li><li><a href="../ai.html">AI</a></li><li><a href="../makers.html">創客</a></li><li><a href="../storage.html">儲存</a></li><li><a href="../server.html">伺服器</a></li><li><a href="../download.html">下載</a></li></ul>
  376. </div>
  377. <div class="foot-col">
  378. <h2>開發者</h2>
  379. <ul><li><a href="https://aroz-online.github.io/ArozOS-Developers/" target="_blank" rel="noopener">AGI 開發文件</a></li><li><a href="https://github.com/aroz-online/WebApp-and-Subservice-Index" target="_blank" rel="noopener">WebApp 與子服務</a></li><li><a href="./">子服務(已棄用)</a></li><li><a href="https://github.com/aroz-online/ArozOS-Subservice-Example" target="_blank" rel="noopener">子服務範例</a></li><li><a href="../../ArozOS-Cluster-Whitepaper.pdf">叢集白皮書</a></li><li><a href="https://github.com/aroz-online/launcher" target="_blank" rel="noopener">ArozOS Launcher</a></li></ul>
  380. </div>
  381. <div class="foot-col">
  382. <h2>社群</h2>
  383. <ul><li><a href="https://github.com/tobychui/arozos" target="_blank" rel="noopener">原始碼</a></li><li><a href="https://github.com/tobychui/arozos/releases" target="_blank" rel="noopener">發行版本</a></li><li><a href="https://github.com/tobychui/arozos/issues" target="_blank" rel="noopener">回報問題</a></li><li><a href="https://t.me/ArOZBeta" target="_blank" rel="noopener">Telegram</a></li><li><a href="mailto:toby@imuslab.com">電子郵件</a></li></ul>
  384. </div>
  385. <div class="foot-col">
  386. <h2>相關專案</h2>
  387. <ul><li><a href="https://zoraxy.aroz.org" target="_blank" rel="noopener">Zoraxy</a></li><li><a href="https://github.com/tobychui/imusutm" target="_blank" rel="noopener">imusutm</a></li><li><a href="https://github.com/tobychui/SlicerA" target="_blank" rel="noopener">Slicer A</a></li><li><a href="https://github.com/SysAdmin74/ArozOS-Docker" target="_blank" rel="noopener">ArozOS Docker(社群)</a></li><li><a href="https://imuslab.com" target="_blank" rel="noopener">imuslab</a></li></ul>
  388. </div>
  389. </div>
  390. <div class="foot-bottom">
  391. <p>版權所有 © 2016–<span data-year>2026</span> Toby Chui feat. imuslab. 香港製造。 以 <a href="https://github.com/tobychui/arozos/blob/master/LICENSE">GPLv3</a> 授權開源。</p>
  392. <div class="foot-ctl">
  393. <div class="seg sm" role="menu" aria-label="外觀"><button type="button" role="menuitemradio" data-theme-set="light" aria-checked="false"><svg class="i" viewBox="0 0 24 24" aria-hidden="true" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="4"/><path d="M12 2.5v2M12 19.5v2M5.3 5.3l1.4 1.4M17.3 17.3l1.4 1.4M2.5 12h2M19.5 12h2M5.3 18.7l1.4-1.4M17.3 6.7l1.4-1.4"/></svg><span>淺色</span></button><button type="button" role="menuitemradio" data-theme-set="dark" aria-checked="false"><svg class="i" viewBox="0 0 24 24" aria-hidden="true" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><path d="M20.5 14.5A8.5 8.5 0 0 1 9.5 3.5a8.5 8.5 0 1 0 11 11z"/></svg><span>深色</span></button><button type="button" role="menuitemradio" data-theme-set="auto" aria-checked="false"><svg class="i" viewBox="0 0 24 24" aria-hidden="true" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="8.5"/><path d="M12 3.5a8.5 8.5 0 0 1 0 17z" fill="currentColor"/></svg><span>自動</span></button></div>
  394. <div class="foot-langs" role="menu" aria-label="語言"><a role="menuitemradio" href="../../subservice/" hreflang="en" lang="en" data-lang="en" aria-checked="false">English</a><a role="menuitemradio" href="./" hreflang="zh-Hant" lang="zh-Hant" data-lang="zh-Hant" aria-checked="true">繁體中文</a><a role="menuitemradio" href="../../zh-cn/subservice/" hreflang="zh-Hans" lang="zh-Hans" data-lang="zh-Hans" aria-checked="false">简体中文</a><a role="menuitemradio" href="../../ja/subservice/" hreflang="ja" lang="ja" data-lang="ja" aria-checked="false">日本語</a></div>
  395. </div>
  396. </div>
  397. </div>
  398. </footer>
  399. </body>
  400. </html>