From 06da33de8f7c4c7f5ef1f25835abf8271b2dd968 Mon Sep 17 00:00:00 2001 From: sundowndev Date: Thu, 29 Jun 2023 16:41:52 +0400 Subject: [PATCH 1/3] feat: implement analytics in demo website --- build/build.go | 9 ++++++++- build/build_test.go | 6 ++++++ web/client/src/App.vue | 13 +++++++++++-- web/client/yarn.lock | 15 ++++++++++++--- web/controllers.go | 2 ++ web/server_test.go | 2 +- 6 files changed, 40 insertions(+), 7 deletions(-) diff --git a/build/build.go b/build/build.go index 0c2ac2be3..a979f5877 100644 --- a/build/build.go +++ b/build/build.go @@ -1,6 +1,9 @@ package build -import "fmt" +import ( + "fmt" + "os" +) // Version is the corresponding release tag var Version = "dev" @@ -15,3 +18,7 @@ func IsRelease() bool { func String() string { return fmt.Sprintf("%s-%s", Version, Commit) } + +func IsDemo() bool { + return os.Getenv("PHONEINFOGA_DEMO") == "true" +} diff --git a/build/build_test.go b/build/build_test.go index dfd9b4d0c..e8209c6a2 100644 --- a/build/build_test.go +++ b/build/build_test.go @@ -2,6 +2,7 @@ package build import ( "github.com/stretchr/testify/assert" + "os" "testing" ) @@ -11,12 +12,17 @@ func TestBuild(t *testing.T) { assert.Equal(t, "dev", Commit) assert.Equal(t, false, IsRelease()) assert.Equal(t, "dev-dev", String()) + assert.Equal(t, false, IsDemo()) }) t.Run("version and commit default values", func(t *testing.T) { Version = "v2.4.4" Commit = "0ba854f" + _ = os.Setenv("PHONEINFOGA_DEMO", "true") + defer os.Unsetenv("PHONEINFOGA_DEMO") + assert.Equal(t, true, IsRelease()) assert.Equal(t, "v2.4.4-0ba854f", String()) + assert.Equal(t, true, IsDemo()) }) } diff --git a/web/client/src/App.vue b/web/client/src/App.vue index d5634ff36..5ec6fecf4 100644 --- a/web/client/src/App.vue +++ b/web/client/src/App.vue @@ -48,6 +48,7 @@ + Welcome to the demo of PhoneInfoga web client. + @@ -93,10 +101,10 @@ import { mapState } from "vuex"; import config from "@/config"; import axios, { AxiosResponse } from "axios"; -type HealthResponse = { success: boolean; version: string }; +type HealthResponse = { success: boolean; version: string; demo: boolean }; export default Vue.extend({ - data: () => ({ config, version: "" }), + data: () => ({ config, version: "", isDemo: false }), computed: { ...mapState(["number", "errors"]), }, @@ -104,6 +112,7 @@ export default Vue.extend({ const res: AxiosResponse = await axios.get(config.apiUrl); this.version = res.data.version; + this.isDemo = res.data.demo; }, }); diff --git a/web/client/yarn.lock b/web/client/yarn.lock index b2ac2e182..0816d5913 100644 --- a/web/client/yarn.lock +++ b/web/client/yarn.lock @@ -2,7 +2,7 @@ # Manual changes might be lost - proceed with caution! __metadata: - version: 5 + version: 6 cacheKey: 8 "@achrinza/node-ipc@npm:9.2.2": @@ -2371,6 +2371,15 @@ __metadata: languageName: node linkType: hard +"acorn@npm:^8.5.0": + version: 8.9.0 + resolution: "acorn@npm:8.9.0" + bin: + acorn: bin/acorn + checksum: 25dfb94952386ecfb847e61934de04a4e7c2dc21c2e700fc4e2ef27ce78cb717700c4c4f279cd630bb4774948633c3859fc16063ec8573bda4568e0a312e6744 + languageName: node + linkType: hard + "address@npm:^1.1.2": version: 1.2.1 resolution: "address@npm:1.2.1" @@ -15182,11 +15191,11 @@ __metadata: "typescript@patch:typescript@4.2.3#~builtin": version: 4.2.3 - resolution: "typescript@patch:typescript@npm%3A4.2.3#~builtin::version=4.2.3&hash=ddd1e8" + resolution: "typescript@patch:typescript@npm%3A4.2.3#~builtin::version=4.2.3&hash=701156" bin: tsc: bin/tsc tsserver: bin/tsserver - checksum: f97b1f885444f13c340127a0918b17d0c4e5c248f99203a22712b3b43d7129c9c7b95437e4f1de99edf79d3046fa9e15356fb5d27d9d94e47a98158c8b18fda5 + checksum: f00e6e6e72c950865979d5beb66916c75d92eda09514eb2953828b95505cfd2ef3ae9ac776fdac9f841a9ce67744999b70d23779726e0072656a1841c8080860 languageName: node linkType: hard diff --git a/web/controllers.go b/web/controllers.go index 8663fe427..b2b61f642 100644 --- a/web/controllers.go +++ b/web/controllers.go @@ -24,6 +24,7 @@ type healthResponse struct { Success bool `json:"success"` Version string `json:"version"` Commit string `json:"commit"` + Demo bool `json:"demo"` } // @ID getAllNumbers @@ -183,5 +184,6 @@ func healthHandler(c *gin.Context) { Success: true, Version: build.Version, Commit: build.Commit, + Demo: build.IsDemo(), }) } diff --git a/web/server_test.go b/web/server_test.go index 3d33fb74f..b2fd7b83d 100644 --- a/web/server_test.go +++ b/web/server_test.go @@ -246,7 +246,7 @@ func TestApi(t *testing.T) { body, _ := ioutil.ReadAll(res.Body) assert.Equal(t, 200, res.Result().StatusCode) - assert.Equal(t, "{\"success\":true,\"version\":\"dev\",\"commit\":\"dev\"}", string(body)) + assert.Equal(t, `{"success":true,"version":"dev","commit":"dev","demo":false}`, string(body)) }) t.Run("404 error - /api/notfound", func(t *testing.T) { From c783a9998dc8afce09e2b30d198f945b2e10e885 Mon Sep 17 00:00:00 2001 From: sundowndev Date: Thu, 29 Jun 2023 16:56:45 +0400 Subject: [PATCH 2/3] chore: revert yarn lock file --- web/client/yarn.lock | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) diff --git a/web/client/yarn.lock b/web/client/yarn.lock index 0816d5913..b2ac2e182 100644 --- a/web/client/yarn.lock +++ b/web/client/yarn.lock @@ -2,7 +2,7 @@ # Manual changes might be lost - proceed with caution! __metadata: - version: 6 + version: 5 cacheKey: 8 "@achrinza/node-ipc@npm:9.2.2": @@ -2371,15 +2371,6 @@ __metadata: languageName: node linkType: hard -"acorn@npm:^8.5.0": - version: 8.9.0 - resolution: "acorn@npm:8.9.0" - bin: - acorn: bin/acorn - checksum: 25dfb94952386ecfb847e61934de04a4e7c2dc21c2e700fc4e2ef27ce78cb717700c4c4f279cd630bb4774948633c3859fc16063ec8573bda4568e0a312e6744 - languageName: node - linkType: hard - "address@npm:^1.1.2": version: 1.2.1 resolution: "address@npm:1.2.1" @@ -15191,11 +15182,11 @@ __metadata: "typescript@patch:typescript@4.2.3#~builtin": version: 4.2.3 - resolution: "typescript@patch:typescript@npm%3A4.2.3#~builtin::version=4.2.3&hash=701156" + resolution: "typescript@patch:typescript@npm%3A4.2.3#~builtin::version=4.2.3&hash=ddd1e8" bin: tsc: bin/tsc tsserver: bin/tsserver - checksum: f00e6e6e72c950865979d5beb66916c75d92eda09514eb2953828b95505cfd2ef3ae9ac776fdac9f841a9ce67744999b70d23779726e0072656a1841c8080860 + checksum: f97b1f885444f13c340127a0918b17d0c4e5c248f99203a22712b3b43d7129c9c7b95437e4f1de99edf79d3046fa9e15356fb5d27d9d94e47a98158c8b18fda5 languageName: node linkType: hard From 740c23cf79bb6e860d707410260054453ebe69af Mon Sep 17 00:00:00 2001 From: sundowndev Date: Thu, 29 Jun 2023 17:00:35 +0400 Subject: [PATCH 3/3] chore: regenerate openapi specs --- web/docs/docs.go | 3 +++ web/docs/swagger.json | 3 +++ web/docs/swagger.yaml | 2 ++ 3 files changed, 8 insertions(+) diff --git a/web/docs/docs.go b/web/docs/docs.go index 9c061993a..8f2158c46 100644 --- a/web/docs/docs.go +++ b/web/docs/docs.go @@ -774,6 +774,9 @@ var doc = `{ "commit": { "type": "string" }, + "demo": { + "type": "boolean" + }, "success": { "type": "boolean" }, diff --git a/web/docs/swagger.json b/web/docs/swagger.json index ba27e3e83..c9103d2e1 100644 --- a/web/docs/swagger.json +++ b/web/docs/swagger.json @@ -763,6 +763,9 @@ "commit": { "type": "string" }, + "demo": { + "type": "boolean" + }, "success": { "type": "boolean" }, diff --git a/web/docs/swagger.yaml b/web/docs/swagger.yaml index eb8e61b55..13117f8d2 100644 --- a/web/docs/swagger.yaml +++ b/web/docs/swagger.yaml @@ -193,6 +193,8 @@ definitions: properties: commit: type: string + demo: + type: boolean success: type: boolean version: