Skip to content

Commit 06aeae5

Browse files
committed
clean: miscellaneous cleanups
1 parent 3329393 commit 06aeae5

20 files changed

+24
-187
lines changed

Diff for: src/backend/src/services/AppInformationService.js

+1-7
Original file line numberDiff line numberDiff line change
@@ -185,8 +185,7 @@ class AppInformationService {
185185
const db = this.services.get('database').get(DB_READ, 'apps');
186186

187187
let apps = await db.read('SELECT * FROM apps');
188-
for (let index = 0; index < apps.length; index++) {
189-
const app = apps[index];
188+
for ( const app of apps ) {
190189
kv.set('apps:name:' + app.name, app);
191190
kv.set('apps:id:' + app.id, app);
192191
kv.set('apps:uid:' + app.uid, app);
@@ -249,9 +248,6 @@ class AppInformationService {
249248
const apps = await db.read(`SELECT uid, index_url FROM apps`);
250249

251250
for ( const app of apps ) {
252-
const sql =
253-
`SELECT COUNT(id) AS referral_count FROM user WHERE referrer = ?`;
254-
255251
const origin = origin_from_url(app.index_url);
256252

257253
// only count the referral if the origin hashes to the app's uid
@@ -286,7 +282,6 @@ class AppInformationService {
286282
*/
287283
async _refresh_recent_cache () {
288284
const app_keys = kv.keys(`apps:uid:*`);
289-
// console.log('APP KEYS', app_keys);
290285

291286
let apps = [];
292287
for ( const key of app_keys ) {
@@ -314,7 +309,6 @@ class AppInformationService {
314309
*/
315310
async _refresh_tags () {
316311
const app_keys = kv.keys(`apps:uid:*`);
317-
// console.log('APP KEYS', app_keys);
318312

319313
let apps = [];
320314
for ( const key of app_keys ) {

Diff for: src/backend/src/services/BootScriptService.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,7 @@ class BootScriptService extends BaseService {
5656
}
5757
};
5858

59-
for ( let i=0 ; i < boot_json.length ; i++ ) {
60-
const statement = boot_json[i];
59+
for ( const statement of boot_json ) {
6160
const [cmd, ...args] = statement;
6261
if ( ! scope[cmd] ) {
6362
throw new Error(`Unknown command: ${cmd}`);

Diff for: src/backend/src/services/CommentService.js

-6
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,6 @@ class CommentService extends BaseService {
6666
});
6767

6868
if ( req.body.version ) {
69-
// this.attach_comment_to_fsentry_version({
70-
// node, comment, version,
71-
// });
7269
res.status(400).send('not implemented yet');
7370
return;
7471
} else {
@@ -104,9 +101,6 @@ class CommentService extends BaseService {
104101
});
105102

106103
if ( req.body.version ) {
107-
// this.attach_comment_to_fsentry_version({
108-
// node, comment, version,
109-
// });
110104
res.status(400).send('not implemented yet');
111105
return;
112106
} else {

Diff for: src/backend/src/services/ConfigurableCountingService.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ const { Context } = require("../util/context");
2323
const { DB_WRITE } = require('./database/consts');
2424

2525
const hash = v => {
26-
var sum = crypto.createHash('sha1');
27-
sum.update('foo');
26+
const sum = crypto.createHash('sha1');
27+
sum.update(v);
2828
return sum.digest();
2929
}
3030

Diff for: src/backend/src/services/DevConsoleService.js

-19
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,6 @@ class DevConsoleService extends BaseService {
191191
*/
192192
async _init () {
193193
const services = this.services;
194-
// await services.ready;
195194
const commands = services.get('commands');
196195

197196
const readline = require('readline');
@@ -223,7 +222,6 @@ class DevConsoleService extends BaseService {
223222
await commands.executeRawCommand(input, console);
224223
}
225224
this._after_cmd();
226-
// rl.prompt();
227225
});
228226

229227

@@ -354,26 +352,9 @@ class DevConsoleService extends BaseService {
354352
consoleLogManager.post_all(() => {
355353
this._post_write();
356354
})
357-
// logService.loggers.unshift({
358-
// onLogMessage: () => {
359-
// rl.pause();
360-
// rl.output.write('\x1b[2K\r');
361-
// }
362-
// });
363-
// logService.loggers.push({
364-
// onLogMessage: () => {
365-
// rl.resume();
366-
// rl._refreshLine();
367-
// }
368-
// });
369355

370356
// This prevents the promptline background from staying
371357
// when Ctrl+C is used to terminate the server
372-
/**
373-
* Handles the SIGINT signal to gracefully terminate the server.
374-
* This method ensures that the console output is reset and the process exits cleanly.
375-
* It is triggered when the user presses Ctrl+C in the terminal.
376-
*/
377358
rl.on('SIGINT', () => {
378359
process.stdout.write(`\x1b[0m\r`);
379360
process.exit(0);

Diff for: src/backend/src/services/DevTODService.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ class DevTODService extends BaseService {
112112
...random_tip,
113113
];
114114
if ( ! this.global_config.minimal_console ) {
115-
lines.unshift("\x1B[1mTip of the Day\x1B[0m"),
115+
lines.unshift("\x1B[1mTip of the Day\x1B[0m");
116116
lines.push("Type tod:dismiss to un-stick this message");
117117
}
118118
surrounding_box('33;1', lines);

Diff for: src/backend/src/services/EventService.js

+1-14
Original file line numberDiff line numberDiff line change
@@ -74,22 +74,9 @@ class EventService extends BaseService {
7474
// actual emit
7575
const listeners = this.listeners_[part];
7676
if ( ! listeners ) continue;
77-
for ( let i = 0; i < listeners.length; i++ ) {
78-
const callback = listeners[i];
79-
77+
for ( const callback of listeners ) {
8078
// IIAFE wrapper to catch errors without blocking
8179
// event dispatch.
82-
/**
83-
* IIAFE wrapper to handle emitting events asynchronously while catching errors.
84-
* This method ensures that any errors thrown in the event listeners do not block
85-
* the dispatching of other events.
86-
*
87-
* @param {string} key - The event key to emit.
88-
* @param {any} data - The data to be sent with the event.
89-
* @param {Object} [meta={}] - Additional metadata for the event.
90-
*
91-
* @returns {void}
92-
*/
9380
Context.arun(async () => {
9481
try {
9582
await callback(key, data, meta);

Diff for: src/backend/src/services/GetUserService.js

-5
Original file line numberDiff line numberDiff line change
@@ -131,11 +131,6 @@ class GetUserService extends BaseService {
131131
kv.set(`users:${prop}:${user[prop]}`, user);
132132
}
133133
}
134-
// kv.set('users:username:' + user.username, user);
135-
// kv.set('users:email:' + user.email, user);
136-
// kv.set('users:uuid:' + user.uuid, user);
137-
// kv.set('users:id:' + user.id, user);
138-
// kv.set('users:referral_code:' + user.referral_code, user);
139134
} catch (e) {
140135
console.error(e);
141136
}

Diff for: src/backend/src/services/KernelInfoService.js

-3
Original file line numberDiff line numberDiff line change
@@ -78,15 +78,12 @@ class KernelInfoService extends BaseService {
7878
}
7979

8080
const services = [];
81-
const modules = [];
8281
for ( const k in this.services.modules_ ) {
8382
const module_info = {
8483
name: k,
8584
services: []
8685
};
8786

88-
modules.push(module_info);
89-
9087
for ( const s_k of this.services.modules_[k].services_l ) {
9188
const service_info = {
9289
name: s_k,

Diff for: src/backend/src/services/PuterHomepageService.js

-10
Original file line numberDiff line numberDiff line change
@@ -163,8 +163,6 @@ class PuterHomepageService extends BaseService {
163163
}) {
164164
const require = this.require;
165165
const {encode} = require('html-entities');
166-
const path_ = require('path');
167-
const fs_ = require('fs');
168166

169167
const e = encode;
170168

@@ -175,7 +173,6 @@ class PuterHomepageService extends BaseService {
175173
company,
176174
canonical_url,
177175
social_media_image,
178-
icon,
179176
} = meta;
180177

181178
gui_params = {
@@ -190,7 +187,6 @@ class PuterHomepageService extends BaseService {
190187

191188
const asset_dir = env === 'dev'
192189
? '/src' : '/dist' ;
193-
// const asset_dir = '/dist';
194190

195191
gui_params.asset_dir = asset_dir;
196192

@@ -209,12 +205,6 @@ class PuterHomepageService extends BaseService {
209205
// set social media image to default if it is not valid
210206
const social_media_image_url = social_media_image || `${asset_dir}/images/screenshot.png`;
211207

212-
const writeScriptTag = path =>
213-
`<script type="${
214-
Array.isArray(path) ? 'text/javascirpt' : 'module'
215-
}" src="${Array.isArray(path) ? path[0] : path}"></script>\n`
216-
;
217-
218208
return `<!DOCTYPE html>
219209
<html lang="en">
220210

Diff for: src/backend/src/services/ReferralCodeService.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ const { Context } = require('../util/context');
2323
const { get_user } = require('../helpers');
2424
const { DB_WRITE } = require('./database/consts');
2525
const BaseService = require('./BaseService');
26-
const { UsernameNotifSelector, UserIDNotifSelector } = require('./NotificationService');
26+
const { UserIDNotifSelector } = require('./NotificationService');
2727

2828

2929
/**
@@ -112,7 +112,7 @@ class ReferralCodeService extends BaseService {
112112
referral_code = generate_random_code(8, { rng });
113113
}
114114
try {
115-
const update_res = db.write(`
115+
db.write(`
116116
UPDATE user SET referral_code=? WHERE id=?
117117
`, [referral_code, user.id]);
118118
return referral_code;

Diff for: src/backend/src/services/ServeLandingService.js

-31
This file was deleted.

Diff for: src/backend/src/services/ShareService.js

-1
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,6 @@ class ShareService extends BaseService {
9393
user: issuer_user,
9494
});
9595

96-
// const svc_permission = this.services.get('permission');
9796
const svc_acl = this.services.get('acl');
9897

9998
for ( const permission of share.data.permissions ) {

Diff for: src/backend/src/services/WSPushService.js

-6
Original file line numberDiff line numberDiff line change
@@ -299,12 +299,6 @@ class WSPushService extends BaseService {
299299

300300
if ( ! socket_id ) {
301301
this.log.error('missing socket id', { metadata });
302-
303-
// TODO: this error is temporarily disabled for
304-
// Puter V1 release, because it will cause a
305-
// lot of redundant PagerDuty alerts.
306-
307-
// throw new Error('missing socket id');
308302
}
309303

310304
this.log.info('socket id: ' + socket_id);

Diff for: src/backend/src/services/auth/ACLService.js

-6
Original file line numberDiff line numberDiff line change
@@ -248,11 +248,6 @@ class ACLService extends BaseService {
248248

249249
const stat = await this.stat_user_user(issuer, holder, resource);
250250

251-
// this.log.info('stat object', {
252-
// stat,
253-
// path: await resource.get('path')
254-
// });
255-
256251
const perms_on_this = stat[await resource.get('path')] ?? [];
257252

258253
const mode_parts = perms_on_this.map(perm => PermissionUtil.split(perm)[2]);
@@ -463,7 +458,6 @@ class ACLService extends BaseService {
463458

464459
const svc_permission = await context.get('services').get('permission');
465460

466-
// const modes = this._higher_modes(mode);
467461
const modes = [mode];
468462
let perm_fsNode = fsNode;
469463
while ( ! await perm_fsNode.get('is-root') ) {

Diff for: src/backend/src/services/auth/Actor.js

+12-28
Original file line numberDiff line numberDiff line change
@@ -140,20 +140,21 @@ class Actor extends AdvancedBase {
140140
}
141141
}
142142

143+
class ActorType {
144+
constructor (o) {
145+
for ( const k in o ) {
146+
this[k] = o[k];
147+
}
148+
}
149+
}
143150

144151
/**
145152
* Class representing the system actor type within the actor framework.
146153
* This type serves as a specific implementation of an actor that
147154
* represents a system-level entity and provides methods for UID retrieval
148155
* and related type management.
149156
*/
150-
class SystemActorType {
151-
constructor (o, ...a) {
152-
// super(o, ...a);
153-
for ( const k in o ) {
154-
this[k] = o[k];
155-
}
156-
}
157+
class SystemActorType extends ActorType {
157158
/**
158159
* Constructs a new instance of the actor type.
159160
*
@@ -179,13 +180,7 @@ class SystemActorType {
179180
* specific to user actors. This class extends the base functionality to uniquely identify
180181
* user actors and define how they relate to other types of actors within the system.
181182
*/
182-
class UserActorType {
183-
constructor (o, ...a) {
184-
// super(o, ...a);
185-
for ( const k in o ) {
186-
this[k] = o[k];
187-
}
188-
}
183+
class UserActorType extends ActorType {
189184
/**
190185
* Constructs a new UserActorType instance.
191186
*
@@ -208,13 +203,7 @@ class UserActorType {
208203
* retrieving related actor types. It extends the base actor type functionality
209204
* to cater to user-specific needs.
210205
*/
211-
class AppUnderUserActorType {
212-
constructor (o, ...a) {
213-
// super(o, ...a);
214-
for ( const k in o ) {
215-
this[k] = o[k];
216-
}
217-
}
206+
class AppUnderUserActorType extends ActorType {
218207
/**
219208
* Create a new instance of the actor type, initializing it with the given parameters.
220209
*
@@ -246,16 +235,11 @@ class AppUnderUserActorType {
246235
* An AccessTokenActorType associates an authorizer and an authorized actor
247236
* with a string token, facilitating permission checks and identity management.
248237
*/
249-
class AccessTokenActorType {
238+
class AccessTokenActorType extends ActorType {
250239
// authorizer: an Actor who authorized the token
251240
// authorized: an Actor who is authorized by the token
252241
// token: a string
253-
constructor (o, ...a) {
254-
// super(o, ...a);
255-
for ( const k in o ) {
256-
this[k] = o[k];
257-
}
258-
}
242+
259243
/**
260244
* Constructs an instance of AccessTokenActorType.
261245
* This class represents an access token actor containing information

0 commit comments

Comments
 (0)