Class: CollavreOpenclaw::PendingCallback
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- CollavreOpenclaw::PendingCallback
- Defined in:
- app/models/collavre_openclaw/pending_callback.rb
Constant Summary collapse
- EXPIRATION_TIME =
Default expiration time (7 days to support scheduled callbacks like cron jobs)
7.days
Class Method Summary collapse
-
.cleanup_expired! ⇒ Object
Cleanup expired callbacks.
-
.create_for_request(user:, creative_id: nil, comment_id: nil, thread_id: nil, context: {}) ⇒ Object
Generate a new pending callback for a request.
- .generate_nonce ⇒ Object
-
.verify_and_consume!(nonce) ⇒ Object
Verify and consume a nonce (one-time use).
Class Method Details
.cleanup_expired! ⇒ Object
Cleanup expired callbacks
43 44 45 |
# File 'app/models/collavre_openclaw/pending_callback.rb', line 43 def self.cleanup_expired! expired.delete_all end |
.create_for_request(user:, creative_id: nil, comment_id: nil, thread_id: nil, context: {}) ⇒ Object
Generate a new pending callback for a request
20 21 22 23 24 25 26 27 28 29 30 |
# File 'app/models/collavre_openclaw/pending_callback.rb', line 20 def self.create_for_request(user:, creative_id: nil, comment_id: nil, thread_id: nil, context: {}) create!( user: user, nonce: generate_nonce, creative_id: creative_id, comment_id: comment_id, thread_id: thread_id, context: context || {}, expires_at: EXPIRATION_TIME.from_now ) end |
.generate_nonce ⇒ Object
49 50 51 |
# File 'app/models/collavre_openclaw/pending_callback.rb', line 49 def self.generate_nonce SecureRandom.urlsafe_base64(32) end |
.verify_and_consume!(nonce) ⇒ Object
Verify and consume a nonce (one-time use)
33 34 35 36 37 38 39 40 |
# File 'app/models/collavre_openclaw/pending_callback.rb', line 33 def self.verify_and_consume!(nonce) callback = valid.find_by(nonce: nonce) return nil unless callback # Consume the nonce (delete it) callback.destroy! callback end |