settings_view.js 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  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. ];
  34. const languageOption = (longName, shortName) => {
  35. return shortName === selectedLanguage
  36. ? option({ value: shortName, selected: true }, longName)
  37. : option({ value: shortName }, longName);
  38. };
  39. const rebuildButton = form(
  40. { action: "/settings/rebuild", method: "post" },
  41. button({ type: "submit" }, i18n.rebuildName)
  42. );
  43. const updateFlagPath = path.join(__dirname, '../server/.update_required');
  44. let updateButton = null;
  45. if (fs.existsSync(updateFlagPath)) {
  46. updateButton = form(
  47. { action: "/update", method: "post" },
  48. button({ type: "submit" }, i18n.updateit)
  49. );
  50. }
  51. return template(
  52. i18n.settings,
  53. section(
  54. div({ class: "tags-header" },
  55. h2(i18n.settings),
  56. p(a({ href: snhUrl, target: "_blank" }, i18n.settingsIntro({ version }))),
  57. updateButton
  58. )
  59. ),
  60. section(
  61. div({ class: "tags-header" },
  62. h2(i18n.theme),
  63. p(i18n.themeIntro),
  64. form(
  65. { action: "/settings/theme", method: "post" },
  66. select({ name: "theme" }, ...themeElements),
  67. br(),
  68. br(),
  69. button({ type: "submit" }, i18n.setTheme)
  70. )
  71. )
  72. ),
  73. section(
  74. div({ class: "tags-header" },
  75. h2(i18n.language),
  76. p(i18n.languageDescription),
  77. form(
  78. { action: "/language", method: "post" },
  79. select({ name: "language" }, [
  80. languageOption("English", "en"),
  81. languageOption("Castellano", "es"),
  82. languageOption("Euskara", "eu")
  83. ]),
  84. br(),
  85. br(),
  86. button({ type: "submit" }, i18n.setLanguage)
  87. )
  88. )
  89. ),
  90. section(
  91. div({ class: "tags-header" },
  92. h2(i18n.wallet),
  93. p(
  94. i18n.walletSettingsDescription, " ",
  95. a({ href: "docs/ecoin.md", target: "_blank", rel: "noopener" }, `[${i18n.walletSettingsDocLink}]`)
  96. ),
  97. form(
  98. { action: "/settings/wallet", method: "POST" },
  99. label({ for: "wallet_url" }, i18n.walletAddress), br(),
  100. input({ type: "text", id: "wallet_url", name: "wallet_url", placeholder: walletUrl, value: walletUrl }), br(),
  101. label({ for: "wallet_user" }, i18n.walletUser), br(),
  102. input({ type: "text", id: "wallet_user", name: "wallet_user", placeholder: walletUser, value: walletUser }), br(),
  103. label({ for: "wallet_pass" }, i18n.walletPass), br(),
  104. input({ type: "password", id: "wallet_pass", name: "wallet_pass" }), br(),
  105. label({ for: "wallet_fee" }, i18n.walletFee), br(),
  106. input({ type: "text", id: "wallet_fee", name: "wallet_fee", placeholder: walletFee, value: walletFee }), br(),
  107. button({ type: "submit" }, i18n.walletConfiguration)
  108. )
  109. )
  110. ),
  111. section(
  112. div({ class: "tags-header" },
  113. h2(i18n.pubWallet),
  114. p(i18n.pubWalletDescription),
  115. form(
  116. { action: "/settings/pub-wallet", method: "POST" },
  117. label({ for: "pub_wallet_url" }, i18n.walletAddress), br(),
  118. input({
  119. type: "text",
  120. id: "pub_wallet_url",
  121. name: "wallet_url",
  122. placeholder: pubWalletUrl,
  123. value: pubWalletUrl
  124. }), br(),
  125. label({ for: "pub_wallet_user" }, i18n.walletUser), br(),
  126. input({
  127. type: "text",
  128. id: "pub_wallet_user",
  129. name: "wallet_user",
  130. placeholder: pubWalletUser,
  131. value: pubWalletUser
  132. }), br(),
  133. label({ for: "pub_wallet_pass" }, i18n.walletPass), br(),
  134. input({
  135. type: "password",
  136. id: "pub_wallet_pass",
  137. name: "wallet_pass"
  138. }), br(),
  139. button({ type: "submit" }, i18n.pubWalletConfiguration)
  140. )
  141. )
  142. ),
  143. section(
  144. div({ class: "tags-header" },
  145. h2(i18n.aiTitle),
  146. p(i18n.aiSettingsDescription),
  147. form(
  148. { action: "/settings/ai", method: "POST" },
  149. input({
  150. type: "text",
  151. id: "ai_prompt",
  152. name: "ai_prompt",
  153. placeholder: aiPrompt,
  154. value: aiPrompt,
  155. maxlength: "128",
  156. required: true
  157. }), br(),
  158. button({ type: "submit" }, i18n.aiConfiguration)
  159. )
  160. )
  161. ),
  162. section(
  163. div({ class: "tags-header" },
  164. h2(i18n.ssbLogStream),
  165. p(i18n.ssbLogStreamDescription),
  166. form(
  167. { action: "/settings/ssb-logstream", method: "POST" },
  168. input({
  169. type: "number",
  170. id: "ssb_log_limit",
  171. name: "ssb_log_limit",
  172. min: 1,
  173. max: 100000,
  174. value: currentConfig.ssbLogStream?.limit || 1000
  175. }), br(),br(),
  176. button({ type: "submit" }, i18n.saveSettings)
  177. )
  178. )
  179. ),
  180. section(
  181. div({ class: "tags-header" },
  182. h2(i18n.indexes),
  183. p(i18n.indexesDescription),
  184. rebuildButton
  185. )
  186. ),
  187. section(
  188. div({ class: "tags-header" },
  189. h2(i18n.exportDataTitle),
  190. p(i18n.exportDataDescription),
  191. form(
  192. { action: "/export/create", method: "POST", id: "exportForm" },
  193. button({ type: "submit" }, i18n.exportDataButton)
  194. )
  195. )
  196. ),
  197. section(
  198. div({ class: "tags-header" },
  199. h2(i18n.panicMode),
  200. p(i18n.removeDataDescription),
  201. form(
  202. { action: "/panic/remove", method: "POST", id: "removeForm" },
  203. button({ type: "submit" }, i18n.removePanicButton)
  204. )
  205. )
  206. )
  207. );
  208. };
  209. exports.settingsView = settingsView;