Merge branch 'main' into dev

dev
Anton Franzluebbers 2024-02-01 15:14:46 -05:00
commit 73c2ccea0a
44 changed files with 491 additions and 23 deletions

View File

@ -37,4 +37,4 @@
"dependencies": {
"@velaboratory/velconnect": "../../VEL-Connect/velconnect-npm"
}
}
}

View File

@ -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,

View File

@ -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

View File

@ -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"]

View File

@ -4,6 +4,6 @@ services:
build: .
restart: always
ports:
- "8091:8092"
- "8094:8090"
volumes:
- ./pb_data:/pb/pb_data

View File

@ -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

View File

@ -5,7 +5,7 @@ import (
"log"
"net/http"
_ "velaboratory/velconnect/migrations"
_ "velaboratory/velconnect/pb_migrations"
"github.com/labstack/echo/v5"
"github.com/pocketbase/pocketbase"

View File

@ -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
})
}