Skip to content

Commit 42fe999

Browse files
committed
Merge branch '0.3.1-release' of https://github.com/PoglyApp/pogly-standalone into 0.3.1-release
2 parents 1e6b57b + 167f10d commit 42fe999

27 files changed

+659
-142
lines changed

package-lock.json

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "pogly-standalone",
3-
"version": "0.3.0",
3+
"version": "0.3.1",
44
"private": true,
55
"type": "module",
66
"dependencies": {
@@ -40,7 +40,7 @@
4040
"react-zoom-pan-pinch": "^3.4.4",
4141
"reakeys": "^2.0.3",
4242
"remark-gfm": "^4.0.0",
43-
"spacetimedb": "^1.8.0",
43+
"spacetimedb": "^1.7.0",
4444
"sql.js": "^1.13.0",
4545
"styled-components": "^6.1.6",
4646
"tailwindcss": "^4.1.4",

server/Config/ConfigReducers.cs

Lines changed: 78 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,15 @@ private static void Configure(ReducerContext ctx)
6161
Ceiling = 1000000
6262
});
6363

64+
ctx.Db.AutoInc.Insert(new AutoInc
65+
{
66+
Version = 0,
67+
FolderIncrement = 0,
68+
ElementsIncrement = 0,
69+
ElementDataIncrement = 0,
70+
LayoutsIncrement = 0,
71+
});
72+
6473
ctx.Db.Layouts.Insert(new Layouts
6574
{
6675
Name = "Default",
@@ -104,7 +113,7 @@ public static void SetConfig(ReducerContext ctx, string platform, string channel
104113

105114
if (authentication && string.IsNullOrEmpty(authKey))
106115
throw new Exception($"Unable to {func}: {ctx.Sender} has authentication enabled but did not provide a Key!");
107-
116+
108117
try
109118
{
110119
var newConfig = oldConfig.Value;
@@ -120,13 +129,30 @@ public static void SetConfig(ReducerContext ctx, string platform, string channel
120129

121130
try
122131
{
132+
var configGuest = ctx.Db.Guests.Address.Find(guest.Address);
133+
if (configGuest is not null) ctx.Db.Guests.Address.Update(configGuest.Value with {Authenticated = true});
123134
SetPermission(ctx, newConfig.OwnerIdentity, PermissionTypes.Owner);
124135
}
125136
catch (Exception e)
126137
{
127138
Log.Exception($"[{func}] - Unable to set guest as owner! " + e.Message);
128139
throw new Exception($"[{func}] - Unable to set guest as owner!");
129140
}
141+
142+
try
143+
{
144+
ctx.Db.GuestNames.Insert(new GuestNames
145+
{
146+
Identity = ctx.Sender,
147+
Nickname = GetJwtUsernameCased(ctx),
148+
StreamingPlatform = GetJwtStreamingPlatform(ctx),
149+
AvatarUrl = GetJwtAvatar(ctx)
150+
});
151+
}
152+
catch (Exception e)
153+
{
154+
Log.Exception($"[{func}] - Unable to add Owner's GuestName! " + e.Message);
155+
}
130156

131157
ctx.Db.AuthenticationKey.Insert(new AuthenticationKey
132158
{
@@ -395,4 +421,55 @@ public static void Authenticate(ReducerContext ctx, string _key)
395421
$"[Authenticate] - Unable to update {guest.Nickname} ({guest.Identity.ToString()}) authenticated status for some reason!");
396422
}
397423
}
424+
425+
[Reducer]
426+
public static void SyncAutoInc(ReducerContext ctx)
427+
{
428+
string func = "SyncAutoInc";
429+
430+
if (!IsGuestOwner(func, ctx))
431+
{
432+
if (ctx.Db.Config.Version.Find(0)!.Value.ConfigInit) return;
433+
}
434+
435+
InternalAutoIncSync(ctx, func);
436+
}
437+
438+
private static void InternalAutoIncSync(ReducerContext ctx, string func)
439+
{
440+
try
441+
{
442+
uint maxFolderId = 0;
443+
uint maxElementsId = 0;
444+
uint maxElementDataId = 0;
445+
uint maxLayoutsId = 0;
446+
foreach (var f in ctx.Db.Folders.Iter())
447+
{
448+
if (f.Id > maxFolderId) maxFolderId = f.Id;
449+
}
450+
foreach (var e in ctx.Db.Elements.Iter())
451+
{
452+
if (e.Id > maxElementsId) maxElementsId = e.Id;
453+
}
454+
foreach (var d in ctx.Db.ElementData.Iter())
455+
{
456+
if (d.Id > maxElementDataId) maxElementDataId = d.Id;
457+
}
458+
foreach (var l in ctx.Db.Layouts.Iter())
459+
{
460+
if (l.Id > maxLayoutsId) maxLayoutsId = l.Id;
461+
}
462+
463+
var autoInc = ctx.Db.AutoInc.Version.Find(0)!.Value;
464+
autoInc.FolderIncrement = maxFolderId;
465+
autoInc.ElementsIncrement = maxElementsId;
466+
autoInc.ElementDataIncrement = maxElementDataId;
467+
autoInc.LayoutsIncrement = maxLayoutsId;
468+
ctx.Db.AutoInc.Version.Update(autoInc);
469+
}
470+
catch (Exception e)
471+
{
472+
Log.Error($"[{func}] Error syncing AutoInc, requested by {ctx.Sender}. " + e.Message);
473+
}
474+
}
398475
}

server/Config/ConfigTables.cs

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,8 @@ public partial class Module
55
[Table(Public = true, Name = "Heartbeat")]
66
public partial struct Heartbeat
77
{
8-
[PrimaryKey]
9-
public uint Id;
10-
8+
[PrimaryKey] public uint Id;
119
public Identity ServerIdentity;
12-
1310
public int Tick;
1411
}
1512

@@ -23,9 +20,7 @@ public partial struct KeepAliveWorker
2320
[Table(Public = true, Name = "Config")]
2421
public partial struct Config
2522
{
26-
[PrimaryKey]
27-
public uint Version;
28-
23+
[PrimaryKey] public uint Version;
2924
public Identity OwnerIdentity;
3025
public string StreamingPlatform;
3126
public string StreamName;
@@ -42,23 +37,29 @@ public partial struct Config
4237
[Table(Public = false, Name = "OwnerRecoveryKey")]
4338
public partial struct AuthenticationKey
4439
{
45-
[PrimaryKey]
46-
public uint Version;
47-
40+
[PrimaryKey] public uint Version;
4841
public string Key;
4942
}
5043

5144
[Table(Public = false, Name = "ZIndex")]
5245
public partial struct ZIndex
5346
{
54-
[PrimaryKey]
55-
public uint Version;
56-
47+
[PrimaryKey] public uint Version;
5748
public int Min;
5849
public int Max;
5950
public int Ceiling;
6051
}
6152

53+
[Table(Public = false, Name = "AutoInc")]
54+
public partial struct AutoInc
55+
{
56+
[PrimaryKey] public uint Version;
57+
public uint FolderIncrement;
58+
public uint ElementsIncrement;
59+
public uint ElementDataIncrement;
60+
public uint LayoutsIncrement;
61+
}
62+
6263
private const string SEVEN_TV_TENOR_REGEX = @"^https?:\/\/(www\.)?cdn\.7tv\.app(?:\/.*)?$|^https?:\/\/(www\.)?media\.tenor\.com(?:\/.*)?$|^https?:\/\/(www\.)?cdn\.betterttv\.net(?:\/.*)?$";
6364

6465
private const string HTML_TAG_REGEX = @"<[^>]*>";

server/ElementData/ElementDataReducers.cs

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,11 @@ public static void AddElementData(ReducerContext ctx, string name, DataType type
1515

1616
try
1717
{
18-
uint maxId = 0;
19-
foreach (var i in ctx.Db.ElementData.Iter())
20-
{
21-
if (i.Id > maxId) maxId = i.Id;
22-
}
18+
var autoInc = ctx.Db.AutoInc.Version.Find(0) ?? MigrateAutoInc(ctx, func);
2319

2420
var elementData = new ElementData
2521
{
26-
Id = maxId + 1,
22+
Id = autoInc.ElementDataIncrement + 1,
2723
Name = name,
2824
DataType = type,
2925
Data = data,
@@ -32,6 +28,7 @@ public static void AddElementData(ReducerContext ctx, string name, DataType type
3228
CreatedBy = guest.Nickname
3329
};
3430
ctx.Db.ElementData.Insert(elementData);
31+
IncrementElementData(ctx, func);
3532

3633
LogAudit(ctx,func,GetEmptyStruct(),GetChangeStructFromElementData(elementData), ctx.Db.Config.Version.Find(0)!.Value.DebugMode);
3734
}
@@ -87,15 +84,11 @@ public static void AddElementDataArray(ReducerContext ctx, string name, DataType
8784

8885
try
8986
{
90-
uint maxId = 0;
91-
foreach (var i in ctx.Db.ElementData.Iter())
92-
{
93-
if (i.Id > maxId) maxId = i.Id;
94-
}
87+
var autoInc = ctx.Db.AutoInc.Version.Find(0) ?? MigrateAutoInc(ctx, func);
9588

9689
var elementData = new ElementData
9790
{
98-
Id = maxId + 1,
91+
Id = autoInc.ElementDataIncrement + 1,
9992
Name = name,
10093
DataType = type,
10194
Data = data,
@@ -105,6 +98,7 @@ public static void AddElementDataArray(ReducerContext ctx, string name, DataType
10598
CreatedBy = guest.Nickname
10699
};
107100
ctx.Db.ElementData.Insert(elementData);
101+
IncrementElementData(ctx, func);
108102

109103
LogAudit(ctx,func,GetEmptyStruct(),GetChangeStructFromElementData(elementData), ctx.Db.Config.Version.Find(0)!.Value.DebugMode);
110104
}

server/Elements/ElementReducers.cs

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,11 @@ public static void AddElement(ReducerContext ctx, ElementStruct element, int tra
2929
return;
3030
}
3131

32-
uint maxId = 0;
33-
foreach (var i in ctx.Db.Elements.Iter())
34-
{
35-
if (i.Id > maxId) maxId = i.Id;
36-
}
32+
var autoInc = ctx.Db.AutoInc.Version.Find(0) ?? MigrateAutoInc(ctx, func);
3733

3834
var newElement = new Elements
3935
{
40-
Id = maxId + 1,
36+
Id = autoInc.ElementsIncrement + 1,
4137
Element = element,
4238
Transparency = transparency,
4339
Transform = transform,
@@ -50,6 +46,7 @@ public static void AddElement(ReducerContext ctx, ElementStruct element, int tra
5046
ZIndex = ctx.Db.ZIndex.Version.Find(0)!.Value.Max + 1
5147
};
5248
ctx.Db.Elements.Insert(newElement);
49+
IncrementElements(ctx, func);
5350

5451
LogAudit(ctx,func,GetEmptyStruct(),GetChangeStructFromElement(newElement), ctx.Db.Config.Version.Find(0)!.Value.DebugMode);
5552
}
@@ -85,15 +82,11 @@ public static void AddElementToLayout(ReducerContext ctx, ElementStruct element,
8582
return;
8683
}
8784

88-
uint maxId = 0;
89-
foreach (var i in ctx.Db.Elements.Iter())
90-
{
91-
if (i.Id > maxId) maxId = i.Id;
92-
}
93-
85+
var autoInc = ctx.Db.AutoInc.Version.Find(0) ?? MigrateAutoInc(ctx, func);
86+
9487
var newElement = new Elements
9588
{
96-
Id = maxId + 1,
89+
Id = autoInc.ElementsIncrement + 1,
9790
Element = element,
9891
Transparency = transparency,
9992
Transform = transform,
@@ -106,6 +99,7 @@ public static void AddElementToLayout(ReducerContext ctx, ElementStruct element,
10699
ZIndex = ctx.Db.ZIndex.Version.Find(0)!.Value.Max + 1
107100
};
108101
ctx.Db.Elements.Insert(newElement);
102+
IncrementElements(ctx, func);
109103

110104
LogAudit(ctx,func,GetEmptyStruct(),GetChangeStructFromElement(newElement), ctx.Db.Config.Version.Find(0)!.Value.DebugMode);
111105
}

server/Folders/FolderReducers.cs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,20 +15,17 @@ public static void AddFolder(ReducerContext ctx, string name, string icon)
1515

1616
try
1717
{
18-
uint maxId = 0;
19-
foreach (var i in ctx.Db.Folders.Iter())
20-
{
21-
if (i.Id > maxId) maxId = i.Id;
22-
}
18+
var autoInc = ctx.Db.AutoInc.Version.Find(0) ?? MigrateAutoInc(ctx, func);
2319

2420
var newFolder = new Folders
2521
{
26-
Id = maxId + 1,
22+
Id = autoInc.FolderIncrement + 1,
2723
Icon = icon,
2824
Name = name,
2925
CreatedBy = guest.Nickname
3026
};
3127
ctx.Db.Folders.Insert(newFolder);
28+
IncrementFolder(ctx, func);
3229

3330
//TODO: Add AuditLog() ChangeStruct types and methods for Folders
3431
if(ctx.Db.Config.Version.Find(0)!.Value.DebugMode)

server/Guests/GuestReducers.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ public static void UpdateGuestNickname(ReducerContext ctx, string nickname)
4747

4848
if (ctx.ConnectionId is null) return;
4949
if (!GetGuest(func, ctx, out var guest)) return;
50+
if (!GuestAuthenticated(func, guest)) return;
5051

5152
try
5253
{

0 commit comments

Comments
 (0)