diff --git a/example_dashboard/package.json b/example_dashboard/package.json index 1209be9..52ad12b 100644 --- a/example_dashboard/package.json +++ b/example_dashboard/package.json @@ -37,4 +37,4 @@ "dependencies": { "@velaboratory/velconnect": "../../VEL-Connect/velconnect-npm" } -} \ No newline at end of file +} diff --git a/example_dashboard/src/lib/js/util.ts b/example_dashboard/src/lib/js/util.ts index 59e7c88..2805d85 100644 --- a/example_dashboard/src/lib/js/util.ts +++ b/example_dashboard/src/lib/js/util.ts @@ -15,7 +15,8 @@ export function prettyDate(date: string | Date | DateTime, includeYear = false) } // return DateTime.fromISO(date).toFormat("yyyy-LL-dd hh:mm a ZZZZ"); const fromNow = DateTime.utc().minus(d.toMillis()).toMillis(); - const yearReplace = includeYear ? '' : ', 2023'; + // TODO fix + const yearReplace = includeYear ? '' : ', 2024'; if (fromNow > 0) { return `${d.toLocaleString(DateTime.DATETIME_MED)} (${humanizeDuration(fromNow, { round: true, diff --git a/unity_package/Runtime/VELConnectManager.cs b/unity_package/Runtime/VELConnectManager.cs index 64a77e3..1a4f9e2 100644 --- a/unity_package/Runtime/VELConnectManager.cs +++ b/unity_package/Runtime/VELConnectManager.cs @@ -185,7 +185,23 @@ namespace VELConnect sb.Append("EDITOR"); #endif string id = Convert.ToBase64String(md5.ComputeHash(Encoding.UTF8.GetBytes(sb.ToString()))); - deviceId = id[..15]; + deviceId = CreateDeviceId(); + } + + // Computes 15-char device id compatibly with pocketbase + private static string CreateDeviceId() + { + MD5CryptoServiceProvider md5 = new MD5CryptoServiceProvider(); + StringBuilder sb = new StringBuilder(SystemInfo.deviceUniqueIdentifier); + sb.Append(Application.productName); +#if UNITY_EDITOR + // allows running multiple builds on the same computer + // return SystemInfo.deviceUniqueIdentifier + Hash128.Compute(Application.dataPath); + sb.Append(Application.dataPath); + sb.Append("EDITOR"); +#endif + string id = Convert.ToBase64String(md5.ComputeHash(Encoding.UTF8.GetBytes(sb.ToString()))); + return id[..15]; } // Start is called before the first frame update diff --git a/velconnect/Dockerfile b/velconnect/Dockerfile index 45b4f58..6cc00ae 100644 --- a/velconnect/Dockerfile +++ b/velconnect/Dockerfile @@ -1,22 +1,20 @@ -FROM alpine:latest +# syntax=docker/dockerfile:1 +FROM golang:1.21 as build +WORKDIR /src +COPY go.mod go.sum ./ +RUN go mod download -ARG PB_VERSION=0.20.7 +COPY *.go ./ +COPY pb_migrations/ ./pb_migrations -RUN apk add --no-cache \ - unzip \ - ca-certificates +# Build +RUN CGO_ENABLED=0 go build -ldflags="-s -w" -o ./velconnect +# RUN ./velconnect-pb migrate up -# download and unzip PocketBase -ADD https://github.com/pocketbase/pocketbase/releases/download/v${PB_VERSION}/pocketbase_${PB_VERSION}_linux_arm64.zip /tmp/pb.zip -RUN unzip /tmp/pb.zip -d /pb/ +FROM alpine:3.19.1 +COPY --from=build /src/velconnect /velconnect -# uncomment to copy the local pb_migrations dir into the image -# COPY ./pb_migrations /pb/pb_migrations +EXPOSE 8090 -# uncomment to copy the local pb_hooks dir into the image -# COPY ./pb_hooks /pb/pb_hooks - -EXPOSE 8092 - -# start PocketBase -CMD ["/pb/pocketbase", "serve", "--http=0.0.0.0:8092"] +# Run +ENTRYPOINT ["./velconnect", "serve", "--http=0.0.0.0:8090"] \ No newline at end of file diff --git a/velconnect/docker-compose.yml b/velconnect/docker-compose.yml index 6f4a660..9e05d25 100644 --- a/velconnect/docker-compose.yml +++ b/velconnect/docker-compose.yml @@ -4,6 +4,6 @@ services: build: . restart: always ports: - - "8091:8092" + - "8094:8090" volumes: - ./pb_data:/pb/pb_data diff --git a/velconnect/go.mod b/velconnect/go.mod index a4a0ba2..7d37805 100644 --- a/velconnect/go.mod +++ b/velconnect/go.mod @@ -4,6 +4,7 @@ go 1.18 require ( github.com/labstack/echo/v5 v5.0.0-20220201181537-ed2888cfa198 + github.com/pocketbase/dbx v1.10.0 github.com/pocketbase/pocketbase v0.16.7 ) @@ -50,7 +51,6 @@ require ( github.com/mattn/go-isatty v0.0.19 // indirect github.com/mattn/go-sqlite3 v1.14.17 // indirect github.com/mgutz/ansi v0.0.0-20200706080929-d51e80ef957d // indirect - github.com/pocketbase/dbx v1.10.0 // indirect github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec // indirect github.com/spf13/cast v1.5.1 // indirect github.com/spf13/cobra v1.7.0 // indirect diff --git a/velconnect/main.go b/velconnect/main.go index d95aa8d..05eed1a 100644 --- a/velconnect/main.go +++ b/velconnect/main.go @@ -5,7 +5,7 @@ import ( "log" "net/http" - _ "velaboratory/velconnect/migrations" + _ "velaboratory/velconnect/pb_migrations" "github.com/labstack/echo/v5" "github.com/pocketbase/pocketbase" diff --git a/velconnect/migrations/1706737010_collections_snapshot.go b/velconnect/migrations/1706737010_collections_snapshot.go new file mode 100644 index 0000000..41db26b --- /dev/null +++ b/velconnect/migrations/1706737010_collections_snapshot.go @@ -0,0 +1,453 @@ +package migrations + +import ( + "encoding/json" + + "github.com/pocketbase/dbx" + "github.com/pocketbase/pocketbase/daos" + m "github.com/pocketbase/pocketbase/migrations" + "github.com/pocketbase/pocketbase/models" +) + +func init() { + m.Register(func(db dbx.Builder) error { + jsonData := `[ + { + "id": "ve85cwsj7syqvxu", + "created": "2023-07-06 23:08:13.962Z", + "updated": "2023-11-03 18:47:06.094Z", + "name": "UserCount", + "type": "base", + "system": false, + "schema": [ + { + "system": false, + "id": "pnhtdbcx", + "name": "app_id", + "type": "text", + "required": false, + "unique": false, + "options": { + "min": null, + "max": null, + "pattern": "" + } + }, + { + "system": false, + "id": "wkf3zyyb", + "name": "room_id", + "type": "text", + "required": false, + "unique": false, + "options": { + "min": null, + "max": null, + "pattern": "" + } + }, + { + "system": false, + "id": "f7k9hdoc", + "name": "total_users", + "type": "number", + "required": false, + "unique": false, + "options": { + "min": null, + "max": null + } + }, + { + "system": false, + "id": "uevek8os", + "name": "room_users", + "type": "number", + "required": false, + "unique": false, + "options": { + "min": null, + "max": null + } + }, + { + "system": false, + "id": "coilxuep", + "name": "version", + "type": "text", + "required": false, + "unique": false, + "options": { + "min": null, + "max": null, + "pattern": "" + } + }, + { + "system": false, + "id": "zee0a2yb", + "name": "platform", + "type": "text", + "required": false, + "unique": false, + "options": { + "min": null, + "max": null, + "pattern": "" + } + } + ], + "indexes": [], + "listRule": null, + "viewRule": null, + "createRule": "", + "updateRule": null, + "deleteRule": null, + "options": {} + }, + { + "id": "fupstz47c55s69f", + "created": "2023-07-06 23:10:31.321Z", + "updated": "2023-11-03 18:47:06.120Z", + "name": "Device", + "type": "base", + "system": false, + "schema": [ + { + "system": false, + "id": "1tkrnxqf", + "name": "os_info", + "type": "text", + "required": false, + "unique": false, + "options": { + "min": null, + "max": null, + "pattern": "" + } + }, + { + "system": false, + "id": "knspamfx", + "name": "friendly_name", + "type": "text", + "required": false, + "unique": false, + "options": { + "min": null, + "max": null, + "pattern": "" + } + }, + { + "system": false, + "id": "qfalwg3c", + "name": "modified_by", + "type": "text", + "required": false, + "unique": false, + "options": { + "min": null, + "max": null, + "pattern": "" + } + }, + { + "system": false, + "id": "x0zlup7v", + "name": "current_app", + "type": "text", + "required": false, + "unique": false, + "options": { + "min": null, + "max": null, + "pattern": "" + } + }, + { + "system": false, + "id": "vpzen2th", + "name": "current_room", + "type": "text", + "required": false, + "unique": false, + "options": { + "min": null, + "max": null, + "pattern": "" + } + }, + { + "system": false, + "id": "d0ckgjhm", + "name": "pairing_code", + "type": "text", + "required": false, + "unique": false, + "options": { + "min": null, + "max": null, + "pattern": "" + } + }, + { + "system": false, + "id": "hglbl7da", + "name": "last_online", + "type": "date", + "required": false, + "unique": false, + "options": { + "min": "", + "max": "" + } + }, + { + "system": false, + "id": "qxsvm1rf", + "name": "data", + "type": "relation", + "required": true, + "unique": false, + "options": { + "collectionId": "3qwwkz4wb0lyi78", + "cascadeDelete": false, + "minSelect": null, + "maxSelect": 1, + "displayFields": [ + "data" + ] + } + }, + { + "system": false, + "id": "nfernq2q", + "name": "owner", + "type": "relation", + "required": false, + "unique": false, + "options": { + "collectionId": "_pb_users_auth_", + "cascadeDelete": false, + "minSelect": null, + "maxSelect": 1, + "displayFields": [ + "username" + ] + } + }, + { + "system": false, + "id": "p1aruqz5", + "name": "past_owners", + "type": "relation", + "required": false, + "unique": false, + "options": { + "collectionId": "_pb_users_auth_", + "cascadeDelete": false, + "minSelect": null, + "maxSelect": null, + "displayFields": [ + "username" + ] + } + } + ], + "indexes": [], + "listRule": "", + "viewRule": "", + "createRule": null, + "updateRule": "", + "deleteRule": null, + "options": {} + }, + { + "id": "3qwwkz4wb0lyi78", + "created": "2023-07-06 23:12:11.113Z", + "updated": "2024-01-31 21:26:53.835Z", + "name": "DataBlock", + "type": "base", + "system": false, + "schema": [ + { + "system": false, + "id": "wbifl8pv", + "name": "category", + "type": "text", + "required": false, + "unique": false, + "options": { + "min": null, + "max": null, + "pattern": "" + } + }, + { + "system": false, + "id": "5a3nwg7m", + "name": "modified_by", + "type": "text", + "required": false, + "unique": false, + "options": { + "min": null, + "max": null, + "pattern": "" + } + }, + { + "system": false, + "id": "mkzyfsng", + "name": "data", + "type": "json", + "required": false, + "unique": false, + "options": {} + }, + { + "system": false, + "id": "a3d7pkoh", + "name": "owner", + "type": "relation", + "required": false, + "unique": false, + "options": { + "collectionId": "_pb_users_auth_", + "cascadeDelete": false, + "minSelect": null, + "maxSelect": 1, + "displayFields": [ + "username" + ] + } + }, + { + "system": false, + "id": "80tmi6fm", + "name": "block_id", + "type": "text", + "required": false, + "unique": false, + "options": { + "min": null, + "max": null, + "pattern": "" + } + } + ], + "indexes": [ + "CREATE INDEX ` + "`" + `idx_aYVfg1q` + "`" + ` ON ` + "`" + `DataBlock` + "`" + ` (` + "`" + `block_id` + "`" + `)" + ], + "listRule": "", + "viewRule": "", + "createRule": "", + "updateRule": "", + "deleteRule": null, + "options": {} + }, + { + "id": "_pb_users_auth_", + "created": "2023-11-03 18:47:06.067Z", + "updated": "2024-01-31 21:26:53.820Z", + "name": "Users", + "type": "auth", + "system": false, + "schema": [ + { + "system": false, + "id": "users_name", + "name": "name", + "type": "text", + "required": false, + "unique": false, + "options": { + "min": null, + "max": null, + "pattern": "" + } + }, + { + "system": false, + "id": "users_avatar", + "name": "avatar", + "type": "file", + "required": false, + "unique": false, + "options": { + "maxSelect": 1, + "maxSize": 5242880, + "mimeTypes": [ + "image/jpeg", + "image/png", + "image/svg+xml", + "image/gif", + "image/webp" + ], + "thumbs": null, + "protected": false + } + }, + { + "system": false, + "id": "1hwaooub", + "name": "devices", + "type": "relation", + "required": false, + "unique": false, + "options": { + "collectionId": "fupstz47c55s69f", + "cascadeDelete": false, + "minSelect": null, + "maxSelect": null, + "displayFields": [] + } + }, + { + "system": false, + "id": "xvw8arlm", + "name": "profiles", + "type": "relation", + "required": false, + "unique": false, + "options": { + "collectionId": "3qwwkz4wb0lyi78", + "cascadeDelete": false, + "minSelect": null, + "maxSelect": null, + "displayFields": [ + "data" + ] + } + } + ], + "indexes": [], + "listRule": "id = @request.auth.id", + "viewRule": "id = @request.auth.id", + "createRule": "", + "updateRule": "id = @request.auth.id", + "deleteRule": "id = @request.auth.id", + "options": { + "allowEmailAuth": true, + "allowOAuth2Auth": true, + "allowUsernameAuth": true, + "exceptEmailDomains": null, + "manageRule": null, + "minPasswordLength": 6, + "onlyEmailDomains": null, + "requireEmail": false + } + } + ]` + + collections := []*models.Collection{} + if err := json.Unmarshal([]byte(jsonData), &collections); err != nil { + return err + } + + return daos.New(db).ImportCollections(collections, true, nil) + }, func(db dbx.Builder) error { + return nil + }) +} diff --git a/velconnect/migrations/1688687760_velconnect.go b/velconnect/pb_migrations/1688687760_velconnect.go similarity index 100% rename from velconnect/migrations/1688687760_velconnect.go rename to velconnect/pb_migrations/1688687760_velconnect.go diff --git a/velconnect/migrations/1688688320_collections_snapshot.go b/velconnect/pb_migrations/1688688320_collections_snapshot.go similarity index 100% rename from velconnect/migrations/1688688320_collections_snapshot.go rename to velconnect/pb_migrations/1688688320_collections_snapshot.go diff --git a/velconnect/migrations/1688698903_updated_Device.go b/velconnect/pb_migrations/1688698903_updated_Device.go similarity index 100% rename from velconnect/migrations/1688698903_updated_Device.go rename to velconnect/pb_migrations/1688698903_updated_Device.go diff --git a/velconnect/migrations/1688762268_updated_Device.go b/velconnect/pb_migrations/1688762268_updated_Device.go similarity index 100% rename from velconnect/migrations/1688762268_updated_Device.go rename to velconnect/pb_migrations/1688762268_updated_Device.go diff --git a/velconnect/migrations/1688762282_updated_Device.go b/velconnect/pb_migrations/1688762282_updated_Device.go similarity index 100% rename from velconnect/migrations/1688762282_updated_Device.go rename to velconnect/pb_migrations/1688762282_updated_Device.go diff --git a/velconnect/migrations/1688764015_updated_users.go b/velconnect/pb_migrations/1688764015_updated_users.go similarity index 100% rename from velconnect/migrations/1688764015_updated_users.go rename to velconnect/pb_migrations/1688764015_updated_users.go diff --git a/velconnect/migrations/1688764331_updated_Users.go b/velconnect/pb_migrations/1688764331_updated_Users.go similarity index 100% rename from velconnect/migrations/1688764331_updated_Users.go rename to velconnect/pb_migrations/1688764331_updated_Users.go diff --git a/velconnect/migrations/1688765190_updated_Device.go b/velconnect/pb_migrations/1688765190_updated_Device.go similarity index 100% rename from velconnect/migrations/1688765190_updated_Device.go rename to velconnect/pb_migrations/1688765190_updated_Device.go diff --git a/velconnect/migrations/1688782403_updated_Device.go b/velconnect/pb_migrations/1688782403_updated_Device.go similarity index 100% rename from velconnect/migrations/1688782403_updated_Device.go rename to velconnect/pb_migrations/1688782403_updated_Device.go diff --git a/velconnect/migrations/1688783036_updated_Device.go b/velconnect/pb_migrations/1688783036_updated_Device.go similarity index 100% rename from velconnect/migrations/1688783036_updated_Device.go rename to velconnect/pb_migrations/1688783036_updated_Device.go diff --git a/velconnect/migrations/1688786744_updated_UserCount.go b/velconnect/pb_migrations/1688786744_updated_UserCount.go similarity index 100% rename from velconnect/migrations/1688786744_updated_UserCount.go rename to velconnect/pb_migrations/1688786744_updated_UserCount.go diff --git a/velconnect/migrations/1688786749_updated_UserCount.go b/velconnect/pb_migrations/1688786749_updated_UserCount.go similarity index 100% rename from velconnect/migrations/1688786749_updated_UserCount.go rename to velconnect/pb_migrations/1688786749_updated_UserCount.go diff --git a/velconnect/migrations/1689182903_updated_DataBlock.go b/velconnect/pb_migrations/1689182903_updated_DataBlock.go similarity index 100% rename from velconnect/migrations/1689182903_updated_DataBlock.go rename to velconnect/pb_migrations/1689182903_updated_DataBlock.go diff --git a/velconnect/migrations/1689182917_updated_DataBlock.go b/velconnect/pb_migrations/1689182917_updated_DataBlock.go similarity index 100% rename from velconnect/migrations/1689182917_updated_DataBlock.go rename to velconnect/pb_migrations/1689182917_updated_DataBlock.go diff --git a/velconnect/migrations/1689182928_updated_Device.go b/velconnect/pb_migrations/1689182928_updated_Device.go similarity index 100% rename from velconnect/migrations/1689182928_updated_Device.go rename to velconnect/pb_migrations/1689182928_updated_Device.go diff --git a/velconnect/migrations/1689183964_updated_Device.go b/velconnect/pb_migrations/1689183964_updated_Device.go similarity index 100% rename from velconnect/migrations/1689183964_updated_Device.go rename to velconnect/pb_migrations/1689183964_updated_Device.go diff --git a/velconnect/migrations/1689184089_updated_DataBlock.go b/velconnect/pb_migrations/1689184089_updated_DataBlock.go similarity index 100% rename from velconnect/migrations/1689184089_updated_DataBlock.go rename to velconnect/pb_migrations/1689184089_updated_DataBlock.go diff --git a/velconnect/migrations/1689184118_deleted_UserDevice.go b/velconnect/pb_migrations/1689184118_deleted_UserDevice.go similarity index 100% rename from velconnect/migrations/1689184118_deleted_UserDevice.go rename to velconnect/pb_migrations/1689184118_deleted_UserDevice.go diff --git a/velconnect/migrations/1689184532_updated_Device.go b/velconnect/pb_migrations/1689184532_updated_Device.go similarity index 100% rename from velconnect/migrations/1689184532_updated_Device.go rename to velconnect/pb_migrations/1689184532_updated_Device.go diff --git a/velconnect/migrations/1689185047_updated_DataBlock.go b/velconnect/pb_migrations/1689185047_updated_DataBlock.go similarity index 100% rename from velconnect/migrations/1689185047_updated_DataBlock.go rename to velconnect/pb_migrations/1689185047_updated_DataBlock.go diff --git a/velconnect/migrations/1689186241_updated_DataBlock.go b/velconnect/pb_migrations/1689186241_updated_DataBlock.go similarity index 100% rename from velconnect/migrations/1689186241_updated_DataBlock.go rename to velconnect/pb_migrations/1689186241_updated_DataBlock.go diff --git a/velconnect/migrations/1689186267_updated_Device.go b/velconnect/pb_migrations/1689186267_updated_Device.go similarity index 100% rename from velconnect/migrations/1689186267_updated_Device.go rename to velconnect/pb_migrations/1689186267_updated_Device.go diff --git a/velconnect/migrations/1689186346_updated_Device.go b/velconnect/pb_migrations/1689186346_updated_Device.go similarity index 100% rename from velconnect/migrations/1689186346_updated_Device.go rename to velconnect/pb_migrations/1689186346_updated_Device.go diff --git a/velconnect/migrations/1689187696_updated_DataBlock.go b/velconnect/pb_migrations/1689187696_updated_DataBlock.go similarity index 100% rename from velconnect/migrations/1689187696_updated_DataBlock.go rename to velconnect/pb_migrations/1689187696_updated_DataBlock.go diff --git a/velconnect/migrations/1689187725_updated_Device.go b/velconnect/pb_migrations/1689187725_updated_Device.go similarity index 100% rename from velconnect/migrations/1689187725_updated_Device.go rename to velconnect/pb_migrations/1689187725_updated_Device.go diff --git a/velconnect/migrations/1689432006_updated_Users.go b/velconnect/pb_migrations/1689432006_updated_Users.go similarity index 100% rename from velconnect/migrations/1689432006_updated_Users.go rename to velconnect/pb_migrations/1689432006_updated_Users.go diff --git a/velconnect/migrations/1689432678_updated_Users.go b/velconnect/pb_migrations/1689432678_updated_Users.go similarity index 100% rename from velconnect/migrations/1689432678_updated_Users.go rename to velconnect/pb_migrations/1689432678_updated_Users.go diff --git a/velconnect/migrations/1689432745_updated_Users.go b/velconnect/pb_migrations/1689432745_updated_Users.go similarity index 100% rename from velconnect/migrations/1689432745_updated_Users.go rename to velconnect/pb_migrations/1689432745_updated_Users.go diff --git a/velconnect/migrations/1689432842_updated_Users.go b/velconnect/pb_migrations/1689432842_updated_Users.go similarity index 100% rename from velconnect/migrations/1689432842_updated_Users.go rename to velconnect/pb_migrations/1689432842_updated_Users.go diff --git a/velconnect/migrations/1689438773_updated_DataBlock.go b/velconnect/pb_migrations/1689438773_updated_DataBlock.go similarity index 100% rename from velconnect/migrations/1689438773_updated_DataBlock.go rename to velconnect/pb_migrations/1689438773_updated_DataBlock.go diff --git a/velconnect/migrations/1689439744_updated_DataBlock.go b/velconnect/pb_migrations/1689439744_updated_DataBlock.go similarity index 100% rename from velconnect/migrations/1689439744_updated_DataBlock.go rename to velconnect/pb_migrations/1689439744_updated_DataBlock.go diff --git a/velconnect/migrations/1689439798_updated_DataBlock.go b/velconnect/pb_migrations/1689439798_updated_DataBlock.go similarity index 100% rename from velconnect/migrations/1689439798_updated_DataBlock.go rename to velconnect/pb_migrations/1689439798_updated_DataBlock.go diff --git a/velconnect/migrations/1689439831_updated_Users.go b/velconnect/pb_migrations/1689439831_updated_Users.go similarity index 100% rename from velconnect/migrations/1689439831_updated_Users.go rename to velconnect/pb_migrations/1689439831_updated_Users.go diff --git a/velconnect/migrations/1699037643_updated_Users.go b/velconnect/pb_migrations/1699037643_updated_Users.go similarity index 100% rename from velconnect/migrations/1699037643_updated_Users.go rename to velconnect/pb_migrations/1699037643_updated_Users.go diff --git a/velconnect/migrations/1701978583_updated_Users.go b/velconnect/pb_migrations/1701978583_updated_Users.go similarity index 100% rename from velconnect/migrations/1701978583_updated_Users.go rename to velconnect/pb_migrations/1701978583_updated_Users.go diff --git a/velconnect/migrations/1701981023_updated_Users.go b/velconnect/pb_migrations/1701981023_updated_Users.go similarity index 100% rename from velconnect/migrations/1701981023_updated_Users.go rename to velconnect/pb_migrations/1701981023_updated_Users.go