Skip to content

Commit

Permalink
Load embedded resources into the application
Browse files Browse the repository at this point in the history
  • Loading branch information
Akkadius committed Nov 30, 2021
1 parent 7fb91b2 commit fa43b4a
Show file tree
Hide file tree
Showing 10 changed files with 167 additions and 21 deletions.
7 changes: 2 additions & 5 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
# Changelog
All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## [1.0.2]
* Embed the changelog you're reading into the app

## [1.0.1]
* Remove application boot dependency on having `APP_NAME` set
Expand Down
4 changes: 4 additions & 0 deletions boot/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ type App struct {
desktop *desktop.WebBoot
}

func (a App) Cache() *gocache.Cache {
return a.cache
}

func (a App) Desktop() *desktop.WebBoot {
return a.desktop
}
Expand Down
3 changes: 3 additions & 0 deletions boot/inject_http.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ var httpSet = wire.NewSet(
controllers.NewAuthController,
controllers.NewDocsController,
controllers.NewQuestApiController,
controllers.NewAppController,
provideControllers,
NewRouter,
)
Expand Down Expand Up @@ -102,6 +103,7 @@ func provideControllers(
connections *controllers.ConnectionsController,
docs *controllers.DocsController,
quest *controllers.QuestApiController,
app *controllers.AppController,
) *appControllerGroups {
return &appControllerGroups{
authControllers: []routes.Controller{
Expand All @@ -116,6 +118,7 @@ func provideControllers(
},
v1controllersNoAuth: []routes.Controller{
quest,
app,
},
}
}
Expand Down
3 changes: 2 additions & 1 deletion boot/wire_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion frontend/src/app/spells.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2967,7 +2967,7 @@ export class Spells {
<div style="display: inline-block">
<img
:src="spellCdnUrl + '' + (${spell.new_icon} > 0 ? ${spell.new_icon} : 0) + '.gif'"
style="width: ${iconSize}px;height:auto; border: 2px solid ${targetTypeColor}; border-radius: 7px;"
style="width: ${iconSize}px;height:auto; border: 1px solid ${targetTypeColor}; border-radius: 7px;"
>
<span style="color: #f7ff00">${spell.name}</span>
</div>
Expand Down
77 changes: 65 additions & 12 deletions frontend/src/views/pages/Home.vue
Original file line number Diff line number Diff line change
@@ -1,26 +1,79 @@
<template>
<div>
<div class="container-fluid">

<div class="row justify-content-center">
<div class="col-12 col-lg-10 col-xl-10 content-pop">
<!-- <page-header title="Components" pre-title="Preview Components"/>-->

<div class="container-fluid">

<div class="header mt-md-1">
<div class="header-body">
<h1 class="header-title" id="progress-bars">
Changelog & News
</h1>

<p class="header-subtitle">
See the latest Spire changes here!
</p>
</div>
</div>

<div class="row">
<v-runtime-template :template="changelog"/>
</div>

</div>
</div>
</div>
</div>
</template>

<script>
import EqWindow from "@/components/eq-ui/EQWindow";
import UserContext from "@/app/user/UserContext";
import EqWindow from "@/components/eq-ui/EQWindow";
import UserContext from "@/app/user/UserContext";
import {SpireApiClient} from "../../app/api/spire-api-client";
export default {
components: { EqWindow },
data() {
return {
userContext: null,
}
},
async mounted() {
this.userContext = await (UserContext.getUser())
export default {
components: {
EqWindow,
"v-runtime-template": () => import("v-runtime-template")
},
data() {
return {
userContext: null,
changelog: "",
}
},
async mounted() {
this.userContext = await (UserContext.getUser())
SpireApiClient.v1().get(`/app/changelog`).then((response) => {
if (response.data && response.data.data) {
const md = require("markdown-it")({
html: true,
xhtmlOut: false,
breaks: true,
typographer: false
});
let result = response.data.data
result = md.render(result);
console.log(result)
// doc
this.changelog = "<div>" + result + "</div>"
}
})
}
}
</script>

2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/Akkadius/spire

go 1.12
go 1.16

require (
github.com/Jeffail/gabs v1.4.0
Expand Down
71 changes: 71 additions & 0 deletions internal/http/controllers/app_controller.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
package controllers

import (
"encoding/json"
"github.com/Akkadius/spire/internal/env"
"github.com/Akkadius/spire/internal/http/routes"
"github.com/labstack/echo/v4"
gocache "github.com/patrickmn/go-cache"
"github.com/sirupsen/logrus"
"net/http"
)

type AppController struct {
cache *gocache.Cache
logger *logrus.Logger
}

func NewAppController(cache *gocache.Cache, logger *logrus.Logger) *AppController {
return &AppController{
cache: cache,
logger: logger,
}
}

func (d *AppController) Routes() []*routes.Route {
return []*routes.Route{
routes.RegisterRoute(http.MethodGet, "app/changelog", d.changelog, nil),
routes.RegisterRoute(http.MethodGet, "app/env", d.env, nil),
}
}

func (d *AppController) changelog(c echo.Context) error {
changelog, _ := d.cache.Get("changelog")
return c.JSON(200, echo.Map{"data": changelog})
}

type EnvResponse struct {
Env string `json:"env"`
Version string `json:"version"`
}

type PackageJson struct {
Name string `json:"name"`
Version string `json:"version"`
Repository struct {
Type string `json:"type"`
URL string `json:"url"`
} `json:"repository"`
}

func (d *AppController) env(c echo.Context) error {
data, _ := d.cache.Get("packageJson")

pJson, ok := data.([]byte)
if ok {
var pkg PackageJson
err := json.Unmarshal(pJson, &pkg)
if err != nil {
return err
}

response := EnvResponse{
Env: env.Get("APP_ENV", "local"),
Version: pkg.Version,
}

return c.JSON(200, echo.Map{"data": response})
}

return c.JSON(500, echo.Map{"error": "Unknown error"})
}
17 changes: 17 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package main

import (
_ "embed"
"github.com/Akkadius/spire/boot"
"github.com/Akkadius/spire/console"
"github.com/Akkadius/spire/internal/env"
Expand All @@ -21,6 +22,9 @@ func main() {
log.Fatal(err)
}

// load embedded resources
loadEmbedded(&app)

// ran via executable on desktop
if len(os.Args) == 1 && runtime.GOOS == "windows" {
app.Desktop().Boot()
Expand All @@ -31,3 +35,16 @@ func main() {
log.Fatal(err)
}
}

var (
//go:embed CHANGELOG.md
changelog string
//go:embed package.json
packageJson []byte
)

func loadEmbedded(app *boot.App) {
// load embedded files into cache
app.Cache().Set("changelog", changelog, -1)
app.Cache().Set("packageJson", packageJson, -1)
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "spire",
"version": "1.0.1",
"version": "1.0.2",
"repository": {
"type": "git",
"url": "https://github.com/Akkadius/spire.git"
Expand Down

0 comments on commit fa43b4a

Please sign in to comment.