settings_view.js 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  1. const { form, button, div, h2, p, section, select, option, input, br, a, label } = require("../server/node_modules/hyperaxe");
  2. const fs = require('fs');
  3. const path = require('path');
  4. const { getConfig } = require('../configs/config-manager.js');
  5. const { template, selectedLanguage, i18n, setLanguage } = require('./main_views');
  6. const i18nBase = require("../client/assets/translations/i18n");
  7. const snhUrl = "https://wiki.solarnethub.com/socialnet/overview";
  8. const themeFilePath = path.join(__dirname, '../configs/oasis-config.json');
  9. const getThemeConfig = () => {
  10. try {
  11. const configData = fs.readFileSync(themeFilePath);
  12. return JSON.parse(configData);
  13. } catch (error) {
  14. console.error('Error reading config file:', error);
  15. return {};
  16. }
  17. };
  18. const settingsView = ({ version, aiPrompt }) => {
  19. const currentThemeConfig = getThemeConfig();
  20. const theme = currentThemeConfig.themes?.current || "Dark-SNH";
  21. const currentConfig = getConfig();
  22. const walletUrl = currentConfig.wallet.url;
  23. const walletUser = currentConfig.wallet.user;
  24. const walletFee = currentConfig.wallet.fee;
  25. const pubWalletUrl = currentConfig.walletPub.url || '';
  26. const pubWalletUser = currentConfig.walletPub.user || '';
  27. const pubWalletPass = currentConfig.walletPub.pass || '';
  28. const themeElements = [
  29. option({ value: "Dark-SNH", selected: theme === "Dark-SNH" ? true : undefined }, "Dark-SNH"),
  30. option({ value: "Clear-SNH", selected: theme === "Clear-SNH" ? true : undefined }, "Clear-SNH"),
  31. option({ value: "Purple-SNH", selected: theme === "Purple-SNH" ? true : undefined }, "Purple-SNH"),
  32. option({ value: "Matrix-SNH", selected: theme === "Matrix-SNH" ? true : undefined }, "Matrix-SNH"),
  33. option({ value: "OasisMobile", selected: theme === "OasisMobile" ? true : undefined }, "Oasis-Mobile")
  34. ];
  35. const languageOption = (longName, shortName) => {
  36. return shortName === selectedLanguage
  37. ? option({ value: shortName, selected: true }, longName)
  38. : option({ value: shortName }, longName);
  39. };
  40. const rebuildButton = form(
  41. { action: "/settings/rebuild", method: "post" },
  42. button({ type: "submit" }, i18n.rebuildName)
  43. );
  44. const updateFlagPath = path.join(__dirname, '../server/.update_required');
  45. let updateButton = null;
  46. if (fs.existsSync(updateFlagPath)) {
  47. updateButton = form(
  48. { action: "/update", method: "post" },
  49. button({ type: "submit" }, i18n.updateit)
  50. );
  51. }
  52. return template(
  53. i18n.settings,
  54. section(
  55. div({ class: "tags-header" },
  56. h2(i18n.settings),
  57. p(a({ href: snhUrl, target: "_blank" }, i18n.settingsIntro({ version }))),
  58. updateButton
  59. )
  60. ),
  61. section(
  62. div({ class: "tags-header" },
  63. h2(i18n.theme),
  64. p(i18n.themeIntro),
  65. form(
  66. { action: "/settings/theme", method: "post" },
  67. select({ name: "theme" }, ...themeElements),
  68. br(),
  69. br(),
  70. button({ type: "submit" }, i18n.setTheme)
  71. )
  72. )
  73. ),
  74. section(
  75. div({ class: "tags-header" },
  76. h2(i18n.language),
  77. p(i18n.languageDescription),
  78. form(
  79. { action: "/language", method: "post" },
  80. select({ name: "language" }, [
  81. languageOption("English", "en"),
  82. languageOption("Español", "es"),
  83. languageOption("Français", "fr"),
  84. languageOption("Euskara", "eu"),
  85. languageOption("Deutsch", "de"),
  86. languageOption("Italiano", "it"),
  87. languageOption("Português", "pt"),
  88. languageOption("中文", "zh"),
  89. languageOption("العربية", "ar"),
  90. languageOption("हिन्दी", "hi"),
  91. languageOption("Русский", "ru")
  92. ]),
  93. br(),
  94. br(),
  95. button({ type: "submit" }, i18n.setLanguage)
  96. )
  97. )
  98. ),
  99. section(
  100. div({ class: "tags-header" },
  101. h2(i18n.homePageTitle),
  102. p(i18n.homePageDescription),
  103. form(
  104. { action: "/settings/home-page", method: "POST" },
  105. select({ name: "homePage" },
  106. option({ value: "activity", selected: currentConfig.homePage === "activity" ? true : undefined }, i18n.activityTitle),
  107. option({ value: "ai", selected: currentConfig.homePage === "ai" ? true : undefined }, i18n.aiTitle),
  108. option({ value: "trending", selected: currentConfig.homePage === "trending" ? true : undefined }, i18n.trendingTitle),
  109. option({ value: "opinions", selected: currentConfig.homePage === "opinions" ? true : undefined }, i18n.opinionsTitle),
  110. option({ value: "forum", selected: currentConfig.homePage === "forum" ? true : undefined }, i18n.forumTitle),
  111. option({ value: "feed", selected: currentConfig.homePage === "feed" ? true : undefined }, i18n.feedTitle),
  112. option({ value: "mentions", selected: currentConfig.homePage === "mentions" ? true : undefined }, i18n.mentions),
  113. option({ value: "inbox", selected: currentConfig.homePage === "inbox" ? true : undefined }, i18n.inbox),
  114. option({ value: "agenda", selected: currentConfig.homePage === "agenda" ? true : undefined }, i18n.agendaTitle),
  115. option({ value: "favorites", selected: currentConfig.homePage === "favorites" ? true : undefined }, i18n.favoritesTitle),
  116. option({ value: "stats", selected: currentConfig.homePage === "stats" ? true : undefined }, i18n.statsTitle),
  117. option({ value: "blockexplorer", selected: currentConfig.homePage === "blockexplorer" ? true : undefined }, i18n.blockchain)
  118. ),
  119. br(), br(),
  120. button({ type: "submit" }, i18n.saveHomePage)
  121. )
  122. )
  123. ),
  124. section(
  125. div({ class: "tags-header" },
  126. h2(i18n.ssbLogStream),
  127. p(i18n.ssbLogStreamDescription),
  128. form(
  129. { action: "/settings/ssb-logstream", method: "POST" },
  130. input({
  131. type: "number",
  132. id: "ssb_log_limit",
  133. name: "ssb_log_limit",
  134. min: 1,
  135. max: 100000,
  136. value: currentConfig.ssbLogStream?.limit || 1000
  137. }), br(),br(),
  138. button({ type: "submit" }, i18n.saveSettings)
  139. )
  140. )
  141. ),
  142. section(
  143. div({ class: "tags-header" },
  144. h2(i18n.wallet),
  145. p(
  146. i18n.walletSettingsDescription, " ",
  147. a({ href: "docs/ecoin.md", target: "_blank", rel: "noopener" }, `[${i18n.walletSettingsDocLink}]`)
  148. ),
  149. form(
  150. { action: "/settings/wallet", method: "POST" },
  151. label({ for: "wallet_url" }, i18n.walletAddress), br(),
  152. input({ type: "text", id: "wallet_url", name: "wallet_url", placeholder: walletUrl, value: walletUrl }), br(),
  153. label({ for: "wallet_user" }, i18n.walletUser), br(),
  154. input({ type: "text", id: "wallet_user", name: "wallet_user", placeholder: walletUser, value: walletUser }), br(),
  155. label({ for: "wallet_pass" }, i18n.walletPass), br(),
  156. input({ type: "password", id: "wallet_pass", name: "wallet_pass" }), br(),
  157. label({ for: "wallet_fee" }, i18n.walletFee), br(),
  158. input({ type: "text", id: "wallet_fee", name: "wallet_fee", placeholder: walletFee, value: walletFee }), br(),
  159. button({ type: "submit" }, i18n.walletConfiguration)
  160. )
  161. )
  162. ),
  163. section(
  164. div({ class: "tags-header" },
  165. h2(i18n.pubWallet),
  166. p(i18n.pubWalletDescription),
  167. form(
  168. { action: "/settings/pub-wallet", method: "POST" },
  169. label({ for: "pub_wallet_url" }, i18n.walletAddress), br(),
  170. input({
  171. type: "text",
  172. id: "pub_wallet_url",
  173. name: "wallet_url",
  174. placeholder: pubWalletUrl,
  175. value: pubWalletUrl
  176. }), br(),
  177. label({ for: "pub_wallet_user" }, i18n.walletUser), br(),
  178. input({
  179. type: "text",
  180. id: "pub_wallet_user",
  181. name: "wallet_user",
  182. placeholder: pubWalletUser,
  183. value: pubWalletUser
  184. }), br(),
  185. label({ for: "pub_wallet_pass" }, i18n.walletPass), br(),
  186. input({
  187. type: "password",
  188. id: "pub_wallet_pass",
  189. name: "wallet_pass"
  190. }), br(),
  191. button({ type: "submit" }, i18n.pubWalletConfiguration)
  192. )
  193. )
  194. ),
  195. section(
  196. div({ class: "tags-header" },
  197. h2(i18n.aiTitle),
  198. p(i18n.aiSettingsDescription),
  199. form(
  200. { action: "/settings/ai", method: "POST" },
  201. input({
  202. type: "text",
  203. id: "ai_prompt",
  204. name: "ai_prompt",
  205. placeholder: aiPrompt,
  206. value: aiPrompt,
  207. maxlength: "128",
  208. required: true
  209. }), br(),
  210. button({ type: "submit" }, i18n.aiConfiguration)
  211. )
  212. )
  213. ),
  214. section(
  215. div({ class: "tags-header" },
  216. h2(i18n.indexes),
  217. p(i18n.indexesDescription),
  218. rebuildButton
  219. )
  220. ),
  221. section(
  222. div({ class: "tags-header" },
  223. h2(i18n.exportDataTitle),
  224. p(i18n.exportDataDescription),
  225. form(
  226. { action: "/export/create", method: "POST", id: "exportForm" },
  227. button({ type: "submit" }, i18n.exportDataButton)
  228. )
  229. )
  230. ),
  231. section(
  232. div({ class: "tags-header" },
  233. h2(i18n.panicMode),
  234. p(i18n.removeDataDescription),
  235. form(
  236. { action: "/panic/remove", method: "POST", id: "removeForm" },
  237. button({ type: "submit" }, i18n.removePanicButton)
  238. )
  239. )
  240. )
  241. );
  242. };
  243. exports.settingsView = settingsView;