2022-09-11 20:10:01 +02:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2024-01-22 23:43:06 +01:00
|
|
|
require "web-push"
|
2022-09-11 20:10:01 +02:00
|
|
|
|
|
|
|
class AddWebpushApp < ActiveRecord::Migration[6.1]
|
|
|
|
def up
|
2024-01-22 23:43:06 +01:00
|
|
|
vapid_keypair = WebPush.generate_key.to_hash
|
2022-09-11 20:10:01 +02:00
|
|
|
app = Rpush::Webpush::App.new
|
|
|
|
app.name = "webpush"
|
2022-12-26 12:03:18 +01:00
|
|
|
app.certificate = vapid_keypair.merge(subject: APP_CONFIG.fetch("contact_email")).to_json
|
2022-09-11 20:10:01 +02:00
|
|
|
app.connections = 1
|
|
|
|
app.save!
|
|
|
|
end
|
|
|
|
|
|
|
|
def down
|
|
|
|
Rpush::Webpush::App.find_by(name: "webpush").destroy!
|
|
|
|
end
|
|
|
|
end
|