cc-rehab 3.0.2 → 3.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.mjs +14 -1
- package/package.json +1 -1
package/index.mjs
CHANGED
|
@@ -174,10 +174,23 @@ function deriveStatsServer(sessions) {
|
|
|
174
174
|
|
|
175
175
|
// ── Supabase sync ──
|
|
176
176
|
async function syncToSupabase(stats, cfg) {
|
|
177
|
+
// Fetch existing row to preserve _name/_avatar set by frontend
|
|
178
|
+
let existingName = "Anonymous", existingAvatar = "🫠";
|
|
179
|
+
try {
|
|
180
|
+
const r = await fetch(`${SUPA_URL}/rest/v1/user_stats?id=eq.${cfg.uid}&select=stats&limit=1`, {
|
|
181
|
+
headers: { apikey: SUPA_KEY },
|
|
182
|
+
});
|
|
183
|
+
if (r.ok) {
|
|
184
|
+
const rows = await r.json();
|
|
185
|
+
if (rows[0]?.stats?._name) existingName = rows[0].stats._name;
|
|
186
|
+
if (rows[0]?.stats?._avatar) existingAvatar = rows[0].stats._avatar;
|
|
187
|
+
}
|
|
188
|
+
} catch {}
|
|
189
|
+
|
|
177
190
|
const body = {
|
|
178
191
|
id: cfg.uid,
|
|
179
192
|
pair_code: cfg.token,
|
|
180
|
-
stats,
|
|
193
|
+
stats: { _name: existingName, _avatar: existingAvatar, ...stats },
|
|
181
194
|
updated_at: new Date().toISOString(),
|
|
182
195
|
};
|
|
183
196
|
try {
|