added webhook
parent
d406f34ed8
commit
0d1ad0f6b7
|
@ -1 +1,2 @@
|
||||||
numpy==1.24.3
|
numpy==1.24.3
|
||||||
|
pdf2image==1.17.0
|
||||||
|
|
|
@ -63,7 +63,7 @@
|
||||||
display: flex;
|
display: flex;
|
||||||
justify-content: center;
|
justify-content: center;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
gap: 20mm;
|
gap: 0mm;
|
||||||
z-index: -10;
|
z-index: -10;
|
||||||
opacity: 0.25;
|
opacity: 0.25;
|
||||||
}
|
}
|
||||||
|
@ -90,16 +90,18 @@
|
||||||
display: flex;
|
display: flex;
|
||||||
justify-content: space-between;
|
justify-content: space-between;
|
||||||
width: 100%;
|
width: 100%;
|
||||||
gap: 20mm;
|
gap: 15mm;
|
||||||
}
|
}
|
||||||
|
|
||||||
.bgContainer {
|
.bgContainer {
|
||||||
display: flex;
|
display: flex;
|
||||||
justify-content: center;
|
justify-content: center;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
gap: 40mm;
|
gap: 50mm;
|
||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
width: 60mm;
|
width: 80mm;
|
||||||
|
|
||||||
|
position: relative;
|
||||||
}
|
}
|
||||||
|
|
||||||
.myCustomText {
|
.myCustomText {
|
||||||
|
@ -127,12 +129,12 @@
|
||||||
<div class="social_media">
|
<div class="social_media">
|
||||||
<p>Folge uns</p>
|
<p>Folge uns</p>
|
||||||
<img class="insta_logo" src="../../groupsData/shx-order-package-label/instagram-logo.png" />
|
<img class="insta_logo" src="../../groupsData/shx-order-package-label/instagram-logo.png" />
|
||||||
<p>SHINNEX</p>
|
<p>shinnex.official</p>
|
||||||
</div>
|
</div>
|
||||||
<div class="social_media">
|
<div class="social_media">
|
||||||
<p>Folge uns</p>
|
<p>Folge uns</p>
|
||||||
<img class="tiktok_logo" src="../../groupsData/shx-order-package-label/tiktok-logo.png" />
|
<img class="tiktok_logo" src="../../groupsData/shx-order-package-label/tiktok-logo.png" />
|
||||||
<p>SHINNEX</p>
|
<p>shinnex.official</p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
@ -142,12 +144,12 @@
|
||||||
<div class="social_media">
|
<div class="social_media">
|
||||||
<p>Folge uns</p>
|
<p>Folge uns</p>
|
||||||
<img class="tiktok_logo" src="../../groupsData/shx-order-package-label/tiktok-logo.png" />
|
<img class="tiktok_logo" src="../../groupsData/shx-order-package-label/tiktok-logo.png" />
|
||||||
<p>SHINNEX</p>
|
<p>shinnex.official</p>
|
||||||
</div>
|
</div>
|
||||||
<div class="social_media">
|
<div class="social_media">
|
||||||
<p>Folge uns</p>
|
<p>Folge uns</p>
|
||||||
<img class="insta_logo" src="../../groupsData/shx-order-package-label/instagram-logo.png" />
|
<img class="insta_logo" src="../../groupsData/shx-order-package-label/instagram-logo.png" />
|
||||||
<p>SHINNEX</p>
|
<p>shinnex.official</p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -4,6 +4,8 @@ import sys
|
||||||
from PIL import Image
|
from PIL import Image
|
||||||
import os
|
import os
|
||||||
|
|
||||||
|
from pdf2image import convert_from_path
|
||||||
|
|
||||||
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '../..')))
|
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '../..')))
|
||||||
|
|
||||||
from libs.utils import utils
|
from libs.utils import utils
|
||||||
|
@ -44,7 +46,7 @@ def createHighDpiPng(sourceHtml, outputPng):
|
||||||
print(stderr.decode()) # Decoding the stderr for better readability
|
print(stderr.decode()) # Decoding the stderr for better readability
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
def downloadFile(url, filename):
|
def downloadFilePNG(url, filename):
|
||||||
command = [
|
command = [
|
||||||
"curl",
|
"curl",
|
||||||
"-o",
|
"-o",
|
||||||
|
@ -72,6 +74,41 @@ def downloadFile(url, filename):
|
||||||
|
|
||||||
rotated_image.save(filename)
|
rotated_image.save(filename)
|
||||||
|
|
||||||
|
def downloadFilePDF(url, filename):
|
||||||
|
pdf_filename = filename + ".pdf"
|
||||||
|
|
||||||
|
command = [
|
||||||
|
"curl",
|
||||||
|
"-L", # Follow redirects
|
||||||
|
"-o",
|
||||||
|
pdf_filename,
|
||||||
|
url,
|
||||||
|
]
|
||||||
|
|
||||||
|
process = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
||||||
|
stdout, stderr = process.communicate()
|
||||||
|
|
||||||
|
if process.returncode != 0:
|
||||||
|
print("Error downloading file")
|
||||||
|
print("STDOUT:")
|
||||||
|
print(stdout.decode()) # Decoding the stdout for better readability
|
||||||
|
print("STDERR:")
|
||||||
|
print(stderr.decode()) # Decoding the stderr for better readability
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
# Convert the PDF to a PNG
|
||||||
|
images = convert_from_path(pdf_filename, dpi=300)
|
||||||
|
|
||||||
|
page = images[0]
|
||||||
|
|
||||||
|
h = page.height/2
|
||||||
|
spacing = 250
|
||||||
|
|
||||||
|
# box=(left, upper, right, lower)
|
||||||
|
page.crop((0, spacing, page.width, h-spacing)
|
||||||
|
).save(filename, 'PNG')
|
||||||
|
|
||||||
|
|
||||||
def replacePlaceholder():
|
def replacePlaceholder():
|
||||||
with open("index.html", "r") as file:
|
with open("index.html", "r") as file:
|
||||||
index_html = file.read()
|
index_html = file.read()
|
||||||
|
@ -87,10 +124,14 @@ if __name__ == "__main__":
|
||||||
|
|
||||||
print(f"Creating package label for {customer_first_name}")
|
print(f"Creating package label for {customer_first_name}")
|
||||||
|
|
||||||
downloadFile(shipping_label_url, "label.png")
|
#if shipping_label_url contains .pdf, download the file and convert it to a PNG
|
||||||
|
if ".pdf" in shipping_label_url or "https://cloud.umbach.dev/" in shipping_label_url:
|
||||||
|
downloadFilePDF(shipping_label_url, "label.png")
|
||||||
|
else:
|
||||||
|
downloadFilePNG(shipping_label_url, "label.png")
|
||||||
|
|
||||||
replacePlaceholder()
|
replacePlaceholder()
|
||||||
|
|
||||||
createHighDpiPng("index.html", "Versandlabel.png")
|
createHighDpiPng("index.html", "Versandlabel.png")
|
||||||
|
|
||||||
utils.clear_workspace(["index.html", "label.png"])
|
utils.clear_workspace(["index.html", "label.png.pdf", "label.png"])
|
||||||
|
|
|
@ -3,6 +3,7 @@ package config
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"github.com/joho/godotenv"
|
"github.com/joho/godotenv"
|
||||||
)
|
)
|
||||||
|
@ -20,6 +21,7 @@ type Config struct {
|
||||||
FolderPaths FolderPaths
|
FolderPaths FolderPaths
|
||||||
MariaDB MariaDB
|
MariaDB MariaDB
|
||||||
InvexAPI InvexAPI
|
InvexAPI InvexAPI
|
||||||
|
NotificationUserIds []string
|
||||||
}
|
}
|
||||||
|
|
||||||
type FolderPaths struct {
|
type FolderPaths struct {
|
||||||
|
@ -72,6 +74,7 @@ func LoadConfig() {
|
||||||
Base: os.Getenv("INVEX_API_BASE"),
|
Base: os.Getenv("INVEX_API_BASE"),
|
||||||
Token: os.Getenv("INVEX_API_TOKEN"),
|
Token: os.Getenv("INVEX_API_TOKEN"),
|
||||||
},
|
},
|
||||||
|
NotificationUserIds: strings.Split(os.Getenv("NOTIFICATION_USER_IDS"), ","),
|
||||||
}
|
}
|
||||||
|
|
||||||
// load default values if not in docker
|
// load default values if not in docker
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package crm
|
package crm
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"jannex/admin-dashboard-backend/modules/config"
|
||||||
"jannex/admin-dashboard-backend/modules/database"
|
"jannex/admin-dashboard-backend/modules/database"
|
||||||
"jannex/admin-dashboard-backend/modules/logger"
|
"jannex/admin-dashboard-backend/modules/logger"
|
||||||
"jannex/admin-dashboard-backend/modules/notification"
|
"jannex/admin-dashboard-backend/modules/notification"
|
||||||
|
@ -771,7 +772,7 @@ func CrmUseLink(c *fiber.Ctx) error {
|
||||||
database.DB.First(&crmCustomer, "id = ?", link.CustomerId)
|
database.DB.First(&crmCustomer, "id = ?", link.CustomerId)
|
||||||
|
|
||||||
notification.AddNotification(nil, structs.AddNotificationRequest{
|
notification.AddNotification(nil, structs.AddNotificationRequest{
|
||||||
UserIds: []string{"00de4e2c-4790-4272-bc30-e0b25d8426b6", "3d7f3dc2-dc81-4d5d-93a1-dc6690511ee3"},
|
UserIds: config.Cfg.NotificationUserIds,
|
||||||
Type: 1,
|
Type: 1,
|
||||||
Title: "Crm link used: " + link.Name + " by crm customer: " + crmCustomer.FirstName + " " + crmCustomer.Email + " (" + link.CustomerId + ")",
|
Title: "Crm link used: " + link.Name + " by crm customer: " + crmCustomer.FirstName + " " + crmCustomer.Email + " (" + link.CustomerId + ")",
|
||||||
})
|
})
|
||||||
|
|
|
@ -0,0 +1,75 @@
|
||||||
|
package webhook
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
|
"jannex/admin-dashboard-backend/modules/config"
|
||||||
|
"jannex/admin-dashboard-backend/modules/logger"
|
||||||
|
"jannex/admin-dashboard-backend/modules/notification"
|
||||||
|
"jannex/admin-dashboard-backend/modules/structs"
|
||||||
|
|
||||||
|
"git.ex.umbach.dev/Alex/roese-utils/rslogger"
|
||||||
|
"github.com/gofiber/fiber/v2"
|
||||||
|
)
|
||||||
|
|
||||||
|
type EventData struct {
|
||||||
|
Type string `json:"type"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type PrinterData struct {
|
||||||
|
ID int `json:"id"`
|
||||||
|
Name string `json:"name"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type PrintData struct {
|
||||||
|
ID int `json:"id"`
|
||||||
|
Filename string `json:"filename"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type Message struct {
|
||||||
|
Event EventData `json:"event"`
|
||||||
|
Printer PrinterData `json:"printer"`
|
||||||
|
Print PrintData `json:"print"`
|
||||||
|
ImgURL string `json:"img_url"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func Webhook(c *fiber.Ctx) error {
|
||||||
|
logger.AddSystemLog(rslogger.LogTypeInfo, "Received webhook: %v query: %v", string(c.Body()), c.Query("auth"))
|
||||||
|
|
||||||
|
if c.Query("auth") == "oThBd3apemoexlRyyNmLvgLRswGH6Fp9niCzxuxZgFg8ahnYqE" {
|
||||||
|
var message Message
|
||||||
|
|
||||||
|
if err := json.Unmarshal(c.Body(), &message); err != nil {
|
||||||
|
logger.AddSystemLog(rslogger.LogTypeError, "Failed to unmarshal body, err: %v", err.Error())
|
||||||
|
return c.SendStatus(fiber.StatusOK)
|
||||||
|
}
|
||||||
|
|
||||||
|
var state uint8
|
||||||
|
|
||||||
|
if message.Event.Type == "PrintFailure" {
|
||||||
|
state = 4
|
||||||
|
} else if message.Event.Type == "PrintPaused" {
|
||||||
|
state = 3
|
||||||
|
} else {
|
||||||
|
state = 0
|
||||||
|
}
|
||||||
|
|
||||||
|
notification.AddNotification(nil, structs.AddNotificationRequest{
|
||||||
|
UserIds: config.Cfg.NotificationUserIds,
|
||||||
|
Type: state,
|
||||||
|
Title: fmt.Sprintf("Event: %s\nPrinter ID: %d\nPrinter Name: %s\nPrint ID: %d\nPrint Filename: %s\nImg Url: %s",
|
||||||
|
message.Event.Type,
|
||||||
|
message.Printer.ID,
|
||||||
|
message.Printer.Name,
|
||||||
|
message.Print.ID,
|
||||||
|
message.Print.Filename,
|
||||||
|
message.ImgURL),
|
||||||
|
})
|
||||||
|
|
||||||
|
return c.SendStatus(fiber.StatusOK)
|
||||||
|
}
|
||||||
|
|
||||||
|
logger.AddSystemLog(rslogger.LogTypeWarning, "Received webhook with unknown auth")
|
||||||
|
|
||||||
|
return c.SendStatus(fiber.StatusBadRequest)
|
||||||
|
}
|
|
@ -15,6 +15,7 @@ import (
|
||||||
"jannex/admin-dashboard-backend/routers/router/api/v1/notification"
|
"jannex/admin-dashboard-backend/routers/router/api/v1/notification"
|
||||||
"jannex/admin-dashboard-backend/routers/router/api/v1/user"
|
"jannex/admin-dashboard-backend/routers/router/api/v1/user"
|
||||||
"jannex/admin-dashboard-backend/routers/router/api/v1/users"
|
"jannex/admin-dashboard-backend/routers/router/api/v1/users"
|
||||||
|
"jannex/admin-dashboard-backend/routers/router/api/v1/webhook"
|
||||||
"jannex/admin-dashboard-backend/socketclients"
|
"jannex/admin-dashboard-backend/socketclients"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
@ -26,6 +27,8 @@ import (
|
||||||
func SetupRoutes(app *fiber.App) {
|
func SetupRoutes(app *fiber.App) {
|
||||||
v1 := app.Group("/v1")
|
v1 := app.Group("/v1")
|
||||||
|
|
||||||
|
v1.Post("/webhook", webhook.Webhook)
|
||||||
|
|
||||||
u := v1.Group("/user")
|
u := v1.Group("/user")
|
||||||
u.Post("/auth/login", user.UserLogin)
|
u.Post("/auth/login", user.UserLogin)
|
||||||
u.Delete("/auth/logout", requestAccessValidation, user.UserLogout)
|
u.Delete("/auth/logout", requestAccessValidation, user.UserLogout)
|
||||||
|
|
Loading…
Reference in New Issue