Skip to content

Commit

Permalink
tweak universal func
Browse files Browse the repository at this point in the history
  • Loading branch information
Leask committed Mar 9, 2024
1 parent f54f450 commit b2945eb
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 8 deletions.
4 changes: 4 additions & 0 deletions controllers/apiSubconscious.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ const analyze = async (ctx, next) => {
}
ctx.userAgent._agent.geoIp
= ctx.request.ip ? await geoIp.lookup(ctx.request.ip) : null;
if (globalThis.debug) {
console.log('> ctx:', ctx);
console.log('> ctx.request.body:', ctx.request.body);
}
await next();
};

Expand Down
4 changes: 2 additions & 2 deletions controllers/apiUniversal.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ const sendUniversal = async (ctx, next) => {
};

const callFunc = async (ctx, next) => {
const { params, options } = ctx.request.body;
const stream = options?.stream ? ctx.stream : null;
const params = ctx.request.body;
const stream = params[~~params?.length - 1]?.stream ? ctx.stream : null;
const resp = await call(ctx.params.func, params, {
user: ctx.verification.user, stream
});
Expand Down
13 changes: 7 additions & 6 deletions lib/universal.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -110,12 +110,13 @@ const runtime = {

callFunc: async (name, params, options) => {
assertFunc(name);
params = params || [];
options = options || {};
options?.autoStream !== false && params[params.length - 1]?.stream && (
options.stream = options?.stream || params[params.length - 1]?.stream
);
return callApi(`universal/${name}`, null, { params, options }, options);
[params, options] = [params || [], options || {}];
const last = params.length - 1;
if (options?.autoStream !== false && params[last]?.stream) {
options.stream = options?.stream || params[last].stream;
params[last].stream = true;
};
return callApi(`universal/${name}`, null, params, options);
},
};

Expand Down

0 comments on commit b2945eb

Please sign in to comment.