{"size": 785, "ext": "js", "max_stars_repo_path": "app/controller/notificationApi.js", "max_stars_repo_name": "wc5858/auto-change-style-tool", "max_stars_repo_stars_event_min_datetime": "2021-01-16T04:07:44.000Z", "max_stars_repo_stars_event_max_datetime": "2021-01-16T04:07:44.000Z", "max_issues_repo_path": "app/controller/notificationApi.js", "max_issues_repo_name": "Cypherss/auto-change-style-tool", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "app/controller/notificationApi.js", "max_forks_repo_name": "Cypherss/auto-change-style-tool", "max_forks_repo_forks_event_min_datetime": "2020-02-01T07:53:42.000Z", "max_forks_repo_forks_event_max_datetime": "2021-01-24T12:07:50.000Z"}
{"max_stars_count": 1, "max_issues_count": null, "max_forks_count": 2, "avg_line_length": 22.4285714286, "max_line_length": 62, "alphanum_fraction": 0.5350318471}
const webpush = require('web-push');

module.exports = app => {
  return class NotificationController extends app.Controller {
    async key() {
      const { ctx } = this;
      console.log(ctx.app.vapidKeys.publicKey)
      ctx.body = {
        success: true,
        key: ctx.app.vapidKeys.publicKey
      };
    }
    async subscribe() {
      const { ctx } = this;
      ctx.session.subscription = ctx.request.body;
      ctx.body = {
        success: true
      };
    }
    async cancel() {
      const { ctx } = this;
      delete ctx.session.subscription;
      ctx.body = {
        success: true
      };
    }
    async test() {
      const { ctx } = this;
      ctx.service.notification.notice('test notice');
      ctx.body = {
        success: true
      };
    }
  };
};