Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 5 additions & 11 deletions src/backend/src/ExtensionService.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
*/

const { AdvancedBase } = require('@heyputer/putility');
const eggspress = require('./api/eggspress');
const BaseService = require('./services/BaseService');
const { Endpoint } = require('./util/expressutil');
const configurable_auth = require('./middleware/configurable_auth');
const { Context } = require('./util/context');
const { DB_WRITE } = require('./services/database/consts');
Expand Down Expand Up @@ -58,16 +58,14 @@ class ExtensionServiceState extends AdvancedBase {
mw.push(configurable_auth(auth_conf));
}

const endpoint = Endpoint({
methods: options.methods ?? ['GET'],
const router = eggspress(path, {
allowedMethods: options.methods ?? ['GET'],
mw,
route: path,
handler: handler,
...(options.subdomain ? { subdomain: options.subdomain } : {}),
otherOpts: options.otherOpts || {},
});
}, handler);

this.expressThings_.push({ type: 'endpoint', value: endpoint });
this.expressThings_.push({ type: 'router', value: [router] });
}
}

Expand Down Expand Up @@ -181,10 +179,6 @@ class ExtensionService extends BaseService {

'__on_install.routes' (_, { app }) {
for ( const thing of this.state.expressThings_ ) {
if ( thing.type === 'endpoint' ) {
thing.value.attach(app);
continue;
}
if ( thing.type === 'router' ) {
app.use(...thing.value);
continue;
Expand Down
19 changes: 0 additions & 19 deletions src/backend/src/filesystem/batch/BatchExecutor.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ const APIError = require('../../api/APIError');
const { Context } = require('../../util/context');
const config = require('../../config');
const { TeePromise } = require('@heyputer/putility').libs.promise;
const { WorkUnit } = require('../../modules/core/lib/expect');

class BatchExecutor extends AdvancedBase {
static LOG_LEVEL = true;

Expand All @@ -33,7 +31,6 @@ class BatchExecutor extends AdvancedBase {
this.x = x;
this.actor = actor;
this.pathResolver = new PathResolver({ actor });
this.expectations = x.get('services').get('expectations');
this.log = log;
this.errors = errors;
this.responsePromises = [];
Expand Down Expand Up @@ -64,19 +61,12 @@ class BatchExecutor extends AdvancedBase {

this.concurrent_ops++;

const { expectations } = this;
const command_cls = commands[op.op];
if ( this.log_batchCommands ) {
console.log(command_cls, JSON.stringify(op, null, 2));
}
delete op.op;

const workUnit = WorkUnit.create();
expectations.expect_eventually({
workUnit,
checkpoint: 'operation responded',
});

// TEMP: event service will handle this
op.original_client_socket_id = req.body.original_client_socket_id;
op.socket_id = req.body.socket_id;
Expand All @@ -93,22 +83,13 @@ class BatchExecutor extends AdvancedBase {
});
}

if ( file ) {
workUnit.checkpoint(`about to run << ${
file.originalname ?? file.name
} >> ${
JSON.stringify(op)}`);
}
const command_ins = await command_cls.run({
getFile: () => file,
pathResolver: this.pathResolver,
actor: this.actor,
}, op);
workUnit.checkpoint('operation invoked');

const res = await command_ins.awaitValue('result');
// const res = await opctx.awaitValue('response');
workUnit.checkpoint('operation responded');
return res;
} catch (e) {
this.hasError = true;
Expand Down
18 changes: 7 additions & 11 deletions src/backend/src/modules/apps/AppIconService.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import { NodePathSelector } from '../../filesystem/node/selectors.js';
import { get_app } from '../../helpers.js';
import BaseService from '../../services/BaseService.js';
import { DB_READ, DB_WRITE } from '../../services/database/consts.js';
import { Endpoint } from '../../util/expressutil.js';
import eggspress from '../../api/eggspress.js';
import { buffer_to_stream, stream_to_buffer } from '../../util/streamutil.js';
import { AppRedisCacheSpace } from './AppRedisCacheSpace.js';
import DEFAULT_APP_ICON from './default-app-icon.js';
Expand Down Expand Up @@ -106,16 +106,12 @@ export class AppIconService extends BaseService {
stream.pipe(res);
};

Endpoint({
route: '/app-icon/:app_uid',
methods: ['GET'],
handler,
}).attach(app);
Endpoint({
route: '/app-icon/:app_uid/:size',
methods: ['GET'],
handler,
}).attach(app);
app.use(eggspress('/app-icon/:app_uid', {
allowedMethods: ['GET'],
}, handler));
app.use(eggspress('/app-icon/:app_uid/:size', {
allowedMethods: ['GET'],
}, handler));
}

getSizes () {
Expand Down
11 changes: 4 additions & 7 deletions src/backend/src/modules/broadcast/BroadcastService.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ import { createHmac, randomUUID, timingSafeEqual } from 'crypto';
import { Agent as HttpsAgent } from 'https';
import axios from 'axios';
import { redisClient } from '../../clients/redis/redisSingleton.js';
import eggspress from '../../api/eggspress.js';
import { BaseService } from '../../services/BaseService.js';
import { Context } from '../../util/context.js';
import { Endpoint } from '../../util/expressutil.js';

export class BroadcastService extends BaseService {
#peersByKey = {};
Expand Down Expand Up @@ -348,12 +348,9 @@ export class BroadcastService extends BaseService {
const svc_web = this.services.get('web-server');
svc_web.allow_undefined_origin('/broadcast/webhook');

// TODO DS: stop using Endpoint
Endpoint({
route: '/broadcast/webhook',
methods: ['POST'],
handler: this.#handleWebhookRequest.bind(this),
}).attach(app);
app.use(eggspress('/broadcast/webhook', {
allowedMethods: ['POST'],
}, this.#handleWebhookRequest.bind(this)));
}

async #handleWebhookRequest (req, res) {
Expand Down
106 changes: 52 additions & 54 deletions src/backend/src/modules/captcha/services/CaptchaService.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*/

const BaseService = require('../../../services/BaseService');
const { Endpoint } = require('../../../util/expressutil');
const eggspress = require('../../../api/eggspress');
const { checkCaptcha } = require('../middleware/captcha-middleware');

/**
Expand Down Expand Up @@ -129,36 +129,32 @@ class CaptchaService extends BaseService {
app.use('/api/captcha', api);

// Generate captcha endpoint
Endpoint({
route: '/generate',
methods: ['GET'],
handler: async (req, res) => {
const captcha = this.generateCaptcha();
res.json({
token: captcha.token,
image: captcha.data,
});
},
}).attach(api);
api.use(eggspress('/generate', {
allowedMethods: ['GET'],
}, async (req, res) => {
const captcha = this.generateCaptcha();
res.json({
token: captcha.token,
image: captcha.data,
});
}));

// Verify captcha endpoint
Endpoint({
route: '/verify',
methods: ['POST'],
handler: (req, res) => {
const { token, answer } = req.body;

if ( !token || !answer ) {
return res.status(400).json({
valid: false,
error: 'Missing token or answer',
});
}
api.use(eggspress('/verify', {
allowedMethods: ['POST'],
}, (req, res) => {
const { token, answer } = req.body;

if ( !token || !answer ) {
return res.status(400).json({
valid: false,
error: 'Missing token or answer',
});
}

const isValid = this.verifyCaptcha(token, answer);
res.json({ valid: isValid });
},
}).attach(api);
const isValid = this.verifyCaptcha(token, answer);
res.json({ valid: isValid });
}));

// Special endpoint for automated testing
// This should be disabled in production
Expand Down Expand Up @@ -430,8 +426,10 @@ class CaptchaService extends BaseService {
// Invalid token or expired
if ( ! captchaData ) {
console.log('Verification FAILED: No data found for this token');
console.log('TOKENS_TRACKING: Available tokens (first 8 chars):',
Array.from(this.captchaTokens.keys()).map(t => t.substring(0, 8)));
console.log(
'TOKENS_TRACKING: Available tokens (first 8 chars):',
Array.from(this.captchaTokens.keys()).map(t => t.substring(0, 8)),
);
this.log.debug(`Invalid captcha token: ${token}`);
return false;
}
Expand Down Expand Up @@ -542,29 +540,29 @@ class CaptchaService extends BaseService {
};

switch ( this.difficulty ) {
case 'easy':
return {
...baseOptions,
size: 4,
width: 150,
height: 50,
noise: 1,
};
case 'hard':
return {
...baseOptions,
size: 7,
width: 200,
height: 60,
noise: 3,
};
case 'medium':
default:
return {
...baseOptions,
width: 180,
height: 50,
};
case 'easy':
return {
...baseOptions,
size: 4,
width: 150,
height: 50,
noise: 1,
};
case 'hard':
return {
...baseOptions,
size: 7,
width: 200,
height: 60,
noise: 3,
};
case 'medium':
default:
return {
...baseOptions,
width: 180,
height: 50,
};
}
}

Expand Down Expand Up @@ -643,4 +641,4 @@ class CaptchaService extends BaseService {

// Export both as a named export and as a default export for compatibility
module.exports = CaptchaService;
module.exports.CaptchaService = CaptchaService;
module.exports.CaptchaService = CaptchaService;
3 changes: 0 additions & 3 deletions src/backend/src/modules/core/Core2Module.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,6 @@ class Core2Module extends AdvancedBase {
const { PagerService } = require('./PagerService.js');
services.registerService('pager', PagerService);

const { ExpectationService } = require('./ExpectationService.js');
services.registerService('expectations', ExpectationService);

const { ProcessEventService } = require('./ProcessEventService.js');
services.registerService('process-event', ProcessEventService);

Expand Down
Loading
Loading