mirror of
https://github.com/HeyPuter/puter.git
synced 2026-05-04 16:40:41 +00:00
clean: miscellaneous cleanups
Docker Image CI / build-and-push-image (push) Waiting to run
Maintain Release Merge PR / update-release-pr (push) Waiting to run
release-please / release-please (push) Waiting to run
test / test (18.x) (push) Waiting to run
test / test (20.x) (push) Waiting to run
test / test (22.x) (push) Waiting to run
Docker Image CI / build-and-push-image (push) Waiting to run
Maintain Release Merge PR / update-release-pr (push) Waiting to run
release-please / release-please (push) Waiting to run
test / test (18.x) (push) Waiting to run
test / test (20.x) (push) Waiting to run
test / test (22.x) (push) Waiting to run
This commit is contained in:
@@ -185,8 +185,7 @@ class AppInformationService {
|
||||
const db = this.services.get('database').get(DB_READ, 'apps');
|
||||
|
||||
let apps = await db.read('SELECT * FROM apps');
|
||||
for (let index = 0; index < apps.length; index++) {
|
||||
const app = apps[index];
|
||||
for ( const app of apps ) {
|
||||
kv.set('apps:name:' + app.name, app);
|
||||
kv.set('apps:id:' + app.id, app);
|
||||
kv.set('apps:uid:' + app.uid, app);
|
||||
@@ -249,9 +248,6 @@ class AppInformationService {
|
||||
const apps = await db.read(`SELECT uid, index_url FROM apps`);
|
||||
|
||||
for ( const app of apps ) {
|
||||
const sql =
|
||||
`SELECT COUNT(id) AS referral_count FROM user WHERE referrer = ?`;
|
||||
|
||||
const origin = origin_from_url(app.index_url);
|
||||
|
||||
// only count the referral if the origin hashes to the app's uid
|
||||
@@ -286,7 +282,6 @@ class AppInformationService {
|
||||
*/
|
||||
async _refresh_recent_cache () {
|
||||
const app_keys = kv.keys(`apps:uid:*`);
|
||||
// console.log('APP KEYS', app_keys);
|
||||
|
||||
let apps = [];
|
||||
for ( const key of app_keys ) {
|
||||
@@ -314,7 +309,6 @@ class AppInformationService {
|
||||
*/
|
||||
async _refresh_tags () {
|
||||
const app_keys = kv.keys(`apps:uid:*`);
|
||||
// console.log('APP KEYS', app_keys);
|
||||
|
||||
let apps = [];
|
||||
for ( const key of app_keys ) {
|
||||
|
||||
@@ -56,8 +56,7 @@ class BootScriptService extends BaseService {
|
||||
}
|
||||
};
|
||||
|
||||
for ( let i=0 ; i < boot_json.length ; i++ ) {
|
||||
const statement = boot_json[i];
|
||||
for ( const statement of boot_json ) {
|
||||
const [cmd, ...args] = statement;
|
||||
if ( ! scope[cmd] ) {
|
||||
throw new Error(`Unknown command: ${cmd}`);
|
||||
|
||||
@@ -66,9 +66,6 @@ class CommentService extends BaseService {
|
||||
});
|
||||
|
||||
if ( req.body.version ) {
|
||||
// this.attach_comment_to_fsentry_version({
|
||||
// node, comment, version,
|
||||
// });
|
||||
res.status(400).send('not implemented yet');
|
||||
return;
|
||||
} else {
|
||||
@@ -104,9 +101,6 @@ class CommentService extends BaseService {
|
||||
});
|
||||
|
||||
if ( req.body.version ) {
|
||||
// this.attach_comment_to_fsentry_version({
|
||||
// node, comment, version,
|
||||
// });
|
||||
res.status(400).send('not implemented yet');
|
||||
return;
|
||||
} else {
|
||||
|
||||
@@ -23,8 +23,8 @@ const { Context } = require("../util/context");
|
||||
const { DB_WRITE } = require('./database/consts');
|
||||
|
||||
const hash = v => {
|
||||
var sum = crypto.createHash('sha1');
|
||||
sum.update('foo');
|
||||
const sum = crypto.createHash('sha1');
|
||||
sum.update(v);
|
||||
return sum.digest();
|
||||
}
|
||||
|
||||
|
||||
@@ -191,7 +191,6 @@ class DevConsoleService extends BaseService {
|
||||
*/
|
||||
async _init () {
|
||||
const services = this.services;
|
||||
// await services.ready;
|
||||
const commands = services.get('commands');
|
||||
|
||||
const readline = require('readline');
|
||||
@@ -223,7 +222,6 @@ class DevConsoleService extends BaseService {
|
||||
await commands.executeRawCommand(input, console);
|
||||
}
|
||||
this._after_cmd();
|
||||
// rl.prompt();
|
||||
});
|
||||
|
||||
|
||||
@@ -354,26 +352,9 @@ class DevConsoleService extends BaseService {
|
||||
consoleLogManager.post_all(() => {
|
||||
this._post_write();
|
||||
})
|
||||
// logService.loggers.unshift({
|
||||
// onLogMessage: () => {
|
||||
// rl.pause();
|
||||
// rl.output.write('\x1b[2K\r');
|
||||
// }
|
||||
// });
|
||||
// logService.loggers.push({
|
||||
// onLogMessage: () => {
|
||||
// rl.resume();
|
||||
// rl._refreshLine();
|
||||
// }
|
||||
// });
|
||||
|
||||
// This prevents the promptline background from staying
|
||||
// when Ctrl+C is used to terminate the server
|
||||
/**
|
||||
* Handles the SIGINT signal to gracefully terminate the server.
|
||||
* This method ensures that the console output is reset and the process exits cleanly.
|
||||
* It is triggered when the user presses Ctrl+C in the terminal.
|
||||
*/
|
||||
rl.on('SIGINT', () => {
|
||||
process.stdout.write(`\x1b[0m\r`);
|
||||
process.exit(0);
|
||||
|
||||
@@ -112,7 +112,7 @@ class DevTODService extends BaseService {
|
||||
...random_tip,
|
||||
];
|
||||
if ( ! this.global_config.minimal_console ) {
|
||||
lines.unshift("\x1B[1mTip of the Day\x1B[0m"),
|
||||
lines.unshift("\x1B[1mTip of the Day\x1B[0m");
|
||||
lines.push("Type tod:dismiss to un-stick this message");
|
||||
}
|
||||
surrounding_box('33;1', lines);
|
||||
|
||||
@@ -74,22 +74,9 @@ class EventService extends BaseService {
|
||||
// actual emit
|
||||
const listeners = this.listeners_[part];
|
||||
if ( ! listeners ) continue;
|
||||
for ( let i = 0; i < listeners.length; i++ ) {
|
||||
const callback = listeners[i];
|
||||
|
||||
for ( const callback of listeners ) {
|
||||
// IIAFE wrapper to catch errors without blocking
|
||||
// event dispatch.
|
||||
/**
|
||||
* IIAFE wrapper to handle emitting events asynchronously while catching errors.
|
||||
* This method ensures that any errors thrown in the event listeners do not block
|
||||
* the dispatching of other events.
|
||||
*
|
||||
* @param {string} key - The event key to emit.
|
||||
* @param {any} data - The data to be sent with the event.
|
||||
* @param {Object} [meta={}] - Additional metadata for the event.
|
||||
*
|
||||
* @returns {void}
|
||||
*/
|
||||
Context.arun(async () => {
|
||||
try {
|
||||
await callback(key, data, meta);
|
||||
|
||||
@@ -131,11 +131,6 @@ class GetUserService extends BaseService {
|
||||
kv.set(`users:${prop}:${user[prop]}`, user);
|
||||
}
|
||||
}
|
||||
// kv.set('users:username:' + user.username, user);
|
||||
// kv.set('users:email:' + user.email, user);
|
||||
// kv.set('users:uuid:' + user.uuid, user);
|
||||
// kv.set('users:id:' + user.id, user);
|
||||
// kv.set('users:referral_code:' + user.referral_code, user);
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
}
|
||||
|
||||
@@ -78,15 +78,12 @@ class KernelInfoService extends BaseService {
|
||||
}
|
||||
|
||||
const services = [];
|
||||
const modules = [];
|
||||
for ( const k in this.services.modules_ ) {
|
||||
const module_info = {
|
||||
name: k,
|
||||
services: []
|
||||
};
|
||||
|
||||
modules.push(module_info);
|
||||
|
||||
for ( const s_k of this.services.modules_[k].services_l ) {
|
||||
const service_info = {
|
||||
name: s_k,
|
||||
|
||||
@@ -163,8 +163,6 @@ class PuterHomepageService extends BaseService {
|
||||
}) {
|
||||
const require = this.require;
|
||||
const {encode} = require('html-entities');
|
||||
const path_ = require('path');
|
||||
const fs_ = require('fs');
|
||||
|
||||
const e = encode;
|
||||
|
||||
@@ -175,7 +173,6 @@ class PuterHomepageService extends BaseService {
|
||||
company,
|
||||
canonical_url,
|
||||
social_media_image,
|
||||
icon,
|
||||
} = meta;
|
||||
|
||||
gui_params = {
|
||||
@@ -190,7 +187,6 @@ class PuterHomepageService extends BaseService {
|
||||
|
||||
const asset_dir = env === 'dev'
|
||||
? '/src' : '/dist' ;
|
||||
// const asset_dir = '/dist';
|
||||
|
||||
gui_params.asset_dir = asset_dir;
|
||||
|
||||
@@ -209,12 +205,6 @@ class PuterHomepageService extends BaseService {
|
||||
// set social media image to default if it is not valid
|
||||
const social_media_image_url = social_media_image || `${asset_dir}/images/screenshot.png`;
|
||||
|
||||
const writeScriptTag = path =>
|
||||
`<script type="${
|
||||
Array.isArray(path) ? 'text/javascirpt' : 'module'
|
||||
}" src="${Array.isArray(path) ? path[0] : path}"></script>\n`
|
||||
;
|
||||
|
||||
return `<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
|
||||
|
||||
@@ -23,7 +23,7 @@ const { Context } = require('../util/context');
|
||||
const { get_user } = require('../helpers');
|
||||
const { DB_WRITE } = require('./database/consts');
|
||||
const BaseService = require('./BaseService');
|
||||
const { UsernameNotifSelector, UserIDNotifSelector } = require('./NotificationService');
|
||||
const { UserIDNotifSelector } = require('./NotificationService');
|
||||
|
||||
|
||||
/**
|
||||
@@ -112,7 +112,7 @@ class ReferralCodeService extends BaseService {
|
||||
referral_code = generate_random_code(8, { rng });
|
||||
}
|
||||
try {
|
||||
const update_res = db.write(`
|
||||
db.write(`
|
||||
UPDATE user SET referral_code=? WHERE id=?
|
||||
`, [referral_code, user.id]);
|
||||
return referral_code;
|
||||
|
||||
@@ -1,31 +0,0 @@
|
||||
// METADATA // {"ai-commented":{"service":"claude"}}
|
||||
/*
|
||||
* Copyright (C) 2024 Puter Technologies Inc.
|
||||
*
|
||||
* This file is part of Puter.
|
||||
*
|
||||
* Puter is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published
|
||||
* by the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/**
|
||||
* ServeLandingService is for "landing" pages, like payment success or failure.
|
||||
*/
|
||||
/**
|
||||
* @class ServeLandingService
|
||||
* @description Handles the serving and rendering of landing pages throughout the Puter platform.
|
||||
* This service manages various landing pages such as payment success/failure pages, confirmation
|
||||
* pages, and other static informational pages. It provides a centralized way to serve these
|
||||
* pages while maintaining consistent styling and functionality across the platform.
|
||||
*/
|
||||
class ServceLandingService {}
|
||||
@@ -93,7 +93,6 @@ class ShareService extends BaseService {
|
||||
user: issuer_user,
|
||||
});
|
||||
|
||||
// const svc_permission = this.services.get('permission');
|
||||
const svc_acl = this.services.get('acl');
|
||||
|
||||
for ( const permission of share.data.permissions ) {
|
||||
|
||||
@@ -299,12 +299,6 @@ class WSPushService extends BaseService {
|
||||
|
||||
if ( ! socket_id ) {
|
||||
this.log.error('missing socket id', { metadata });
|
||||
|
||||
// TODO: this error is temporarily disabled for
|
||||
// Puter V1 release, because it will cause a
|
||||
// lot of redundant PagerDuty alerts.
|
||||
|
||||
// throw new Error('missing socket id');
|
||||
}
|
||||
|
||||
this.log.info('socket id: ' + socket_id);
|
||||
|
||||
@@ -248,11 +248,6 @@ class ACLService extends BaseService {
|
||||
|
||||
const stat = await this.stat_user_user(issuer, holder, resource);
|
||||
|
||||
// this.log.info('stat object', {
|
||||
// stat,
|
||||
// path: await resource.get('path')
|
||||
// });
|
||||
|
||||
const perms_on_this = stat[await resource.get('path')] ?? [];
|
||||
|
||||
const mode_parts = perms_on_this.map(perm => PermissionUtil.split(perm)[2]);
|
||||
@@ -463,7 +458,6 @@ class ACLService extends BaseService {
|
||||
|
||||
const svc_permission = await context.get('services').get('permission');
|
||||
|
||||
// const modes = this._higher_modes(mode);
|
||||
const modes = [mode];
|
||||
let perm_fsNode = fsNode;
|
||||
while ( ! await perm_fsNode.get('is-root') ) {
|
||||
|
||||
@@ -140,6 +140,13 @@ class Actor extends AdvancedBase {
|
||||
}
|
||||
}
|
||||
|
||||
class ActorType {
|
||||
constructor (o) {
|
||||
for ( const k in o ) {
|
||||
this[k] = o[k];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Class representing the system actor type within the actor framework.
|
||||
@@ -147,13 +154,7 @@ class Actor extends AdvancedBase {
|
||||
* represents a system-level entity and provides methods for UID retrieval
|
||||
* and related type management.
|
||||
*/
|
||||
class SystemActorType {
|
||||
constructor (o, ...a) {
|
||||
// super(o, ...a);
|
||||
for ( const k in o ) {
|
||||
this[k] = o[k];
|
||||
}
|
||||
}
|
||||
class SystemActorType extends ActorType {
|
||||
/**
|
||||
* Constructs a new instance of the actor type.
|
||||
*
|
||||
@@ -179,13 +180,7 @@ class SystemActorType {
|
||||
* specific to user actors. This class extends the base functionality to uniquely identify
|
||||
* user actors and define how they relate to other types of actors within the system.
|
||||
*/
|
||||
class UserActorType {
|
||||
constructor (o, ...a) {
|
||||
// super(o, ...a);
|
||||
for ( const k in o ) {
|
||||
this[k] = o[k];
|
||||
}
|
||||
}
|
||||
class UserActorType extends ActorType {
|
||||
/**
|
||||
* Constructs a new UserActorType instance.
|
||||
*
|
||||
@@ -208,13 +203,7 @@ class UserActorType {
|
||||
* retrieving related actor types. It extends the base actor type functionality
|
||||
* to cater to user-specific needs.
|
||||
*/
|
||||
class AppUnderUserActorType {
|
||||
constructor (o, ...a) {
|
||||
// super(o, ...a);
|
||||
for ( const k in o ) {
|
||||
this[k] = o[k];
|
||||
}
|
||||
}
|
||||
class AppUnderUserActorType extends ActorType {
|
||||
/**
|
||||
* Create a new instance of the actor type, initializing it with the given parameters.
|
||||
*
|
||||
@@ -246,16 +235,11 @@ class AppUnderUserActorType {
|
||||
* An AccessTokenActorType associates an authorizer and an authorized actor
|
||||
* with a string token, facilitating permission checks and identity management.
|
||||
*/
|
||||
class AccessTokenActorType {
|
||||
class AccessTokenActorType extends ActorType {
|
||||
// authorizer: an Actor who authorized the token
|
||||
// authorized: an Actor who is authorized by the token
|
||||
// token: a string
|
||||
constructor (o, ...a) {
|
||||
// super(o, ...a);
|
||||
for ( const k in o ) {
|
||||
this[k] = o[k];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs an instance of AccessTokenActorType.
|
||||
* This class represents an access token actor containing information
|
||||
|
||||
@@ -17,7 +17,6 @@
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
const TeePromise = require("@heyputer/multest/src/util/TeePromise");
|
||||
const { AdvancedBase } = require("@heyputer/putility");
|
||||
const { FileTracker } = require("./FileTracker");
|
||||
const { pausing_tee } = require("../../util/streamutil");
|
||||
@@ -129,7 +128,7 @@ class FileCacheService extends AdvancedBase {
|
||||
}
|
||||
|
||||
_get_path (uid) {
|
||||
const { path_, fs } = this.modules;
|
||||
const { path_ } = this.modules;
|
||||
return path_.join(this.path, uid);
|
||||
}
|
||||
|
||||
@@ -351,9 +350,8 @@ class FileCacheService extends AdvancedBase {
|
||||
|
||||
const { fs } = this.modules;
|
||||
const path = this._get_path(tracker.key);
|
||||
console.log(`precache fetch key I guess?`, tracker.key);
|
||||
console.log(`precache fetch key`, tracker.key);
|
||||
const data = this.precache.get(tracker.key);
|
||||
// console.log(`path and data: ${path} ${data}`);
|
||||
await fs.promises.writeFile(path, data);
|
||||
this.precache.delete(tracker.key);
|
||||
tracker.phase = FileTracker.PHASE_DISK;
|
||||
@@ -384,9 +382,6 @@ class FileCacheService extends AdvancedBase {
|
||||
{
|
||||
id: 'status',
|
||||
handler: async (args, log) => {
|
||||
const { fs } = this.modules;
|
||||
const path = this._get_path('status');
|
||||
|
||||
const status = {
|
||||
precache: {
|
||||
used: this._precache_used,
|
||||
|
||||
@@ -173,16 +173,6 @@ class MonthlyUsageService extends BaseService {
|
||||
// months are zero-indexed by getUTCMonth, which could be confusing
|
||||
const month = new Date().getUTCMonth() + 1;
|
||||
|
||||
// console.log(
|
||||
// 'what check query?',
|
||||
// 'SELECT SUM(`count`) AS sum FROM `service_usage_monthly` ' +
|
||||
// 'WHERE `year` = ? AND `month` = ? AND `user_id` = ? ' +
|
||||
// 'AND `key` = ?',
|
||||
// [
|
||||
// year, month, actor.type.user.id,
|
||||
// key,
|
||||
// ]
|
||||
// );
|
||||
const rows = await this.db.read(
|
||||
'SELECT SUM(`count`) AS sum FROM `service_usage_monthly` ' +
|
||||
'WHERE `year` = ? AND `month` = ? AND `user_id` = ? ' +
|
||||
@@ -211,8 +201,6 @@ class MonthlyUsageService extends BaseService {
|
||||
// months are zero-indexed by getUTCMonth, which could be confusing
|
||||
const month = new Date().getUTCMonth() + 1;
|
||||
|
||||
const specifier_entries = Object.entries(specifiers);
|
||||
|
||||
// SELECT count
|
||||
const rows = await this.db.read(
|
||||
'SELECT `count` FROM `service_usage_monthly` ' +
|
||||
|
||||
@@ -90,11 +90,6 @@ class RateLimitService extends BaseService {
|
||||
window_start = ts_fr_sql(row.window_start);
|
||||
const count = row.count;
|
||||
|
||||
// console.log(
|
||||
// 'set window_start and count from DATABASE',
|
||||
// { window_start, count }
|
||||
// );
|
||||
|
||||
kv.set(`${kvkey}:window_start`, window_start);
|
||||
kv.set(`${kvkey}:count`, count);
|
||||
}
|
||||
@@ -116,21 +111,11 @@ class RateLimitService extends BaseService {
|
||||
);
|
||||
}
|
||||
|
||||
// console.log(
|
||||
// 'DEBUGGING COMPARISON',
|
||||
// { window_start, period, now: Date.now() }
|
||||
// );
|
||||
|
||||
if ( window_start + period < Date.now() ) {
|
||||
window_start = Date.now();
|
||||
kv.set(`${kvkey}:window_start`, window_start);
|
||||
kv.set(`${kvkey}:count`, 0);
|
||||
|
||||
// console.log(
|
||||
// 'REFRESH window_start and count',
|
||||
// { window_start, count: 0 }
|
||||
// );
|
||||
|
||||
await this.db.write(
|
||||
'UPDATE `rl_usage_fixed_window` SET `window_start` = ?, `count` = ? WHERE `key` = ?',
|
||||
[ts_to_sql(window_start), 0, dbkey]
|
||||
|
||||
@@ -382,8 +382,6 @@ class HTTPThumbnailService extends BaseService {
|
||||
* generation or undefined if an error occurred.
|
||||
*/
|
||||
async exec_0 (queue) {
|
||||
const { axios } = this.modules;
|
||||
|
||||
this.log.info('starting thumbnail request');
|
||||
const resp = await this.request_({ queue });
|
||||
this.log.info('done thumbnail request');
|
||||
@@ -448,8 +446,7 @@ class HTTPThumbnailService extends BaseService {
|
||||
let expected = 0;
|
||||
for ( const job of queue ) {
|
||||
expected++;
|
||||
// const blob = new Blob([job.file.buffer], { type: job.file.mimetype });
|
||||
// form.append('file', blob, job.file.filename);
|
||||
|
||||
/**
|
||||
* Prepares and sends a request to the thumbnail service for processing multiple files.
|
||||
*
|
||||
@@ -462,12 +459,7 @@ class HTTPThumbnailService extends BaseService {
|
||||
job.file.size = job.file.buffer.length;
|
||||
return buffer_to_stream(job.file.buffer);
|
||||
})() : job.file.stream;
|
||||
// const file_data = job.file.buffer ?? job.file.stream;
|
||||
console.log('INFORMATION ABOUT THIS FILE', {
|
||||
file_has_a_buffer: !!job.file.buffer,
|
||||
file_has_a_stream: !!job.file.stream,
|
||||
file: job.file,
|
||||
});
|
||||
|
||||
form.append('file', file_data, {
|
||||
filename: job.file.name ?? job.file.originalname,
|
||||
contentType: job.file.type ?? job.file.mimetype,
|
||||
|
||||
Reference in New Issue
Block a user