Compare commits
3 Commits
4904589086
...
v0.0.19
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0eb781a6d3 | ||
|
|
9150550609 | ||
|
|
84abf6b820 |
@@ -98,9 +98,12 @@ jobs:
|
||||
# 2. Create Directory Structure
|
||||
mkdir -p $BUILD_DIR/usr/bin
|
||||
mkdir -p $BUILD_DIR/usr/share/$PKG_NAME
|
||||
mkdir -p $BUILD_DIR/usr/share/$PKG_NAME/data
|
||||
mkdir -p $BUILD_DIR/etc/systemd/system
|
||||
mkdir -p $BUILD_DIR/DEBIAN
|
||||
|
||||
chown -R "$REAL_USER:$REAL_USER" /usr/share/slideshowapp/data
|
||||
|
||||
# 3. Copy Files
|
||||
cp ${APP_NAME} $BUILD_DIR/usr/bin/$PKG_NAME
|
||||
cp -r ./web $BUILD_DIR/usr/share/$PKG_NAME/
|
||||
@@ -115,14 +118,14 @@ jobs:
|
||||
|
||||
# 5. Create a Template Autostart File (Instead of Systemd)
|
||||
mkdir -p $BUILD_DIR/usr/share/$PKG_NAME/setup
|
||||
cat <<EOF > $BUILD_DIR/usr/share/$PKG_NAME/setup/$PKG_NAME.desktop
|
||||
cat <<'EOF' > $BUILD_DIR/usr/share/$PKG_NAME/setup/$PKG_NAME.desktop
|
||||
[Desktop Entry]
|
||||
Type=Application
|
||||
Name=Slideshow App
|
||||
Exec=sh -c ' \
|
||||
i=0; \
|
||||
while [ $i -lt 30 ]; do \
|
||||
if [ "$(ls -A "/media/$REAL_USER" 2>/dev/null)" ] && ping -c 1 -W 1 8.8.8.8 >/dev/null 2>&1; then \
|
||||
if [ "$(ls -A /media/$USER 2>/dev/null)" ] && ping -c 1 -W 1 8.8.8.8 >/dev/null 2>&1; then \
|
||||
break; \
|
||||
fi; \
|
||||
i=$((i+1)); \
|
||||
|
||||
@@ -4,20 +4,36 @@ import (
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
"os"
|
||||
"slideshowApp/utils"
|
||||
)
|
||||
|
||||
type Schedule map[string]interface{}
|
||||
var scheduleFile = "./data/schedule.json"
|
||||
|
||||
type Schedule map[string]any
|
||||
|
||||
func SaveSchedule(w http.ResponseWriter, r *http.Request) {
|
||||
var s Schedule
|
||||
json.NewDecoder(r.Body).Decode(&s)
|
||||
data, _ := json.Marshal(s)
|
||||
os.WriteFile("schedule.json", data, 0644)
|
||||
if err := json.NewDecoder(r.Body).Decode(&s); err != nil {
|
||||
utils.SendJSONError(w, "Invalid input", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
data, err := json.MarshalIndent(s, "", " ")
|
||||
if err != nil {
|
||||
utils.SendJSONError(w, "Encoding failed", http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
err = os.WriteFile(scheduleFile, data, 0644)
|
||||
if err != nil {
|
||||
utils.SendJSONError(w, "write file failed", http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
w.WriteHeader(http.StatusOK)
|
||||
}
|
||||
|
||||
func GetSchedule(w http.ResponseWriter, r *http.Request) {
|
||||
data, err := os.ReadFile("schedule.json")
|
||||
data, err := os.ReadFile(scheduleFile)
|
||||
if err != nil {
|
||||
json.NewEncoder(w).Encode(Schedule{})
|
||||
return
|
||||
|
||||
12
utils/http.go
Normal file
12
utils/http.go
Normal file
@@ -0,0 +1,12 @@
|
||||
package utils
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
func SendJSONError(w http.ResponseWriter, message string, code int) {
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
w.WriteHeader(code)
|
||||
json.NewEncoder(w).Encode(map[string]string{"error": message})
|
||||
}
|
||||
Reference in New Issue
Block a user