Skip to content

feat: Lapse integration#1269

Open
ascpixi wants to merge 21 commits intomainfrom
feat/lapse-integration
Open

feat: Lapse integration#1269
ascpixi wants to merge 21 commits intomainfrom
feat/lapse-integration

Conversation

@ascpixi
Copy link
Member

@ascpixi ascpixi commented Feb 4, 2026

This PR adds several Lapse features to Flavortown! ★,°:.☆( ̄▽ ̄)/$:.°★

This includes the following:

  • creating LapseService,
  • showcasing "Tracked with Lapse" badges on projects that include time originating from Lapse,
  • allowing the user to automatically use Lapse video for a devlog attachment,
  • showcasing Lapse badges on devlogs.

@ascpixi
Copy link
Member Author

ascpixi commented Feb 4, 2026

Only thing that is pending are the devlog badges!

@ascpixi ascpixi marked this pull request as ready for review February 9, 2026 18:11
Copy link
Member

@NeonGamerBot-QK NeonGamerBot-QK left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

everything lgtm but can you add some admin ui (like on the admin projects there should be smt which shows lapse attachments, adjustments into the super mega dash) + i can remove this review if u wana do it in another pr.

@cskartikey
Copy link
Member

Can we get some screenshots and screencasts?

@ascpixi
Copy link
Member Author

ascpixi commented Feb 10, 2026

Devlog selector:

{90E9FB40-A893-4318-BB79-CB6DAE1CC881}

Lapse badge:

{9ECE430D-EC5C-4310-883D-54A4AFB21380} {B8FDFBD7-6A39-4E74-9BFF-2362076476FA}

Timelapse modal (please ignore missing thumbnail, ffmpeg was missing when testing so Lapse didn't generate thumbnails - this won't happen on prod):
{FCF3554B-30D4-4D0A-AF5A-41FCAB4CFBF9}

Comment on lines 601 to 602
hackatime_identity = @project.users.first&.hackatime_identity
hackatime_identity&.uid.present?

This comment was marked as outdated.

@ascpixi ascpixi marked this pull request as draft February 10, 2026 16:34
@ascpixi
Copy link
Member Author

ascpixi commented Feb 10, 2026

Please don't merge yet, I noticed some stuff that needs changing

@ascpixi
Copy link
Member Author

ascpixi commented Feb 10, 2026

{33F432A0-8692-4073-9F95-60E3878CE0E3}

Lapse badges on projects are now displayed only for project owners! Devlog badges are displayed always.

@ascpixi
Copy link
Member Author

ascpixi commented Feb 10, 2026

@cskartikey Should be ready to merge! Before doing so, though, please add these environment variables to Coolify: LAPSE_API_BASE=https://lapse.hackclub.com/api/rest and LAPSE_URL_BASE=https://lapse.hackclub.com.

@ascpixi ascpixi marked this pull request as ready for review February 10, 2026 17:11
Comment on lines +243 to +253
response = Faraday.get(playback_url)
unless response.success?
return false
end

content_type = response.headers["content-type"] || "video/mp4"
extension = Rack::Mime::MIME_TYPES.invert[content_type] || ".mp4"
filename = "timelapse-#{timelapse_id}#{extension}"

@devlog.attachments.attach(
io: StringIO.new(response.body),
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: The synchronous Faraday request to download a Lapse video lacks an explicit timeout, potentially blocking a worker thread for up to 10 seconds.
Severity: MEDIUM

Suggested Fix

Add an explicit timeout to the Faraday.get request to ensure it fails faster than the 10-second advisory lock. This aligns with best practices seen elsewhere in the codebase, such as setting req.options.timeout = 10.

Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent.
Verify if this is a real issue. If it is, propose a fix; if not, explain why it's not
valid.

Location: app/controllers/projects/devlogs_controller.rb#L243-L253

Potential issue: The `attach_lapse_timelapse` method initiates a synchronous
`Faraday.get` request to download a video without a configured timeout. This is
inconsistent with other network calls in the codebase that do have explicit timeouts.
While the operation is wrapped in an advisory lock with a 10-second timeout, which
prevents an indefinite hang, a worker thread can still be blocked for up to 10 seconds
waiting for the download. This can degrade application performance and availability
under concurrent requests.

return redirect_to @project, alert: "Could not calculate your coding time. Please try again." unless @preview_time.present?

@devlog = Post::Devlog.new(devlog_params)
Rails.logger.info "DevlogsController#create: media_type=#{params[:media_type].inspect}, lapse_timelapse_id=#{params.dig(:post_devlog, :lapse_timelapse_id).inspect}"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remnant of dev? maybe remove this

extension = Rack::Mime::MIME_TYPES.invert[content_type] || ".mp4"
filename = "timelapse-#{timelapse_id}#{extension}"

@devlog.attachments.attach(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

might be a good idea to queue a bg job?

@preview_time = nil
end

def attach_lapse_timelapse
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this is being called from the controller and involves downloading a video from a remote URL, should we move this into a background job?
Also, if the timelapse is already stored on R2, is there a way for us to create the ActiveStorage blob without downloading and re-uploading it through th rails server?


def format_timelapse_duration(seconds)
return "0s" if seconds.nil? || seconds <= 0

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this type of formatting seems like it's spread across the entire codebase. It might be a good idea to DRY it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants