Pārlūkot izejas kodu

try fix docker mount problem

Help-14 3 gadi atpakaļ
vecāks
revīzija
920339e94c

+ 3 - 4
docker-compose.yml

@@ -2,9 +2,8 @@ services:
   magma:
   magma:
     container_name: magma
     container_name: magma
     image: help14/magma
     image: help14/magma
-    restart: always
+    restart: unless-stopped
     volumes:
     volumes:
-      - ./common:/app/common
-      #- ./themes/custom:/app/themes/custom
+      - ./data/:/app/data
     ports:
     ports:
-      - '7001:7001'
+      - '7001:7001'

+ 4 - 14
src/main.go

@@ -1,7 +1,6 @@
 package main
 package main
 
 
 import (
 import (
-	"errors"
 	"html/template"
 	"html/template"
 	"io/ioutil"
 	"io/ioutil"
 	"log"
 	"log"
@@ -30,7 +29,7 @@ func main() {
 	websiteData.Language = modules.LoadLanguage(appConfig.Website.Language)
 	websiteData.Language = modules.LoadLanguage(appConfig.Website.Language)
 	websiteData.Contents = modules.LoadContent().Data
 	websiteData.Contents = modules.LoadContent().Data
 
 
-	commonfs := http.FileServer(http.Dir(filepath.Join(pwd, "common")))
+	commonfs := http.FileServer(http.Dir(filepath.Join(pwd, "data")))
 	http.Handle("/common/", http.StripPrefix("/common/", commonfs))
 	http.Handle("/common/", http.StripPrefix("/common/", commonfs))
 
 
 	languagefs := http.FileServer(http.Dir(filepath.Join(pwd, "languages")))
 	languagefs := http.FileServer(http.Dir(filepath.Join(pwd, "languages")))
@@ -78,16 +77,7 @@ func serveTemplate(w http.ResponseWriter, r *http.Request) {
 }
 }
 
 
 func prepareSampleFiles() {
 func prepareSampleFiles() {
-	files, err := ioutil.ReadDir(filepath.Join(pwd, "sample"))
-	if err != nil {
-		log.Fatal(err)
-		return
-	}
-	for _, file := range files {
-		samplePath := filepath.Join(pwd, "sample", file.Name())
-		commonPath := filepath.Join(pwd, "common", file.Name())
-		if _, err := os.Stat(commonPath); errors.Is(err, os.ErrNotExist) {
-			modules.CopyFile(samplePath, commonPath)
-		}
-	}
+	commonPath := filepath.Join(pwd, "common")
+	dataPath := filepath.Join(pwd, "data")
+	modules.CopyDirectory(commonPath, dataPath)
 }
 }

+ 7 - 1
src/modules/file.go

@@ -4,9 +4,10 @@ import (
 	"io"
 	"io"
 	"log"
 	"log"
 	"os"
 	"os"
+	"os/exec"
 )
 )
 
 
-func CopyFile(src string, dst string) {
+func CopyFile(src, dst string) {
 	fin, err := os.Open(src)
 	fin, err := os.Open(src)
 	if err != nil {
 	if err != nil {
 		log.Fatal(err)
 		log.Fatal(err)
@@ -25,3 +26,8 @@ func CopyFile(src string, dst string) {
 		log.Fatal(err)
 		log.Fatal(err)
 	}
 	}
 }
 }
+
+func CopyDirectory(oldDir, newDir string) {
+	cmd := exec.Command("cp", "--recursive", oldDir, newDir)
+	cmd.Run()
+}

+ 0 - 12
src/sample/config.yaml

@@ -1,12 +0,0 @@
-website:
-  theme: "flame"
-  title: "Magma Dashboard"
-  description: ""
-  language: "en"
-  localization: "en-US"
-  useMetric: true
-openweathermap:
-  apiKey:
-  lon:
-  lat:
-addons:

+ 0 - 67
src/sample/data.yaml

@@ -1,67 +0,0 @@
-data:
-  - title: Applications
-    columns:
-      - title: Servers
-        bookmarks:
-          - name: OpenWRT
-            icon: fa-solid fa-wifi
-            url: https://openwrt.org
-          - name: Proxmox
-            icon: fa-solid fa-rectangle-xmark
-            url: https://www.proxmox.com/en/
-          - name: Home Assistant
-            icon: fa-solid fa-house
-            url: https://www.home-assistant.io
-          - name: Docker
-            icon: fa-brands fa-docker
-            url: https://www.docker.com
-      - title: Nas
-        bookmarks:
-          - name: TrueNas
-            icon: fa-solid fa-server
-            url: https://www.truenas.com
-          - name: Kerberos
-            icon: fa-solid fa-video
-            url: https://kerberos.io
-          - name: jDownloader
-            icon: fa-solid fa-cloud-arrow-down
-            url: https://jdownloader.org
-      - title: Monitoring
-        bookmarks:
-          - name: Grafana
-            icon: fa-solid fa-server
-            url: https://grafana.com
-          - name: InfluxDb
-            icon: fa-solid fa-database
-            url: https://www.influxdata.com
-      - title: Tools
-        bookmarks:
-          - name: Bitwarden
-            icon: fa-solid fa-shield-halved
-            url: https://bitwarden.com
-  - title: Bookmarks
-    columns:
-      - title: Social Media
-        bookmarks:
-          - name: Facebook
-            icon: fa-brands fa-facebook
-            url: https://www.facebook.com
-          - name: Reddit
-            icon: fa-brands fa-reddit
-            url: https://www.reddit.com
-          - name: Youtube
-            icon: fa-brands fa-youtube
-            url: https://www.youtube.com
-      - title: Shopping
-        bookmarks:
-          - name: Shopee
-            icon: fa-solid fa-bag-shopping
-            url: https://shopee.vn
-          - name: Lazada
-            icon: fa-brands fa-amazon
-            url: https://www.amazon.com
-      - title: Tools
-        bookmarks:
-          - name: Maps
-            icon: fa-solid fa-map
-            url: https://www.google.com/maps

+ 2 - 1
src/themes/flame/index.html

@@ -8,7 +8,7 @@
     <meta name="viewport" content="width=device-width, initial-scale=1">
     <meta name="viewport" content="width=device-width, initial-scale=1">
 
 
     <link rel="icon" type="image/png" href="/common/assets/favicon.ico" />
     <link rel="icon" type="image/png" href="/common/assets/favicon.ico" />
-    
+
     <link rel="stylesheet" href="/theme/css/font.css">
     <link rel="stylesheet" href="/theme/css/font.css">
     <link rel="stylesheet" href="/theme/css/normalize.min.css">
     <link rel="stylesheet" href="/theme/css/normalize.min.css">
     <link rel="stylesheet" href="/theme/css/skeleton.min.css">
     <link rel="stylesheet" href="/theme/css/skeleton.min.css">
@@ -103,6 +103,7 @@
         (async function loadWeather() {
         (async function loadWeather() {
             // Get info from api
             // Get info from api
             const weather = await (await fetch("./weather")).json();
             const weather = await (await fetch("./weather")).json();
+            if(!weather) return;
             // Parse weather id
             // Parse weather id
             let icon = null;
             let icon = null;
             let isDay = Date.now().hour >= 6 && Date.now().hour < 18;
             let isDay = Date.now().hour >= 6 && Date.now().hour < 18;