Sfoglia il codice sorgente

websocketKey editing in settings

marek 1 mese fa
parent
commit
4d6273db77
5 ha cambiato i file con 22 aggiunte e 6 eliminazioni
  1. 2 1
      lang/en.js
  2. 2 1
      lang/sk.js
  3. 8 4
      routes/include/main.js
  4. 5 0
      templates/en/settings.eta
  5. 5 0
      templates/sk/settings.eta

+ 2 - 1
lang/en.js

@@ -36,7 +36,8 @@ const icons = {
 export default {
     settings: {
         errors: {
-            noCloudURL: () => `you need to provide a cloud url.`
+            noCloudURL: () => `you need to provide a cloud url.`,
+            noWebsocketKey: () => `you need to provide a websocket key.`
         }
     },
 

+ 2 - 1
lang/sk.js

@@ -36,7 +36,8 @@ const icons = {
 export default {
     settings: {
         errors: {
-            noCloudURL: () => `musíte zadať cloud url.`
+            noCloudURL: () => `musíte zadať cloud url.`,
+            noWebsocketKey: () => `musíte zadať websocket kľúč.`
         }
     },
 

+ 8 - 4
routes/include/main.js

@@ -16,22 +16,26 @@ export default (langName, lang) => new Elysia()
   })
   .get('/settings', ({ set }) => {
     set.headers['content-type'] = 'text/html; charset=utf8'
-    return eta.render(`${langName}/settings`, { wifiIPv4: getWifiIPv4(), postDataEnabled: process.env.POST_DATA_ENABLED, cloudURL: process.env.BACKEND_URL })
+    return eta.render(`${langName}/settings`, { wifiIPv4: getWifiIPv4(), postDataEnabled: process.env.POST_DATA_ENABLED, cloudURL: process.env.BACKEND_URL, websocketKey: BACKEND_WEBSOCKET_KEY })
   })
   .post('/settings', async ({ body, set, redirect }) => {
     const postDataEnabled = body?.postDataEnabled
     const cloudURL = body?.cloudURL
-
-    postDataEnabled?.replaceAll(`"`, ``)
-    cloudURL?.replaceAll(`"`, ``)
+    const websocketKey = body?.websocketKey
 
     if (!cloudURL) {
       set.headers['content-type'] = 'text/html; charset=utf8'
       return eta.render(`${langName}/settings`, { wifiIPv4: getWifiIPv4(), lang, error: `noCloudURL` })
     }
+
+    if (!websocketKey) {
+      set.headers['content-type'] = 'text/html; charset=utf8'
+      return eta.render(`${langName}/settings`, { wifiIPv4: getWifiIPv4(), lang, error: `noWebsocketKey` })
+    }
     
     await editEnvVariable(`POST_DATA_ENABLED`, postDataEnabled ?? "false")
     await editEnvVariable(`BACKEND_URL`, cloudURL)
+    await editEnvVariable(`BACKEND_WEBSOCKET_KEY`, websocketKey)
 
     return redirect(`${langName === `sk` ? `/` : `/en`}`)
   })

+ 5 - 0
templates/en/settings.eta

@@ -45,5 +45,10 @@
       <input type="text" id="cloudURL" name="cloudURL" placeholder="wss://meteostanica.com" value="<%= it.cloudURL ?? `wss://meteostanica.com` %>">
     </div>
 
+    <div>
+      <label for="websocketKey">websocket key</label>
+      <input type="text" id="websocketKey" name="websocketKey" value="<%= it.websocketKey ?? `` %>">
+    </div>
+
     <button type="submit">save</button>
 </form>

+ 5 - 0
templates/sk/settings.eta

@@ -45,5 +45,10 @@
       <input type="text" id="cloudURL" name="cloudURL" placeholder="wss://meteostanica.com" value="<%= it.cloudURL ?? `wss://meteostanica.com` %>">
     </div>
 
+    <div>
+      <label for="websocketKey">websocket kľúč</label>
+      <input type="text" id="websocketKey" name="websocketKey" value="<%= it.websocketKey ?? `` %>">
+    </div>
+
     <button type="submit">uložiť</button>
 </form>