incognitolm commited on
Commit
bbce479
·
1 Parent(s): f75d6ae

Cleaned up log

Browse files
server/auth.js CHANGED
@@ -62,18 +62,14 @@ export async function setUsername(userId, accessToken, username) {
62
 
63
  export async function getSubscriptionInfo(accessToken) {
64
  try {
65
- console.log('[Subscription] Fetching subscription info for token:', accessToken?.slice(0, 20) + '...');
66
  const r = await fetch('https://sharktide-lightning.hf.space/subscription', {
67
  headers: { Authorization: `Bearer ${accessToken}`, Accept: 'application/json' },
68
  });
69
- console.log('[Subscription] Response status:', r.status);
70
  if (!r.ok) {
71
  console.warn(`[Subscription] Failed: HTTP ${r.status}`);
72
  return null;
73
  }
74
- const data = await r.json();
75
- console.log('[Subscription] Raw response data:', data);
76
-
77
  // Normalize snake_case keys from HF Space to camelCase
78
  const normalized = {
79
  planKey: data.plan_key || null,
@@ -82,7 +78,6 @@ export async function getSubscriptionInfo(accessToken) {
82
  signedUp: data.signed_up,
83
  subscription: data.subscription,
84
  };
85
- console.log('[Subscription] Normalized response:', normalized);
86
  return normalized;
87
  } catch (err) {
88
  console.error('[Subscription] Error fetching subscription info:', err.message);
 
62
 
63
  export async function getSubscriptionInfo(accessToken) {
64
  try {
 
65
  const r = await fetch('https://sharktide-lightning.hf.space/subscription', {
66
  headers: { Authorization: `Bearer ${accessToken}`, Accept: 'application/json' },
67
  });
 
68
  if (!r.ok) {
69
  console.warn(`[Subscription] Failed: HTTP ${r.status}`);
70
  return null;
71
  }
72
+ const data = await r.json();
 
 
73
  // Normalize snake_case keys from HF Space to camelCase
74
  const normalized = {
75
  planKey: data.plan_key || null,
 
78
  signedUp: data.signed_up,
79
  subscription: data.subscription,
80
  };
 
81
  return normalized;
82
  } catch (err) {
83
  console.error('[Subscription] Error fetching subscription info:', err.message);
server/index.js CHANGED
@@ -109,4 +109,4 @@ wss.on('connection', (ws, req) => {
109
  safeSend(ws, { type: 'connected', tempId: wsClients.get(ws)?.tempId });
110
  });
111
 
112
- httpServer.listen(PORT, '0.0.0.0', () => console.log(`InferencePort Web on port ${PORT}`));
 
109
  safeSend(ws, { type: 'connected', tempId: wsClients.get(ws)?.tempId });
110
  });
111
 
112
+ httpServer.listen(PORT, '0.0.0.0', () => console.log(`Running on port ${PORT}`));
server/sessionStore.js CHANGED
@@ -147,8 +147,8 @@ export const sessionStore = {
147
  return s;
148
  },
149
  async updateUserSession(userId, accessToken, sessionId, patch) {
150
- const user = userCache.get(userId); if (!user) { console.log ("No user for " + userId); return null; }
151
- const s = user.sessions.get(sessionId); if (!s) { console.log ("No session found for " + sessionId); return null; }
152
  Object.assign(s, patch);
153
  await this._persist(userClient(accessToken), userId, s).catch(() => {});
154
  return s;
@@ -171,7 +171,7 @@ export const sessionStore = {
171
  if (u) {
172
  u.sessions.clear();
173
  } else {
174
- console.log('No user for ' + userId);
175
  return null;
176
  }
177
  try {
 
147
  return s;
148
  },
149
  async updateUserSession(userId, accessToken, sessionId, patch) {
150
+ const user = userCache.get(userId); if (!user) { console.error("No user for " + userId); return null; }
151
+ const s = user.sessions.get(sessionId); if (!s) { console.error ("No session found for " + sessionId); return null; }
152
  Object.assign(s, patch);
153
  await this._persist(userClient(accessToken), userId, s).catch(() => {});
154
  return s;
 
171
  if (u) {
172
  u.sessions.clear();
173
  } else {
174
+ console.error('No user for ' + userId);
175
  return null;
176
  }
177
  try {
server/wsHandler.js CHANGED
@@ -78,11 +78,9 @@ const handlers = {
78
 
79
  'auth:login': async (ws, msg, client, wsClients) => {
80
  const { accessToken, tempId: clientTempId } = msg;
81
- console.log('[Auth] Login request received, token:', accessToken?.slice(0, 20) + '...');
82
  if (!accessToken) return safeSend(ws, { type: 'auth:error', message: 'Missing token' });
83
  const user = await verifySupabaseToken(accessToken);
84
  if (!user) return safeSend(ws, { type: 'auth:error', message: 'Invalid token' });
85
- console.log('[Auth] User verified:', user.id);
86
 
87
  client.userId = user.id; client.accessToken = accessToken; client.authenticated = true;
88
  client.deviceToken = deviceSessionStore.create(user.id, client.ip, client.userAgent);
@@ -92,18 +90,15 @@ const handlers = {
92
  const tId = client.tempId;
93
  await sessionStore.transferTempToUser(tId, user.id, accessToken);
94
 
95
- console.log('[Auth] Fetching user data...');
96
  const [sessions, settings, profile, subscription] = await Promise.all([
97
  sessionStore.loadUserSessions(user.id, accessToken),
98
  getUserSettings(user.id, accessToken),
99
  getUserProfile(user.id, accessToken),
100
  getSubscriptionInfo(accessToken),
101
  ]);
102
- console.log('[Auth] User data fetched - subscription:', subscription);
103
 
104
  const authOkMsg = { type: 'auth:ok', userId: user.id, email: user.email,
105
  deviceToken: client.deviceToken, sessions: sessions.map(ser), settings, profile, subscription };
106
- console.log('[Auth] Sending auth:ok with subscription:', subscription);
107
  safeSend(ws, authOkMsg);
108
 
109
  bcast(wsClients, user.id, { type: 'auth:newLogin', message: 'New login on your account.',
@@ -300,7 +295,6 @@ const handlers = {
300
  console.error(`chat:editMessage: Message at index ${messageIndex} not found. History length: ${flatHistory.length}`);
301
  return safeSend(ws, { type: 'error', message: 'Message not found' });
302
  }
303
- console.log(`chat:editMessage: Editing message ${targetMsg.id} at index ${messageIndex}`);
304
 
305
  // Find the target message in the tree and add new version
306
  const newRoot = validateAndRepairTree(JSON.parse(JSON.stringify(rootMessage)));
@@ -333,7 +327,6 @@ const handlers = {
333
  return safeSend(ws, { type: 'error', message: 'Failed to apply edit - message lost' });
334
  }
335
 
336
- console.log(`chat:editMessage: Edit complete. Message ${updatedTargetMsg.id} now has ${updatedTargetMsg.versions?.length ?? 0} versions`);
337
  safeSend(ws, { type: 'chat:messageEdited', sessionId, messageId: targetMsg.id, messageIndex, message: updatedTargetMsg, history: updatedFlatHistory });
338
  },
339
 
@@ -389,9 +382,7 @@ const handlers = {
389
  'account:setUsername': async (ws, msg, c) => { if (!c.userId) return; safeSend(ws, { type: 'account:usernameResult', ...await setUsername(c.userId, c.accessToken, msg.username) }); },
390
  'account:getSubscription': async (ws, msg, c) => {
391
  if (!c.userId) return console.warn('[Account] getSubscription called without userId');
392
- console.log('[Account] getSubscription request for user:', c.userId);
393
  const subInfo = await getSubscriptionInfo(c.accessToken);
394
- console.log('[Account] getSubscription response:', subInfo);
395
  safeSend(ws, { type: 'account:subscription', info: subInfo });
396
  },
397
  'account:getUsage': async (ws, msg, c) => { safeSend(ws, { type: 'account:usage', usage: await getUsageInfo(c.accessToken) }); },
 
78
 
79
  'auth:login': async (ws, msg, client, wsClients) => {
80
  const { accessToken, tempId: clientTempId } = msg;
 
81
  if (!accessToken) return safeSend(ws, { type: 'auth:error', message: 'Missing token' });
82
  const user = await verifySupabaseToken(accessToken);
83
  if (!user) return safeSend(ws, { type: 'auth:error', message: 'Invalid token' });
 
84
 
85
  client.userId = user.id; client.accessToken = accessToken; client.authenticated = true;
86
  client.deviceToken = deviceSessionStore.create(user.id, client.ip, client.userAgent);
 
90
  const tId = client.tempId;
91
  await sessionStore.transferTempToUser(tId, user.id, accessToken);
92
 
 
93
  const [sessions, settings, profile, subscription] = await Promise.all([
94
  sessionStore.loadUserSessions(user.id, accessToken),
95
  getUserSettings(user.id, accessToken),
96
  getUserProfile(user.id, accessToken),
97
  getSubscriptionInfo(accessToken),
98
  ]);
 
99
 
100
  const authOkMsg = { type: 'auth:ok', userId: user.id, email: user.email,
101
  deviceToken: client.deviceToken, sessions: sessions.map(ser), settings, profile, subscription };
 
102
  safeSend(ws, authOkMsg);
103
 
104
  bcast(wsClients, user.id, { type: 'auth:newLogin', message: 'New login on your account.',
 
295
  console.error(`chat:editMessage: Message at index ${messageIndex} not found. History length: ${flatHistory.length}`);
296
  return safeSend(ws, { type: 'error', message: 'Message not found' });
297
  }
 
298
 
299
  // Find the target message in the tree and add new version
300
  const newRoot = validateAndRepairTree(JSON.parse(JSON.stringify(rootMessage)));
 
327
  return safeSend(ws, { type: 'error', message: 'Failed to apply edit - message lost' });
328
  }
329
 
 
330
  safeSend(ws, { type: 'chat:messageEdited', sessionId, messageId: targetMsg.id, messageIndex, message: updatedTargetMsg, history: updatedFlatHistory });
331
  },
332
 
 
382
  'account:setUsername': async (ws, msg, c) => { if (!c.userId) return; safeSend(ws, { type: 'account:usernameResult', ...await setUsername(c.userId, c.accessToken, msg.username) }); },
383
  'account:getSubscription': async (ws, msg, c) => {
384
  if (!c.userId) return console.warn('[Account] getSubscription called without userId');
 
385
  const subInfo = await getSubscriptionInfo(c.accessToken);
 
386
  safeSend(ws, { type: 'account:subscription', info: subInfo });
387
  },
388
  'account:getUsage': async (ws, msg, c) => { safeSend(ws, { type: 'account:usage', usage: await getUsageInfo(c.accessToken) }); },