diff --git a/.gitignore b/.gitignore index d5ac763..9d78b4a 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ .aider* .env +/display/internal/pdfjs/node_modules diff --git a/display/internal/pdfjs/assets.go b/display/internal/pdfjs/assets.go new file mode 100644 index 0000000..3d76cfc --- /dev/null +++ b/display/internal/pdfjs/assets.go @@ -0,0 +1,7 @@ +package pdfjs + +import "embed" + +//go:embed node_modules/pdfjs-dist/build/pdf.min.mjs +//go:embed node_modules/pdfjs-dist/build/pdf.worker.min.mjs +var Files embed.FS diff --git a/display/internal/pdfjs/deno.json b/display/internal/pdfjs/deno.json new file mode 100644 index 0000000..b54b896 --- /dev/null +++ b/display/internal/pdfjs/deno.json @@ -0,0 +1,10 @@ +{ + "nodeModulesDir": "manual", + "nodeModulesLinker": "hoisted", + "imports": { + "pdfjs-dist": "npm:pdfjs-dist@6.0.227" + }, + "tasks": { + "install": "deno install --frozen" + } +} diff --git a/display/internal/pdfjs/deno.lock b/display/internal/pdfjs/deno.lock new file mode 100644 index 0000000..56857a9 --- /dev/null +++ b/display/internal/pdfjs/deno.lock @@ -0,0 +1,90 @@ +{ + "version": "5", + "specifiers": { + "npm:pdfjs-dist@6.0.227": "6.0.227" + }, + "npm": { + "@napi-rs/canvas-android-arm64@1.0.0": { + "integrity": "sha512-3hNKJObUK7JsCF9aJlVCs1J0/KE/gGfZNeK8MO1ge6bB3aicr5walGme9t9No1f/oyk9GgvdAT/rjSdsx3gbIw==", + "os": ["android"], + "cpu": ["arm64"] + }, + "@napi-rs/canvas-darwin-arm64@1.0.0": { + "integrity": "sha512-ZIja19/BiGz2puhki+WUYSRriwFeFJ8Mi9eK3hZdSS85w4Y60cuEAJVhMCfKwswQkKkUtrnzdKMBuO7TupvexA==", + "os": ["darwin"], + "cpu": ["arm64"] + }, + "@napi-rs/canvas-darwin-x64@1.0.0": { + "integrity": "sha512-hImggWc82jqZVpEsFR9S7PE9OQYjq/H/D7vwCGB6X1jRH+UVBP1+1niJTPBOat1B154T6GKK7/kcFtoWgjgFzQ==", + "os": ["darwin"], + "cpu": ["x64"] + }, + "@napi-rs/canvas-linux-arm-gnueabihf@1.0.0": { + "integrity": "sha512-hlJRy6d+kWLKVOG/+1rEvNQVURZ0DxxRPJsLmEWwhwiXZUJc0BF5o9esALHSEP4CoJK4wChRtj3hnyBgVx2oWA==", + "os": ["linux"], + "cpu": ["arm"] + }, + "@napi-rs/canvas-linux-arm64-gnu@1.0.0": { + "integrity": "sha512-5Hru4T3RXkosRQafcjelv7AUzw9mXqmGYsxnzeDDOWveFCJyEPMSJltvGCM+jfH98seOCbfwm9KyFg6Jm5FhAA==", + "os": ["linux"], + "cpu": ["arm64"] + }, + "@napi-rs/canvas-linux-arm64-musl@1.0.0": { + "integrity": "sha512-LTUl9jS8WsLSUGaxQZKQkxfluOJRpgvBuxxdM4pYcjib+di8AU4OzQc6+L6SzGMLcKc9H0RAjojRatBhTMqYdg==", + "os": ["linux"], + "cpu": ["arm64"] + }, + "@napi-rs/canvas-linux-riscv64-gnu@1.0.0": { + "integrity": "sha512-Iz931SAZf+WVDzpjk52Q3ffW3zw0YflFwEZMgs036Wfu1kX/LrwT9wGjsuSqyduqefUkl91/vTdAjn8hQu5ezA==", + "os": ["linux"], + "cpu": ["riscv64"] + }, + "@napi-rs/canvas-linux-x64-gnu@1.0.0": { + "integrity": "sha512-pFEQ5eFK4JusgN1K6KkO9DKP/Hi1WMJOkF8Ch03/khTc4bFbCKkCCsJG4YcOMOW9bI4XbT2/eMAWxhO0xaWgPA==", + "os": ["linux"], + "cpu": ["x64"] + }, + "@napi-rs/canvas-linux-x64-musl@1.0.0": { + "integrity": "sha512-jnvr8NrLHiZ3NCiOKWqDbkI4Ah+QDrqtZ+sddPZBltEb1mQ2coSvCSJYfict+oAwcm0c970oTmVySpjKP/lnaA==", + "os": ["linux"], + "cpu": ["x64"] + }, + "@napi-rs/canvas-win32-arm64-msvc@1.0.0": { + "integrity": "sha512-y2j9/Gfd5joqiqxdP/L1smqjQ+uAx3C4N0EC7bDHrnZEEH8ToM/OC5p3uHvtj4Lq591aHj+ArL01UDLNwT5HgQ==", + "os": ["win32"], + "cpu": ["arm64"] + }, + "@napi-rs/canvas-win32-x64-msvc@1.0.0": { + "integrity": "sha512-qwdhh9N6Gge/hC4pL9S1tQp0iKwhSl/dYjg7+RGp9k26iRGRi5MqqUyKGOXIWli0zOcuy5Y2wIH/jk2ry6i/jA==", + "os": ["win32"], + "cpu": ["x64"] + }, + "@napi-rs/canvas@1.0.0": { + "integrity": "sha512-Jqxcy1XOIqj+lH9sl1GT+il6GR3uQv13vI2mrwubP3uT8Olak2ClDrK2RnxlQKjwv8BRr4b3ug0YR7c6hBX8wg==", + "optionalDependencies": [ + "@napi-rs/canvas-android-arm64", + "@napi-rs/canvas-darwin-arm64", + "@napi-rs/canvas-darwin-x64", + "@napi-rs/canvas-linux-arm-gnueabihf", + "@napi-rs/canvas-linux-arm64-gnu", + "@napi-rs/canvas-linux-arm64-musl", + "@napi-rs/canvas-linux-riscv64-gnu", + "@napi-rs/canvas-linux-x64-gnu", + "@napi-rs/canvas-linux-x64-musl", + "@napi-rs/canvas-win32-arm64-msvc", + "@napi-rs/canvas-win32-x64-msvc" + ] + }, + "pdfjs-dist@6.0.227": { + "integrity": "sha512-/P6M4SXw+70waMVLUM7rdRtvo+dEzqE1t6W/zQNvBETo2MaRa5rrvCcAYdfWGiUzadTgM0lJmRApUrW0d9zgKg==", + "optionalDependencies": [ + "@napi-rs/canvas" + ] + } + }, + "workspace": { + "dependencies": [ + "npm:pdfjs-dist@6.0.227" + ] + } +} diff --git a/display/justfile b/display/justfile index 8367ed8..2d73542 100644 --- a/display/justfile +++ b/display/justfile @@ -1,5 +1,6 @@ gen: go tool templ generate + cd internal/pdfjs && deno install --frozen dev: gen go run *.go diff --git a/display/pkg/main.templ b/display/pkg/main.templ index 9c54103..5029c76 100644 --- a/display/pkg/main.templ +++ b/display/pkg/main.templ @@ -1,5 +1,7 @@ package pkg +import "strings" + templ basicTemplate() { @@ -115,6 +117,166 @@ templ deviceInfoTemplate(ip string, mac string, showQR bool) { } } +templ pdfTemplate(path string, serverOrigin string) { + @basicTemplate() { + + +
+ + + + + } +} + templ startScreenTemplate(splashScreenHtml string, ip string, mac string, qrPath string) { @basicTemplate() {
diff --git a/display/pkg/open_file.go b/display/pkg/open_file.go index a790a0e..c6117da 100644 --- a/display/pkg/open_file.go +++ b/display/pkg/open_file.go @@ -40,7 +40,12 @@ func OpenFile(path string) error { _ = imageTemplate(path).Render(context.Background(), &templateBuffer) err = browser.Browser.OpenHTML(templateBuffer.String()) case "application/pdf": - err = browser.Browser.OpenPDF(path) + var templateBuffer bytes.Buffer + err = pdfTemplate(path, "http://127.0.0.1:1323").Render(context.Background(), &templateBuffer) + if err == nil { + err = browser.Browser.OpenHTML(templateBuffer.String()) + } + case "application/vnd.openxmlformats-officedocument.presentationml.presentation", "application/vnd.oasis.opendocument.presentation": err = fileHandler.openFileWithApp(path) default: diff --git a/display/web/main.go b/display/web/main.go index 4b5fa7a..8603ea2 100644 --- a/display/web/main.go +++ b/display/web/main.go @@ -16,12 +16,20 @@ import ( "github.com/labstack/echo/v4/middleware" "plg-mudics/display/browser" + "plg-mudics/display/internal/pdfjs" "plg-mudics/display/pkg" ) func StartWebServer(port string) { e := echo.New() + pdfJSGroup := e.Group("/static/pdfjs") + pdfJSGroup.Use(middleware.CORS()) + pdfJSGroup.StaticFS( + "/", + echo.MustSubFS(pdfjs.Files, "node_modules/pdfjs-dist/build"), + ) + apiGroup := e.Group("/api") apiGroup.Use(middleware.CORS()) apiGroup.GET("/ping", pingRoute)