npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@shzlx/badge

v0.0.3

Published

Badge for HydroOJ

Readme

badge

以 https://github.com/cqzym1985/my-hydro-plugins 为基础,并扩充为可与 shop 外挂整合的徽章系统。

功能

  • 徽章新增、编辑、删除。
  • 使用者徽章管理(启用/重设显示徽章)。
  • 徽章展示页。
  • 与商店整合:
    • 可将徽章发布到商店。
    • 兑换时透过 badge_purchase 自动发放徽章。
    • 若使用者已拥有该徽章,会拒绝购买并回传清楚讯息。

路由

  • badge_show /badge/show
  • badge_manage /badge/manage
  • badge_add /badge/add
  • badge_mybadge /badge/mybadge
  • badge_detail /badge/:id
  • badge_edit /badge/:id/edit
  • badge_shop_publish /badge/shop-publish

Shop 整合设计

1) Runtime Bridge(非静态相对汇入)

本外挂不直接使用 ../shop 类型的静态相对路径汇入,而是透过 runtime bridge:

  • 读取 (global.Hydro as any).shopBridge
  • 若 shop 可用:注册购买模型与管理入口
  • 若 shop 不可用:降级为只保留 badge 本体功能

2) 发布徽章到商店

badge_shop_publish 中,会建立商店商品:

  • name = badge.title
  • objectId = badge:{badgeId}
  • purchaseModelId = badge_purchase
  • data.badgeId = 徽章 ID
  • description = badge.content

shop 端会以 Markdown 渲染 description,因此徽章内容可直接在商城显示。

3) 购买处理器 badge_purchase

购买流程由 BadgePurchaseModel.purchase(...) 处理:

  • 徽章不存在:回传失败讯息。
  • 使用者已拥有该徽章:回传失败讯息(例如:你已拥有徽章「...」)。
  • 验证通过:新增使用者徽章并回传成功。

权限

  • badge_managebadge_addbadge_editbadge_shop_publish 需要管理权限(PRIV.PRIV_SET_PERM)。
  • badge_mybadge 需要 PRIV.PRIV_USER_PROFILE

注意事项

  • 若要使用商店发布与兑换,请先启用 shop 外挂。
  • shop 未启用,本外挂仍可正常使用徽章基本功能。
  • 建议在生产环境固定外挂载入顺序,确保 shop 先于 badge 初始化,以便立即完成 bridge 注册。

⚠️ 徽章发布到商店时的权限限制

本外挂将徽章发布到商店时,会使用 HTML 格式渲染商品描述(内含徽章视觉预览):

  • 只有具有 PRIV.PRIV_SET_PERM (徽章管理权限)的管理员可发布徽章到商店
  • 系统会对徽章的所有栏位进行 HTML 逃脱和安全清理,防止 XSS 攻击
  • 请确保只信任有管理权限的人士操作徽章发布功能