VisibleBase
Guides

hook 与商业逻辑

把限额、usage、日志和扣费接入请求生命周期。

VisibleBase 的 hook 让你把商业模式放到统一位置。

调用前

base.all().before(async (ctx) => {
  await quotaService.check({
    user_id: ctx.user.user_id,
    product_id: ctx.product.product_id,
    model: ctx.model.model_id,
  });
});

调用后

base.all().after(async (ctx) => {
  await usageService.record({
    user_id: ctx.user.user_id,
    product_id: ctx.product.product_id,
    model: ctx.model.model_id,
    output: ctx.output,
  });
});

多产品收益

多个产品接入同一个 Base 后,套餐、限额、日志和扣费规则可以集中演进,不需要每个项目各修一次。

On this page