├── log └── .keep ├── script └── .keep ├── storage └── .keep ├── tmp ├── .keep ├── pids │ └── .keep └── storage │ └── .keep ├── vendor ├── .keep └── javascript │ └── .keep ├── lib ├── tasks │ └── .keep └── soundcloud.rb ├── test ├── helpers │ ├── .keep │ └── test_soundcloud.rb ├── mailers │ └── .keep ├── models │ ├── .keep │ └── ip_address_test.rb ├── system │ └── .keep ├── controllers │ ├── .keep │ ├── home_controller_test.rb │ └── api_controller_test.rb ├── integration │ └── .keep ├── fixtures │ ├── files │ │ └── .keep │ └── ip_addresses.yml ├── application_system_test_case.rb └── test_helper.rb ├── app ├── assets │ ├── images │ │ ├── .keep │ │ ├── cathop_logo.png │ │ └── github.svg │ └── stylesheets │ │ ├── services.css │ │ └── application.css ├── models │ ├── concerns │ │ └── .keep │ ├── ip_address.rb │ └── application_record.rb ├── controllers │ ├── concerns │ │ └── .keep │ ├── home_controller.rb │ └── application_controller.rb ├── views │ ├── layouts │ │ ├── mailer.text.erb │ │ ├── mailer.html.erb │ │ └── application.html.erb │ ├── pwa │ │ ├── manifest.json.erb │ │ └── service-worker.js │ └── home │ │ └── index.html.erb ├── helpers │ ├── home_helper.rb │ ├── url_helper.rb │ └── application_helper.rb ├── mailers │ └── application_mailer.rb ├── javascript │ ├── application.js │ └── controllers │ │ ├── application.js │ │ ├── index.js │ │ ├── base64_controller.js │ │ ├── ip_controller.js │ │ ├── url_controller.js │ │ ├── search_controller.js │ │ ├── soundcloud_controller.js │ │ └── domain_controller.js └── jobs │ └── application_job.rb ├── .ruby-version ├── bin ├── dev ├── rake ├── importmap ├── thrust ├── jobs ├── rails ├── brakeman ├── rubocop ├── docker-entrypoint ├── kamal ├── setup └── bundle ├── public ├── icon.png ├── icon.svg ├── robots.txt ├── 404.html ├── 400.html ├── 406-unsupported-browser.html ├── 500.html └── 422.html ├── .kamal ├── hooks │ ├── docker-setup.sample │ ├── post-proxy-reboot.sample │ ├── pre-proxy-reboot.sample │ ├── post-app-boot.sample │ ├── pre-app-boot.sample │ ├── post-deploy.sample │ ├── pre-connect.sample │ ├── pre-build.sample │ └── pre-deploy.sample └── secrets ├── config ├── environment.rb ├── boot.rb ├── credentials.yml.enc ├── importmap.rb ├── initializers │ ├── assets.rb │ ├── filter_parameter_logging.rb │ ├── inflections.rb │ └── content_security_policy.rb ├── recurring.yml ├── cache.yml ├── queue.yml ├── cable.yml ├── routes.rb ├── application.rb ├── storage.yml ├── database.yml ├── locales │ └── en.yml ├── puma.rb ├── environments │ ├── test.rb │ ├── development.rb │ └── production.rb └── deploy.yml ├── config.ru ├── Rakefile ├── .rubocop.yml ├── .github ├── dependabot.yml └── workflows │ └── ci.yml ├── .gitattributes ├── README.md ├── db ├── seeds.rb ├── cable_schema.rb ├── migrate │ └── 20250613224209_create_ip_addresses.rb ├── cache_schema.rb ├── schema.rb └── queue_schema.rb ├── docker-compose.dev.yml ├── .gitignore ├── .dockerignore ├── docker-compose.yml ├── Dockerfile ├── Gemfile └── Gemfile.lock /log/.keep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /script/.keep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /storage/.keep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /tmp/.keep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /vendor/.keep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /lib/tasks/.keep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /test/helpers/.keep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /test/mailers/.keep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /test/models/.keep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /test/system/.keep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /tmp/pids/.keep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /tmp/storage/.keep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /app/assets/images/.keep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /test/controllers/.keep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /test/integration/.keep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /vendor/javascript/.keep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /.ruby-version: -------------------------------------------------------------------------------- 1 | ruby-3.4.4 2 | -------------------------------------------------------------------------------- /app/models/concerns/.keep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /test/fixtures/files/.keep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /app/controllers/concerns/.keep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /app/views/layouts/mailer.text.erb: -------------------------------------------------------------------------------- 1 | <%= yield %> 2 | -------------------------------------------------------------------------------- /app/helpers/home_helper.rb: -------------------------------------------------------------------------------- 1 | module HomeHelper 2 | end 3 | -------------------------------------------------------------------------------- /app/helpers/url_helper.rb: -------------------------------------------------------------------------------- 1 | module UrlHelper 2 | end 3 | -------------------------------------------------------------------------------- /app/helpers/application_helper.rb: -------------------------------------------------------------------------------- 1 | module ApplicationHelper 2 | end 3 | -------------------------------------------------------------------------------- /app/models/ip_address.rb: -------------------------------------------------------------------------------- 1 | class IpAddress < ApplicationRecord 2 | end 3 | -------------------------------------------------------------------------------- /bin/dev: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | exec "./bin/rails", "server", *ARGV 3 | -------------------------------------------------------------------------------- /public/icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sbeltranc/cathop/HEAD/public/icon.png -------------------------------------------------------------------------------- /.kamal/hooks/docker-setup.sample: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | echo "Docker set up on $KAMAL_HOSTS..." 4 | -------------------------------------------------------------------------------- /.kamal/hooks/post-proxy-reboot.sample: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | echo "Rebooted kamal-proxy on $KAMAL_HOSTS" 4 | -------------------------------------------------------------------------------- /.kamal/hooks/pre-proxy-reboot.sample: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | echo "Rebooting kamal-proxy on $KAMAL_HOSTS..." 4 | -------------------------------------------------------------------------------- /.kamal/hooks/post-app-boot.sample: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | echo "Booted app version $KAMAL_VERSION on $KAMAL_HOSTS..." 4 | -------------------------------------------------------------------------------- /.kamal/hooks/pre-app-boot.sample: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | echo "Booting app version $KAMAL_VERSION on $KAMAL_HOSTS..." 4 | -------------------------------------------------------------------------------- /app/assets/images/cathop_logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sbeltranc/cathop/HEAD/app/assets/images/cathop_logo.png -------------------------------------------------------------------------------- /app/models/application_record.rb: -------------------------------------------------------------------------------- 1 | class ApplicationRecord < ActiveRecord::Base 2 | primary_abstract_class 3 | end 4 | -------------------------------------------------------------------------------- /bin/rake: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | require_relative "../config/boot" 3 | require "rake" 4 | Rake.application.run 5 | -------------------------------------------------------------------------------- /bin/importmap: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | 3 | require_relative "../config/application" 4 | require "importmap/commands" 5 | -------------------------------------------------------------------------------- /bin/thrust: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | require "rubygems" 3 | require "bundler/setup" 4 | 5 | load Gem.bin_path("thruster", "thrust") 6 | -------------------------------------------------------------------------------- /app/controllers/home_controller.rb: -------------------------------------------------------------------------------- 1 | class HomeController < ApplicationController 2 | def index 3 | @query = params[:q] 4 | end 5 | end 6 | -------------------------------------------------------------------------------- /app/mailers/application_mailer.rb: -------------------------------------------------------------------------------- 1 | class ApplicationMailer < ActionMailer::Base 2 | default from: "from@example.com" 3 | layout "mailer" 4 | end 5 | -------------------------------------------------------------------------------- /bin/jobs: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | 3 | require_relative "../config/environment" 4 | require "solid_queue/cli" 5 | 6 | SolidQueue::Cli.start(ARGV) 7 | -------------------------------------------------------------------------------- /public/icon.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /bin/rails: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | APP_PATH = File.expand_path("../config/application", __dir__) 3 | require_relative "../config/boot" 4 | require "rails/commands" 5 | -------------------------------------------------------------------------------- /config/environment.rb: -------------------------------------------------------------------------------- 1 | # Load the Rails application. 2 | require_relative "application" 3 | 4 | # Initialize the Rails application. 5 | Rails.application.initialize! 6 | -------------------------------------------------------------------------------- /bin/brakeman: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | require "rubygems" 3 | require "bundler/setup" 4 | 5 | ARGV.unshift("--ensure-latest") 6 | 7 | load Gem.bin_path("brakeman", "brakeman") 8 | -------------------------------------------------------------------------------- /test/models/ip_address_test.rb: -------------------------------------------------------------------------------- 1 | require "test_helper" 2 | 3 | class IpAddressTest < ActiveSupport::TestCase 4 | # test "the truth" do 5 | # assert true 6 | # end 7 | end 8 | -------------------------------------------------------------------------------- /config.ru: -------------------------------------------------------------------------------- 1 | # This file is used by Rack-based servers to start the application. 2 | 3 | require_relative "config/environment" 4 | 5 | run Rails.application 6 | Rails.application.load_server 7 | -------------------------------------------------------------------------------- /app/javascript/application.js: -------------------------------------------------------------------------------- 1 | // Configure your import map in config/importmap.rb. Read more: https://github.com/rails/importmap-rails 2 | import "@hotwired/turbo-rails" 3 | import "controllers" 4 | -------------------------------------------------------------------------------- /public/robots.txt: -------------------------------------------------------------------------------- 1 | # normally i dont have restrictions 2 | # regarding to the robots.txt file 3 | # but just respect the rate-limits 4 | # and make proper usage of the api 5 | # rather than scrapping itself -------------------------------------------------------------------------------- /test/application_system_test_case.rb: -------------------------------------------------------------------------------- 1 | require "test_helper" 2 | 3 | class ApplicationSystemTestCase < ActionDispatch::SystemTestCase 4 | driven_by :selenium, using: :headless_chrome, screen_size: [ 1400, 1400 ] 5 | end 6 | -------------------------------------------------------------------------------- /config/boot.rb: -------------------------------------------------------------------------------- 1 | ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../Gemfile", __dir__) 2 | 3 | require "bundler/setup" # Set up gems listed in the Gemfile. 4 | require "bootsnap/setup" # Speed up boot time by caching expensive operations. 5 | -------------------------------------------------------------------------------- /test/controllers/home_controller_test.rb: -------------------------------------------------------------------------------- 1 | require "test_helper" 2 | 3 | class HomeControllerTest < ActionDispatch::IntegrationTest 4 | test "should get index" do 5 | get root_url 6 | assert_response :success 7 | end 8 | end 9 | -------------------------------------------------------------------------------- /Rakefile: -------------------------------------------------------------------------------- 1 | # Add your own tasks in files placed in lib/tasks ending in .rake, 2 | # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake. 3 | 4 | require_relative "config/application" 5 | 6 | Rails.application.load_tasks 7 | -------------------------------------------------------------------------------- /config/credentials.yml.enc: -------------------------------------------------------------------------------- 1 | +yQRpGPkdAr6sbKq8qSMhS1S9CwLvMdhpwhwqDSDk4ouZKgY5s+Oi2uVvFgFBCAUTvWg0lxH8CQAQJsz5aW6bQ5LLsbyirU+R+rr6vzNurqhLrRatgQBFzOKYnlro0cp8MlhiflfhzTXGuu4RaoLN71JF0jC81mqkg5PUfhC+YgnYUTdt6G32iPhbzL0cJrO+Y2SRDXLwBs3Dg==--LxnAtvZnUOvbVCnX--34ydIq1fqAhxrmdNUXX9Gw== -------------------------------------------------------------------------------- /.rubocop.yml: -------------------------------------------------------------------------------- 1 | # Omakase Ruby styling for Rails 2 | inherit_gem: { rubocop-rails-omakase: rubocop.yml } 3 | 4 | # Overwrite or add rules to create your own house style 5 | # 6 | # # Use `[a, [b, c]]` not `[ a, [ b, c ] ]` 7 | # Layout/SpaceInsideArrayLiteralBrackets: 8 | # Enabled: false 9 | -------------------------------------------------------------------------------- /app/javascript/controllers/application.js: -------------------------------------------------------------------------------- 1 | import { Application } from "@hotwired/stimulus" 2 | 3 | const application = Application.start() 4 | 5 | // Configure Stimulus development experience 6 | application.debug = false 7 | window.Stimulus = application 8 | 9 | export { application } 10 | -------------------------------------------------------------------------------- /bin/rubocop: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | require "rubygems" 3 | require "bundler/setup" 4 | 5 | # explicit rubocop config increases performance slightly while avoiding config confusion. 6 | ARGV.unshift("--config", File.expand_path("../.rubocop.yml", __dir__)) 7 | 8 | load Gem.bin_path("rubocop", "rubocop") 9 | -------------------------------------------------------------------------------- /.github/dependabot.yml: -------------------------------------------------------------------------------- 1 | version: 2 2 | updates: 3 | - package-ecosystem: bundler 4 | directory: "/" 5 | schedule: 6 | interval: daily 7 | open-pull-requests-limit: 10 8 | - package-ecosystem: github-actions 9 | directory: "/" 10 | schedule: 11 | interval: daily 12 | open-pull-requests-limit: 10 13 | -------------------------------------------------------------------------------- /app/jobs/application_job.rb: -------------------------------------------------------------------------------- 1 | class ApplicationJob < ActiveJob::Base 2 | # Automatically retry jobs that encountered a deadlock 3 | # retry_on ActiveRecord::Deadlocked 4 | 5 | # Most jobs are safe to ignore if the underlying records are no longer available 6 | # discard_on ActiveJob::DeserializationError 7 | end 8 | -------------------------------------------------------------------------------- /app/views/layouts/mailer.html.erb: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 8 | 9 | 10 | 11 | <%= yield %> 12 | 13 | 14 | -------------------------------------------------------------------------------- /config/importmap.rb: -------------------------------------------------------------------------------- 1 | # Pin npm packages by running ./bin/importmap 2 | 3 | pin "application" 4 | pin "@hotwired/turbo-rails", to: "turbo.min.js" 5 | pin "@hotwired/stimulus", to: "stimulus.min.js" 6 | pin "@hotwired/stimulus-loading", to: "stimulus-loading.js" 7 | pin_all_from "app/javascript/controllers", under: "controllers" 8 | -------------------------------------------------------------------------------- /test/fixtures/ip_addresses.yml: -------------------------------------------------------------------------------- 1 | one: 2 | ip_address: "8.8.8.8" 3 | asn: "AS15169" 4 | range: "8.8.8.0/24" 5 | provider: "Google LLC" 6 | organisation: "Google LLC" 7 | city: "Mountain View" 8 | region: "California" 9 | country: "United States" 10 | continent: "North America" 11 | latitude: 37 12 | longitude: -122 -------------------------------------------------------------------------------- /config/initializers/assets.rb: -------------------------------------------------------------------------------- 1 | # Be sure to restart your server when you modify this file. 2 | 3 | # Version of your assets, change this if you want to expire all your assets. 4 | Rails.application.config.assets.version = "1.0" 5 | 6 | # Add additional assets to the asset load path. 7 | # Rails.application.config.assets.paths << Emoji.images_path 8 | -------------------------------------------------------------------------------- /config/recurring.yml: -------------------------------------------------------------------------------- 1 | # production: 2 | # periodic_cleanup: 3 | # class: CleanSoftDeletedRecordsJob 4 | # queue: background 5 | # args: [ 1000, { batch_size: 500 } ] 6 | # schedule: every hour 7 | # periodic_command: 8 | # command: "SoftDeletedRecord.due.delete_all" 9 | # priority: 2 10 | # schedule: at 5am every day 11 | -------------------------------------------------------------------------------- /config/cache.yml: -------------------------------------------------------------------------------- 1 | default: &default 2 | store_options: 3 | # Cap age of oldest cache entry to fulfill retention policies 4 | # max_age: <%= 60.days.to_i %> 5 | max_size: <%= 256.megabytes %> 6 | namespace: <%= Rails.env %> 7 | 8 | development: 9 | <<: *default 10 | 11 | test: 12 | <<: *default 13 | 14 | production: 15 | database: cache 16 | <<: *default 17 | -------------------------------------------------------------------------------- /config/queue.yml: -------------------------------------------------------------------------------- 1 | default: &default 2 | dispatchers: 3 | - polling_interval: 1 4 | batch_size: 500 5 | workers: 6 | - queues: "*" 7 | threads: 3 8 | processes: <%= ENV.fetch("JOB_CONCURRENCY", 1) %> 9 | polling_interval: 0.1 10 | 11 | development: 12 | <<: *default 13 | 14 | test: 15 | <<: *default 16 | 17 | production: 18 | <<: *default 19 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | # See https://git-scm.com/docs/gitattributes for more about git attribute files. 2 | 3 | # Mark the database schema as having been generated. 4 | db/schema.rb linguist-generated 5 | 6 | # Mark any vendored files as having been vendored. 7 | vendor/* linguist-vendored 8 | config/credentials/*.yml.enc diff=rails_credentials 9 | config/credentials.yml.enc diff=rails_credentials 10 | -------------------------------------------------------------------------------- /.kamal/hooks/post-deploy.sample: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # A sample post-deploy hook 4 | # 5 | # These environment variables are available: 6 | # KAMAL_RECORDED_AT 7 | # KAMAL_PERFORMER 8 | # KAMAL_VERSION 9 | # KAMAL_HOSTS 10 | # KAMAL_ROLES (if set) 11 | # KAMAL_DESTINATION (if set) 12 | # KAMAL_RUNTIME 13 | 14 | echo "$KAMAL_PERFORMER deployed $KAMAL_VERSION to $KAMAL_DESTINATION in $KAMAL_RUNTIME seconds" 15 | -------------------------------------------------------------------------------- /app/controllers/application_controller.rb: -------------------------------------------------------------------------------- 1 | require "httparty" 2 | 3 | class ApplicationController < ActionController::Base 4 | # Only allow modern browsers supporting webp images, web push, badges, import maps, CSS nesting, and CSS :has. 5 | allow_browser versions: :modern 6 | 7 | def render_error(message, status = :internal_server_error) 8 | render json: { error: message }, status: status 9 | nil 10 | end 11 | end 12 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 |
2 |
3 | an all-in-one utility website made on ruby on rails without any ads, captchas and a open API 4 |
5 | 6 | --- 7 | 8 | > [!IMPORTANT] 9 | > cathop is being built at the moment! when there is an stable infrastructure i'll work on this same README.md :) howeverrrr, you can use the latest image work on https://cathop.lat/ 10 | -------------------------------------------------------------------------------- /bin/docker-entrypoint: -------------------------------------------------------------------------------- 1 | #!/bin/bash -e 2 | 3 | # Enable jemalloc for reduced memory usage and latency. 4 | if [ -z "${LD_PRELOAD+x}" ]; then 5 | LD_PRELOAD=$(find /usr/lib -name libjemalloc.so.2 -print -quit) 6 | export LD_PRELOAD 7 | fi 8 | 9 | # If running the rails server then create or migrate existing database 10 | if [ "${@: -2:1}" == "./bin/rails" ] && [ "${@: -1:1}" == "server" ]; then 11 | ./bin/rails db:prepare 12 | fi 13 | 14 | exec "${@}" 15 | -------------------------------------------------------------------------------- /test/test_helper.rb: -------------------------------------------------------------------------------- 1 | ENV["RAILS_ENV"] ||= "test" 2 | require_relative "../config/environment" 3 | require "rails/test_help" 4 | 5 | module ActiveSupport 6 | class TestCase 7 | # Run tests in parallel with specified workers 8 | parallelize(workers: :number_of_processors) 9 | 10 | # Setup all fixtures in test/fixtures/*.yml for all tests in alphabetical order. 11 | fixtures :all 12 | 13 | # Add more helper methods to be used by all tests here... 14 | end 15 | end 16 | -------------------------------------------------------------------------------- /app/views/pwa/manifest.json.erb: -------------------------------------------------------------------------------- 1 | { 2 | "name": "Cathop", 3 | "icons": [ 4 | { 5 | "src": "/icon.png", 6 | "type": "image/png", 7 | "sizes": "512x512" 8 | }, 9 | { 10 | "src": "/icon.png", 11 | "type": "image/png", 12 | "sizes": "512x512", 13 | "purpose": "maskable" 14 | } 15 | ], 16 | "start_url": "/", 17 | "display": "standalone", 18 | "scope": "/", 19 | "description": "Cathop.", 20 | "theme_color": "red", 21 | "background_color": "red" 22 | } 23 | -------------------------------------------------------------------------------- /config/initializers/filter_parameter_logging.rb: -------------------------------------------------------------------------------- 1 | # Be sure to restart your server when you modify this file. 2 | 3 | # Configure parameters to be partially matched (e.g. passw matches password) and filtered from the log file. 4 | # Use this to limit dissemination of sensitive information. 5 | # See the ActiveSupport::ParameterFilter documentation for supported notations and behaviors. 6 | Rails.application.config.filter_parameters += [ 7 | :passw, :email, :secret, :token, :_key, :crypt, :salt, :certificate, :otp, :ssn, :cvv, :cvc 8 | ] 9 | -------------------------------------------------------------------------------- /db/seeds.rb: -------------------------------------------------------------------------------- 1 | # This file should ensure the existence of records required to run the application in every environment (production, 2 | # development, test). The code here should be idempotent so that it can be executed at any point in every environment. 3 | # The data can then be loaded with the bin/rails db:seed command (or created alongside the database with db:setup). 4 | # 5 | # Example: 6 | # 7 | # ["Action", "Comedy", "Drama", "Horror"].each do |genre_name| 8 | # MovieGenre.find_or_create_by!(name: genre_name) 9 | # end 10 | -------------------------------------------------------------------------------- /app/javascript/controllers/index.js: -------------------------------------------------------------------------------- 1 | // Import and register all your controllers from the importmap via controllers/**/*_controller 2 | import { application } from "controllers/application" 3 | import { eagerLoadControllersFrom } from "@hotwired/stimulus-loading" 4 | eagerLoadControllersFrom("controllers", application) 5 | 6 | // Lazy load controllers as they appear in the DOM (remember not to preload controllers in import map!) 7 | // import { lazyLoadControllersFrom } from "@hotwired/stimulus-loading" 8 | // lazyLoadControllersFrom("controllers", application) 9 | -------------------------------------------------------------------------------- /db/cable_schema.rb: -------------------------------------------------------------------------------- 1 | ActiveRecord::Schema[7.1].define(version: 1) do 2 | create_table "solid_cable_messages", force: :cascade do |t| 3 | t.binary "channel", limit: 1024, null: false 4 | t.binary "payload", limit: 536870912, null: false 5 | t.datetime "created_at", null: false 6 | t.integer "channel_hash", limit: 8, null: false 7 | t.index ["channel"], name: "index_solid_cable_messages_on_channel" 8 | t.index ["channel_hash"], name: "index_solid_cable_messages_on_channel_hash" 9 | t.index ["created_at"], name: "index_solid_cable_messages_on_created_at" 10 | end 11 | end 12 | -------------------------------------------------------------------------------- /test/helpers/test_soundcloud.rb: -------------------------------------------------------------------------------- 1 | require "test_helper" 2 | 3 | class TestSoundcloud < ActiveSupport::TestCase 4 | test "should resolve short URL" do 5 | resolved_url = Soundcloud.new.resolve_short_url("https://on.soundcloud.com/84VP4S4xeiuv2Kqg27") 6 | assert_equal URI("https://soundcloud.com/menthol100s/carve-out-my-left-eye-idiot").path, URI(resolved_url).path 7 | end 8 | 9 | test "should resolve track" do 10 | track = Soundcloud.new.resolve_track("https://soundcloud.com/menthol100s/carve-out-my-left-eye-idiot") 11 | assert_equal "gothangelz", track["genre"] 12 | end 13 | end 14 | -------------------------------------------------------------------------------- /docker-compose.dev.yml: -------------------------------------------------------------------------------- 1 | services: 2 | app: 3 | container_name: cathop_dev_app 4 | build: 5 | context: . 6 | dockerfile: Dockerfile 7 | env_file: 8 | - .env.development 9 | depends_on: 10 | - db 11 | ports: 12 | - 3000:3000 13 | 14 | db: 15 | container_name: cathop_dev_db 16 | image: "postgres:latest" 17 | volumes: 18 | - cathop_dev_db_data:/var/lib/postgresql/data 19 | environment: 20 | - POSTGRES_HOST_AUTH_METHOD=trust 21 | ports: 22 | - 5432:5432 23 | 24 | volumes: 25 | cathop_dev_db_data: 26 | external: false -------------------------------------------------------------------------------- /config/cable.yml: -------------------------------------------------------------------------------- 1 | # Async adapter only works within the same process, so for manually triggering cable updates from a console, 2 | # and seeing results in the browser, you must do so from the web console (running inside the dev process), 3 | # not a terminal started via bin/rails console! Add "console" to any action or any ERB template view 4 | # to make the web console appear. 5 | development: 6 | adapter: async 7 | 8 | test: 9 | adapter: test 10 | 11 | production: 12 | adapter: solid_cable 13 | connects_to: 14 | database: 15 | writing: cable 16 | polling_interval: 0.1.seconds 17 | message_retention: 1.day 18 | -------------------------------------------------------------------------------- /db/migrate/20250613224209_create_ip_addresses.rb: -------------------------------------------------------------------------------- 1 | class CreateIpAddresses < ActiveRecord::Migration[8.0] 2 | def change 3 | create_table :ip_addresses do |t| 4 | t.string :ip_address, null: false 5 | 6 | t.string :asn, null: false 7 | t.string :range, null: false 8 | 9 | t.string :provider, null: false 10 | t.string :organisation, null: false 11 | 12 | t.string :city, null: false 13 | t.string :region, null: false 14 | t.string :country, null: false 15 | t.string :continent, null: false 16 | 17 | t.integer :latitude, null: false 18 | t.integer :longitude, null: false 19 | 20 | t.timestamps 21 | end 22 | end 23 | end 24 | -------------------------------------------------------------------------------- /db/cache_schema.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | ActiveRecord::Schema[7.2].define(version: 1) do 4 | create_table "solid_cache_entries", force: :cascade do |t| 5 | t.binary "key", limit: 1024, null: false 6 | t.binary "value", limit: 536870912, null: false 7 | t.datetime "created_at", null: false 8 | t.integer "key_hash", limit: 8, null: false 9 | t.integer "byte_size", limit: 4, null: false 10 | t.index ["byte_size"], name: "index_solid_cache_entries_on_byte_size" 11 | t.index ["key_hash", "byte_size"], name: "index_solid_cache_entries_on_key_hash_and_byte_size" 12 | t.index ["key_hash"], name: "index_solid_cache_entries_on_key_hash", unique: true 13 | end 14 | end 15 | -------------------------------------------------------------------------------- /config/initializers/inflections.rb: -------------------------------------------------------------------------------- 1 | # Be sure to restart your server when you modify this file. 2 | 3 | # Add new inflection rules using the following format. Inflections 4 | # are locale specific, and you may define rules for as many different 5 | # locales as you wish. All of these examples are active by default: 6 | # ActiveSupport::Inflector.inflections(:en) do |inflect| 7 | # inflect.plural /^(ox)$/i, "\\1en" 8 | # inflect.singular /^(ox)en/i, "\\1" 9 | # inflect.irregular "person", "people" 10 | # inflect.uncountable %w( fish sheep ) 11 | # end 12 | 13 | # These inflection rules are supported but not enabled by default: 14 | # ActiveSupport::Inflector.inflections(:en) do |inflect| 15 | # inflect.acronym "RESTful" 16 | # end 17 | -------------------------------------------------------------------------------- /config/routes.rb: -------------------------------------------------------------------------------- 1 | Rails.application.routes.draw do 2 | root "home#index" 3 | 4 | # API routes 5 | namespace :api do 6 | # lookup namespace 7 | get "lookup/url" => "api#request_url", as: :request_url 8 | get "lookup/ip/:ip" => "api#lookup_ip", as: :lookup_ip, constraints: { ip: /[^\/]+/ } 9 | get "lookup/domain/:domain" => "api#lookup_domain", as: :lookup_domain, constraints: { domain: /[^\/]+/ } 10 | 11 | # soundcloud namespace 12 | get "soundcloud/track" => "api#soundcloud_track_info", as: :soundcloud_track_info 13 | get "soundcloud/download" => "api#soundcloud_download", as: :soundcloud_download 14 | end 15 | 16 | # rails health check 17 | get "up" => "rails/health#show", as: :rails_health_check 18 | end 19 | -------------------------------------------------------------------------------- /bin/kamal: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | # frozen_string_literal: true 3 | 4 | # 5 | # This file was generated by Bundler. 6 | # 7 | # The application 'kamal' is installed as part of a gem, and 8 | # this file is here to facilitate running it. 9 | # 10 | 11 | ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../Gemfile", __dir__) 12 | 13 | bundle_binstub = File.expand_path("bundle", __dir__) 14 | 15 | if File.file?(bundle_binstub) 16 | if File.read(bundle_binstub, 300).include?("This file was generated by Bundler") 17 | load(bundle_binstub) 18 | else 19 | abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run. 20 | Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.") 21 | end 22 | end 23 | 24 | require "rubygems" 25 | require "bundler/setup" 26 | 27 | load Gem.bin_path("kamal", "kamal") 28 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # See https://help.github.com/articles/ignoring-files for more about ignoring files. 2 | # 3 | # Temporary files generated by your text editor or operating system 4 | # belong in git's global ignore instead: 5 | # `$XDG_CONFIG_HOME/git/ignore` or `~/.config/git/ignore` 6 | 7 | # Ignore bundler config. 8 | /.bundle 9 | 10 | # Ignore all environment files. 11 | /.env* 12 | 13 | # Ignore all logfiles and tempfiles. 14 | /log/* 15 | /tmp/* 16 | !/log/.keep 17 | !/tmp/.keep 18 | 19 | # Ignore pidfiles, but keep the directory. 20 | /tmp/pids/* 21 | !/tmp/pids/ 22 | !/tmp/pids/.keep 23 | 24 | # Ignore storage (uploaded files in development and any SQLite databases). 25 | /storage/* 26 | !/storage/.keep 27 | /tmp/storage/* 28 | !/tmp/storage/ 29 | !/tmp/storage/.keep 30 | 31 | /public/assets 32 | 33 | # Ignore master key for decrypting credentials and more. 34 | /config/master.key 35 | /config/credentials.yml.enc -------------------------------------------------------------------------------- /app/views/pwa/service-worker.js: -------------------------------------------------------------------------------- 1 | // Add a service worker for processing Web Push notifications: 2 | // 3 | // self.addEventListener("push", async (event) => { 4 | // const { title, options } = await event.data.json() 5 | // event.waitUntil(self.registration.showNotification(title, options)) 6 | // }) 7 | // 8 | // self.addEventListener("notificationclick", function(event) { 9 | // event.notification.close() 10 | // event.waitUntil( 11 | // clients.matchAll({ type: "window" }).then((clientList) => { 12 | // for (let i = 0; i < clientList.length; i++) { 13 | // let client = clientList[i] 14 | // let clientPath = (new URL(client.url)).pathname 15 | // 16 | // if (clientPath == event.notification.data.path && "focus" in client) { 17 | // return client.focus() 18 | // } 19 | // } 20 | // 21 | // if (clients.openWindow) { 22 | // return clients.openWindow(event.notification.data.path) 23 | // } 24 | // }) 25 | // ) 26 | // }) 27 | -------------------------------------------------------------------------------- /.kamal/secrets: -------------------------------------------------------------------------------- 1 | # Secrets defined here are available for reference under registry/password, env/secret, builder/secrets, 2 | # and accessories/*/env/secret in config/deploy.yml. All secrets should be pulled from either 3 | # password manager, ENV, or a file. DO NOT ENTER RAW CREDENTIALS HERE! This file needs to be safe for git. 4 | 5 | # Example of extracting secrets from 1password (or another compatible pw manager) 6 | # SECRETS=$(kamal secrets fetch --adapter 1password --account your-account --from Vault/Item KAMAL_REGISTRY_PASSWORD RAILS_MASTER_KEY) 7 | # KAMAL_REGISTRY_PASSWORD=$(kamal secrets extract KAMAL_REGISTRY_PASSWORD ${SECRETS}) 8 | # RAILS_MASTER_KEY=$(kamal secrets extract RAILS_MASTER_KEY ${SECRETS}) 9 | 10 | # Use a GITHUB_TOKEN if private repositories are needed for the image 11 | # GITHUB_TOKEN=$(gh config get -h github.com oauth_token) 12 | 13 | # Grab the registry password from ENV 14 | KAMAL_REGISTRY_PASSWORD=$KAMAL_REGISTRY_PASSWORD 15 | 16 | # Improve security by using a password manager. Never check config/master.key into git! 17 | RAILS_MASTER_KEY=$(cat config/master.key) 18 | -------------------------------------------------------------------------------- /.dockerignore: -------------------------------------------------------------------------------- 1 | # See https://docs.docker.com/engine/reference/builder/#dockerignore-file for more about ignoring files. 2 | 3 | # Ignore git directory. 4 | /.git/ 5 | /.gitignore 6 | 7 | # Ignore bundler config. 8 | /.bundle 9 | 10 | # Ignore all environment files. 11 | /.env* 12 | 13 | # Ignore all default key files. 14 | /config/master.key 15 | /config/credentials/*.key 16 | 17 | # Ignore all logfiles and tempfiles. 18 | /log/* 19 | /tmp/* 20 | !/log/.keep 21 | !/tmp/.keep 22 | 23 | # Ignore pidfiles, but keep the directory. 24 | /tmp/pids/* 25 | !/tmp/pids/.keep 26 | 27 | # Ignore storage (uploaded files in development and any SQLite databases). 28 | /storage/* 29 | !/storage/.keep 30 | /tmp/storage/* 31 | !/tmp/storage/.keep 32 | 33 | # Ignore assets. 34 | /node_modules/ 35 | /app/assets/builds/* 36 | !/app/assets/builds/.keep 37 | /public/assets 38 | 39 | # Ignore CI service files. 40 | /.github 41 | 42 | # Ignore Kamal files. 43 | /config/deploy*.yml 44 | /.kamal 45 | 46 | # Ignore development files 47 | /.devcontainer 48 | 49 | # Ignore Docker-related files 50 | /.dockerignore 51 | /Dockerfile* 52 | -------------------------------------------------------------------------------- /config/application.rb: -------------------------------------------------------------------------------- 1 | require_relative "boot" 2 | 3 | require "rails/all" 4 | 5 | # Require the gems listed in Gemfile, including any gems 6 | # you've limited to :test, :development, or :production. 7 | Bundler.require(*Rails.groups) 8 | 9 | module Cathop 10 | class Application < Rails::Application 11 | # Initialize configuration defaults for originally generated Rails version. 12 | config.load_defaults 8.0 13 | 14 | # Please, add to the `ignore` list any other `lib` subdirectories that do 15 | # not contain `.rb` files, or that should not be reloaded or eager loaded. 16 | # Common ones are `templates`, `generators`, or `middleware`, for example. 17 | config.autoload_lib(ignore: %w[assets tasks]) 18 | 19 | # Configuration for the application, engines, and railties goes here. 20 | # 21 | # These settings can be overridden in specific environments using the files 22 | # in config/environments, which are processed later. 23 | # 24 | # config.time_zone = "Central Time (US & Canada)" 25 | # config.eager_load_paths << Rails.root.join("extras") 26 | end 27 | end 28 | -------------------------------------------------------------------------------- /bin/setup: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | require "fileutils" 3 | 4 | APP_ROOT = File.expand_path("..", __dir__) 5 | 6 | def system!(*args) 7 | system(*args, exception: true) 8 | end 9 | 10 | FileUtils.chdir APP_ROOT do 11 | # This script is a way to set up or update your development environment automatically. 12 | # This script is idempotent, so that you can run it at any time and get an expectable outcome. 13 | # Add necessary setup steps to this file. 14 | 15 | puts "== Installing dependencies ==" 16 | system("bundle check") || system!("bundle install") 17 | 18 | # puts "\n== Copying sample files ==" 19 | # unless File.exist?("config/database.yml") 20 | # FileUtils.cp "config/database.yml.sample", "config/database.yml" 21 | # end 22 | 23 | puts "\n== Preparing database ==" 24 | system! "bin/rails db:prepare" 25 | 26 | puts "\n== Removing old logs and tempfiles ==" 27 | system! "bin/rails log:clear tmp:clear" 28 | 29 | unless ARGV.include?("--skip-server") 30 | puts "\n== Starting development server ==" 31 | STDOUT.flush # flush the output before exec(2) so that it displays 32 | exec "bin/dev" 33 | end 34 | end 35 | -------------------------------------------------------------------------------- /config/initializers/content_security_policy.rb: -------------------------------------------------------------------------------- 1 | # Be sure to restart your server when you modify this file. 2 | 3 | # Define an application-wide content security policy. 4 | # See the Securing Rails Applications Guide for more information: 5 | # https://guides.rubyonrails.org/security.html#content-security-policy-header 6 | 7 | # Rails.application.configure do 8 | # config.content_security_policy do |policy| 9 | # policy.default_src :self, :https 10 | # policy.font_src :self, :https, :data 11 | # policy.img_src :self, :https, :data 12 | # policy.object_src :none 13 | # policy.script_src :self, :https 14 | # policy.style_src :self, :https 15 | # # Specify URI for violation reports 16 | # # policy.report_uri "/csp-violation-report-endpoint" 17 | # end 18 | # 19 | # # Generate session nonces for permitted importmap, inline scripts, and inline styles. 20 | # config.content_security_policy_nonce_generator = ->(request) { request.session.id.to_s } 21 | # config.content_security_policy_nonce_directives = %w(script-src style-src) 22 | # 23 | # # Report violations without enforcing the policy. 24 | # # config.content_security_policy_report_only = true 25 | # end 26 | -------------------------------------------------------------------------------- /docker-compose.yml: -------------------------------------------------------------------------------- 1 | services: 2 | app: 3 | container_name: cathop_app 4 | restart: unless-stopped 5 | image: 'ghcr.io/sbeltranc/cathop:latest' 6 | environment: 7 | - RAILS_MASTER_KEY=${RAILS_MASTER_KEY} 8 | env_file: 9 | - .env 10 | depends_on: 11 | - db 12 | networks: 13 | - cathop_network 14 | 15 | db: 16 | container_name: cathop_db 17 | restart: unless-stopped 18 | image: "postgres:latest" 19 | volumes: 20 | - cathop_db_data:/var/lib/postgresql/data 21 | environment: 22 | - POSTGRES_HOST_AUTH_METHOD=trust 23 | healthcheck: 24 | test: ["CMD-SHELL", "pg_isready -U postgres"] 25 | interval: 30s 26 | timeout: 60s 27 | retries: 5 28 | start_period: 60s 29 | networks: 30 | - cathop_network 31 | 32 | tunnel: 33 | container_name: cathop_tunnel 34 | image: "cloudflare/cloudflared:latest" 35 | restart: unless-stopped 36 | command: tunnel run 37 | environment: 38 | - TUNNEL_TOKEN=${CLOUDFLARE_ZERO_TRUST_TOKEN} 39 | networks: 40 | - cathop_network 41 | 42 | volumes: 43 | cathop_db_data: 44 | external: false 45 | 46 | networks: 47 | cathop_network: null -------------------------------------------------------------------------------- /.kamal/hooks/pre-connect.sample: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | 3 | # A sample pre-connect check 4 | # 5 | # Warms DNS before connecting to hosts in parallel 6 | # 7 | # These environment variables are available: 8 | # KAMAL_RECORDED_AT 9 | # KAMAL_PERFORMER 10 | # KAMAL_VERSION 11 | # KAMAL_HOSTS 12 | # KAMAL_ROLES (if set) 13 | # KAMAL_DESTINATION (if set) 14 | # KAMAL_RUNTIME 15 | 16 | hosts = ENV["KAMAL_HOSTS"].split(",") 17 | results = nil 18 | max = 3 19 | 20 | elapsed = Benchmark.realtime do 21 | results = hosts.map do |host| 22 | Thread.new do 23 | tries = 1 24 | 25 | begin 26 | Socket.getaddrinfo(host, 0, Socket::AF_UNSPEC, Socket::SOCK_STREAM, nil, Socket::AI_CANONNAME) 27 | rescue SocketError 28 | if tries < max 29 | puts "Retrying DNS warmup: #{host}" 30 | tries += 1 31 | sleep rand 32 | retry 33 | else 34 | puts "DNS warmup failed: #{host}" 35 | host 36 | end 37 | end 38 | 39 | tries 40 | end 41 | end.map(&:value) 42 | end 43 | 44 | retries = results.sum - hosts.size 45 | nopes = results.count { |r| r == max } 46 | 47 | puts "Prewarmed %d DNS lookups in %.2f sec: %d retries, %d failures" % [ hosts.size, elapsed, retries, nopes ] 48 | -------------------------------------------------------------------------------- /config/storage.yml: -------------------------------------------------------------------------------- 1 | test: 2 | service: Disk 3 | root: <%= Rails.root.join("tmp/storage") %> 4 | 5 | local: 6 | service: Disk 7 | root: <%= Rails.root.join("storage") %> 8 | 9 | # Use bin/rails credentials:edit to set the AWS secrets (as aws:access_key_id|secret_access_key) 10 | # amazon: 11 | # service: S3 12 | # access_key_id: <%= Rails.application.credentials.dig(:aws, :access_key_id) %> 13 | # secret_access_key: <%= Rails.application.credentials.dig(:aws, :secret_access_key) %> 14 | # region: us-east-1 15 | # bucket: your_own_bucket-<%= Rails.env %> 16 | 17 | # Remember not to checkin your GCS keyfile to a repository 18 | # google: 19 | # service: GCS 20 | # project: your_project 21 | # credentials: <%= Rails.root.join("path/to/gcs.keyfile") %> 22 | # bucket: your_own_bucket-<%= Rails.env %> 23 | 24 | # Use bin/rails credentials:edit to set the Azure Storage secret (as azure_storage:storage_access_key) 25 | # microsoft: 26 | # service: AzureStorage 27 | # storage_account_name: your_account_name 28 | # storage_access_key: <%= Rails.application.credentials.dig(:azure_storage, :storage_access_key) %> 29 | # container: your_container_name-<%= Rails.env %> 30 | 31 | # mirror: 32 | # service: Mirror 33 | # primary: local 34 | # mirrors: [ amazon, google, microsoft ] 35 | -------------------------------------------------------------------------------- /config/database.yml: -------------------------------------------------------------------------------- 1 | # SQLite. Versions 3.8.0 and up are supported. 2 | # gem install sqlite3 3 | # 4 | # Ensure the SQLite 3 gem is defined in your Gemfile 5 | # gem "sqlite3" 6 | # 7 | default: &default 8 | adapter: sqlite3 9 | pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %> 10 | timeout: 5000 11 | 12 | development: 13 | <<: *default 14 | database: storage/development.sqlite3 15 | 16 | # Warning: The database defined as "test" will be erased and 17 | # re-generated from your development database when you run "rake". 18 | # Do not set this db to the same as development or production. 19 | test: 20 | <<: *default 21 | database: storage/test.sqlite3 22 | 23 | 24 | # Store production database in the storage/ directory, which by default 25 | # is mounted as a persistent Docker volume in config/deploy.yml. 26 | production: 27 | primary: 28 | <<: *default 29 | database: storage/production.sqlite3 30 | cache: 31 | <<: *default 32 | database: storage/production_cache.sqlite3 33 | migrations_paths: db/cache_migrate 34 | queue: 35 | <<: *default 36 | database: storage/production_queue.sqlite3 37 | migrations_paths: db/queue_migrate 38 | cable: 39 | <<: *default 40 | database: storage/production_cable.sqlite3 41 | migrations_paths: db/cable_migrate 42 | -------------------------------------------------------------------------------- /.kamal/hooks/pre-build.sample: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # A sample pre-build hook 4 | # 5 | # Checks: 6 | # 1. We have a clean checkout 7 | # 2. A remote is configured 8 | # 3. The branch has been pushed to the remote 9 | # 4. The version we are deploying matches the remote 10 | # 11 | # These environment variables are available: 12 | # KAMAL_RECORDED_AT 13 | # KAMAL_PERFORMER 14 | # KAMAL_VERSION 15 | # KAMAL_HOSTS 16 | # KAMAL_ROLES (if set) 17 | # KAMAL_DESTINATION (if set) 18 | 19 | if [ -n "$(git status --porcelain)" ]; then 20 | echo "Git checkout is not clean, aborting..." >&2 21 | git status --porcelain >&2 22 | exit 1 23 | fi 24 | 25 | first_remote=$(git remote) 26 | 27 | if [ -z "$first_remote" ]; then 28 | echo "No git remote set, aborting..." >&2 29 | exit 1 30 | fi 31 | 32 | current_branch=$(git branch --show-current) 33 | 34 | if [ -z "$current_branch" ]; then 35 | echo "Not on a git branch, aborting..." >&2 36 | exit 1 37 | fi 38 | 39 | remote_head=$(git ls-remote $first_remote --tags $current_branch | cut -f1) 40 | 41 | if [ -z "$remote_head" ]; then 42 | echo "Branch not pushed to remote, aborting..." >&2 43 | exit 1 44 | fi 45 | 46 | if [ "$KAMAL_VERSION" != "$remote_head" ]; then 47 | echo "Version ($KAMAL_VERSION) does not match remote HEAD ($remote_head), aborting..." >&2 48 | exit 1 49 | fi 50 | 51 | exit 0 52 | -------------------------------------------------------------------------------- /db/schema.rb: -------------------------------------------------------------------------------- 1 | # This file is auto-generated from the current state of the database. Instead 2 | # of editing this file, please use the migrations feature of Active Record to 3 | # incrementally modify your database, and then regenerate this schema definition. 4 | # 5 | # This file is the source Rails uses to define your schema when running `bin/rails 6 | # db:schema:load`. When creating a new database, `bin/rails db:schema:load` tends to 7 | # be faster and is potentially less error prone than running all of your 8 | # migrations from scratch. Old migrations may fail to apply correctly if those 9 | # migrations use external dependencies or application code. 10 | # 11 | # It's strongly recommended that you check this file into your version control system. 12 | 13 | ActiveRecord::Schema[8.0].define(version: 2025_06_13_224209) do 14 | create_table "ip_addresses", force: :cascade do |t| 15 | t.string "ip_address", null: false 16 | t.string "asn", null: false 17 | t.string "range", null: false 18 | t.string "provider", null: false 19 | t.string "organisation", null: false 20 | t.string "city", null: false 21 | t.string "region", null: false 22 | t.string "country", null: false 23 | t.string "continent", null: false 24 | t.integer "latitude", null: false 25 | t.integer "longitude", null: false 26 | t.datetime "created_at", null: false 27 | t.datetime "updated_at", null: false 28 | end 29 | end 30 | -------------------------------------------------------------------------------- /app/views/layouts/application.html.erb: -------------------------------------------------------------------------------- 1 | 12 | 13 | 14 | 15 | 16 | <%= content_for(:title) || "cathop" %> 17 | 18 | 19 | 20 | 21 | 22 | <%= csrf_meta_tags %> 23 | <%= csp_meta_tag %> 24 | 25 | <%= yield :head %> 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | <%= stylesheet_link_tag "application", "services", "data-turbo-track": "reload" %> 36 | <%= javascript_importmap_tags %> 37 | 38 | 39 | 40 | <%= yield %> 41 | 42 | 43 | -------------------------------------------------------------------------------- /config/locales/en.yml: -------------------------------------------------------------------------------- 1 | # Files in the config/locales directory are used for internationalization and 2 | # are automatically loaded by Rails. If you want to use locales other than 3 | # English, add the necessary files in this directory. 4 | # 5 | # To use the locales, use `I18n.t`: 6 | # 7 | # I18n.t "hello" 8 | # 9 | # In views, this is aliased to just `t`: 10 | # 11 | # <%= t("hello") %> 12 | # 13 | # To use a different locale, set it with `I18n.locale`: 14 | # 15 | # I18n.locale = :es 16 | # 17 | # This would use the information in config/locales/es.yml. 18 | # 19 | # To learn more about the API, please read the Rails Internationalization guide 20 | # at https://guides.rubyonrails.org/i18n.html. 21 | # 22 | # Be aware that YAML interprets the following case-insensitive strings as 23 | # booleans: `true`, `false`, `on`, `off`, `yes`, `no`. Therefore, these strings 24 | # must be quoted to be interpreted as strings. For example: 25 | # 26 | # en: 27 | # "yes": yup 28 | # enabled: "ON" 29 | 30 | en: 31 | search_placeholder: "input your query..." 32 | service_messages: 33 | youtube: "this is a youtube link, you can look up information about the video or download it" 34 | ip: "this is an ip address, you can look up information about it" 35 | roblox: "this is a roblox profile, you can look up information about the user" 36 | spotify: "this is a spotify link, you can look up information about the song or album" 37 | soundcloud: "this is a soundcloud link, you can look up information about the song or album" 38 | domain: "this is a domain, you can look up icann information about it" 39 | base64: "this is a base64 encoded string, you can decode it" 40 | unknown: "couldn't figure out what is this :(" 41 | generic_url: "this is an url, we can request it and see what it returns" 42 | -------------------------------------------------------------------------------- /config/puma.rb: -------------------------------------------------------------------------------- 1 | # This configuration file will be evaluated by Puma. The top-level methods that 2 | # are invoked here are part of Puma's configuration DSL. For more information 3 | # about methods provided by the DSL, see https://puma.io/puma/Puma/DSL.html. 4 | # 5 | # Puma starts a configurable number of processes (workers) and each process 6 | # serves each request in a thread from an internal thread pool. 7 | # 8 | # You can control the number of workers using ENV["WEB_CONCURRENCY"]. You 9 | # should only set this value when you want to run 2 or more workers. The 10 | # default is already 1. 11 | # 12 | # The ideal number of threads per worker depends both on how much time the 13 | # application spends waiting for IO operations and on how much you wish to 14 | # prioritize throughput over latency. 15 | # 16 | # As a rule of thumb, increasing the number of threads will increase how much 17 | # traffic a given process can handle (throughput), but due to CRuby's 18 | # Global VM Lock (GVL) it has diminishing returns and will degrade the 19 | # response time (latency) of the application. 20 | # 21 | # The default is set to 3 threads as it's deemed a decent compromise between 22 | # throughput and latency for the average Rails application. 23 | # 24 | # Any libraries that use a connection pool or another resource pool should 25 | # be configured to provide at least as many connections as the number of 26 | # threads. This includes Active Record's `pool` parameter in `database.yml`. 27 | threads_count = ENV.fetch("RAILS_MAX_THREADS", 3) 28 | threads threads_count, threads_count 29 | 30 | # Specifies the `port` that Puma will listen on to receive requests; default is 3000. 31 | port ENV.fetch("PORT", 3000) 32 | 33 | # Allow puma to be restarted by `bin/rails restart` command. 34 | plugin :tmp_restart 35 | 36 | # Run the Solid Queue supervisor inside of Puma for single-server deployments 37 | plugin :solid_queue if ENV["SOLID_QUEUE_IN_PUMA"] 38 | 39 | # Specify the PID file. Defaults to tmp/pids/server.pid in development. 40 | # In other environments, only set the PID file if requested. 41 | pidfile ENV["PIDFILE"] if ENV["PIDFILE"] 42 | -------------------------------------------------------------------------------- /config/environments/test.rb: -------------------------------------------------------------------------------- 1 | # The test environment is used exclusively to run your application's 2 | # test suite. You never need to work with it otherwise. Remember that 3 | # your test database is "scratch space" for the test suite and is wiped 4 | # and recreated between test runs. Don't rely on the data there! 5 | 6 | Rails.application.configure do 7 | # Settings specified here will take precedence over those in config/application.rb. 8 | 9 | # While tests run files are not watched, reloading is not necessary. 10 | config.enable_reloading = false 11 | 12 | # Eager loading loads your entire application. When running a single test locally, 13 | # this is usually not necessary, and can slow down your test suite. However, it's 14 | # recommended that you enable it in continuous integration systems to ensure eager 15 | # loading is working properly before deploying your code. 16 | config.eager_load = ENV["CI"].present? 17 | 18 | # Configure public file server for tests with cache-control for performance. 19 | config.public_file_server.headers = { "cache-control" => "public, max-age=3600" } 20 | 21 | # Show full error reports. 22 | config.consider_all_requests_local = true 23 | config.cache_store = :null_store 24 | 25 | # Render exception templates for rescuable exceptions and raise for other exceptions. 26 | config.action_dispatch.show_exceptions = :rescuable 27 | 28 | # Disable request forgery protection in test environment. 29 | config.action_controller.allow_forgery_protection = false 30 | 31 | # Store uploaded files on the local file system in a temporary directory. 32 | config.active_storage.service = :test 33 | 34 | # Tell Action Mailer not to deliver emails to the real world. 35 | # The :test delivery method accumulates sent emails in the 36 | # ActionMailer::Base.deliveries array. 37 | config.action_mailer.delivery_method = :test 38 | 39 | # Set host to be used by links generated in mailer templates. 40 | config.action_mailer.default_url_options = { host: "example.com" } 41 | 42 | # Print deprecation notices to the stderr. 43 | config.active_support.deprecation = :stderr 44 | 45 | # Raises error for missing translations. 46 | # config.i18n.raise_on_missing_translations = true 47 | 48 | # Annotate rendered view with file names. 49 | # config.action_view.annotate_rendered_view_with_filenames = true 50 | 51 | # Raise error when a before_action's only/except options reference missing actions. 52 | config.action_controller.raise_on_missing_callback_actions = true 53 | end 54 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | # syntax=docker/dockerfile:1 2 | # check=error=true 3 | 4 | # This Dockerfile is designed for production, not development. Use with Kamal or build'n'run by hand: 5 | # docker build -t cathop . 6 | # docker run -d -p 80:80 -e RAILS_MASTER_KEY= --name cathop cathop 7 | 8 | # For a containerized dev environment, see Dev Containers: https://guides.rubyonrails.org/getting_started_with_devcontainer.html 9 | 10 | # Make sure RUBY_VERSION matches the Ruby version in .ruby-version 11 | ARG RUBY_VERSION=3.4.4 12 | FROM docker.io/library/ruby:$RUBY_VERSION-slim AS base 13 | 14 | # Rails app lives here 15 | WORKDIR /rails 16 | 17 | # Install base packages 18 | RUN apt-get update -qq && \ 19 | apt-get install --no-install-recommends -y curl libjemalloc2 libvips sqlite3 20 | 21 | # Set production environment 22 | ENV RAILS_ENV="production" \ 23 | BUNDLE_DEPLOYMENT="1" \ 24 | BUNDLE_PATH="/usr/local/bundle" \ 25 | BUNDLE_WITHOUT="development" 26 | 27 | # Throw-away build stage to reduce size of final image 28 | FROM base AS build 29 | 30 | # Install packages needed to build gems 31 | RUN apt-get update -qq && \ 32 | apt-get install --no-install-recommends -y build-essential git libyaml-dev pkg-config && \ 33 | rm -rf /var/lib/apt/lists /var/cache/apt/archives 34 | 35 | # Install application gems 36 | COPY Gemfile Gemfile.lock ./ 37 | RUN bundle install && \ 38 | rm -rf ~/.bundle/ "${BUNDLE_PATH}"/ruby/*/cache "${BUNDLE_PATH}"/ruby/*/bundler/gems/*/.git && \ 39 | bundle exec bootsnap precompile --gemfile 40 | 41 | # Copy application code 42 | COPY . . 43 | 44 | # Precompile bootsnap code for faster boot times 45 | RUN bundle exec bootsnap precompile app/ lib/ 46 | 47 | # Precompiling assets for production without requiring secret RAILS_MASTER_KEY 48 | RUN SECRET_KEY_BASE_DUMMY=1 ./bin/rails assets:precompile 49 | 50 | # Final stage for app image 51 | FROM base 52 | 53 | # Copy built artifacts: gems, application 54 | COPY --from=build "${BUNDLE_PATH}" "${BUNDLE_PATH}" 55 | COPY --from=build /rails /rails 56 | 57 | # Run and own only the runtime files as a non-root user for security 58 | RUN groupadd --system --gid 1000 rails && \ 59 | useradd rails --uid 1000 --gid 1000 --create-home --shell /bin/bash && \ 60 | chown -R rails:rails db log storage tmp 61 | USER 1000:1000 62 | 63 | # Entrypoint prepares the database. 64 | ENTRYPOINT ["/rails/bin/docker-entrypoint"] 65 | 66 | # Start server via Thruster by default, this can be overwritten at runtime 67 | EXPOSE 80 68 | CMD ["./bin/thrust", "./bin/rails", "server"] 69 | -------------------------------------------------------------------------------- /Gemfile: -------------------------------------------------------------------------------- 1 | source "https://rubygems.org" 2 | 3 | # Required gem for YouTube interacting 4 | # Bundle edge Rails instead: gem "rails", github: "rails/rails", branch: "main" 5 | gem "rails", "~> 8.0.2" 6 | # The modern asset pipeline for Rails [https://github.com/rails/propshaft] 7 | gem "propshaft" 8 | # Use sqlite3 as the database for Active Record 9 | gem "sqlite3", ">= 2.1" 10 | # Use the Puma web server [https://github.com/puma/puma] 11 | gem "puma", ">= 5.0" 12 | # Use JavaScript with ESM import maps [https://github.com/rails/importmap-rails] 13 | gem "importmap-rails" 14 | # Hotwire's SPA-like page accelerator [https://turbo.hotwired.dev] 15 | gem "turbo-rails" 16 | # Hotwire's modest JavaScript framework [https://stimulus.hotwired.dev] 17 | gem "stimulus-rails" 18 | # Build JSON APIs with ease [https://github.com/rails/jbuilder] 19 | gem "jbuilder" 20 | 21 | # Use Active Model has_secure_password [https://guides.rubyonrails.org/active_model_basics.html#securepassword] 22 | # gem "bcrypt", "~> 3.1.7" 23 | 24 | # Windows does not include zoneinfo files, so bundle the tzinfo-data gem 25 | gem "tzinfo-data", platforms: %i[ windows jruby ] 26 | 27 | # Use the database-backed adapters for Rails.cache, Active Job, and Action Cable 28 | gem "solid_cache" 29 | gem "solid_queue" 30 | gem "solid_cable" 31 | 32 | # Reduces boot times through caching; required in config/boot.rb 33 | gem "bootsnap", require: false 34 | 35 | # Deploy this application anywhere as a Docker container [https://kamal-deploy.org] 36 | gem "kamal", require: false 37 | 38 | # Add HTTP asset caching/compression and X-Sendfile acceleration to Puma [https://github.com/basecamp/thruster/] 39 | gem "thruster", require: false 40 | 41 | # Use Active Storage variants [https://guides.rubyonrails.org/active_storage_overview.html#transforming-images] 42 | # gem "image_processing", "~> 1.2" 43 | 44 | gem "httparty", "~> 0.23.1" 45 | gem "aws-sdk-s3" 46 | 47 | group :development, :test do 48 | # See https://guides.rubyonrails.org/debugging_rails_applications.html#debugging-with-the-debug-gem 49 | gem "debug", platforms: %i[ mri windows ], require: "debug/prelude" 50 | 51 | # Static analysis for security vulnerabilities [https://brakemanscanner.org/] 52 | gem "brakeman", require: false 53 | 54 | # Omakase Ruby styling [https://github.com/rails/rubocop-rails-omakase/] 55 | gem "rubocop-rails-omakase", require: false 56 | end 57 | 58 | group :development do 59 | # Use console on exceptions pages [https://github.com/rails/web-console] 60 | gem "web-console" 61 | end 62 | 63 | group :test do 64 | # Use system testing [https://guides.rubyonrails.org/testing.html#system-testing] 65 | gem "capybara" 66 | gem "selenium-webdriver" 67 | end 68 | 69 | gem "csv", "~> 3.3" 70 | gem "mp3info" 71 | gem "dotenv-rails" 72 | -------------------------------------------------------------------------------- /config/environments/development.rb: -------------------------------------------------------------------------------- 1 | require "active_support/core_ext/integer/time" 2 | 3 | Rails.application.configure do 4 | # Settings specified here will take precedence over those in config/application.rb. 5 | 6 | # Make code changes take effect immediately without server restart. 7 | config.enable_reloading = true 8 | 9 | # Do not eager load code on boot. 10 | config.eager_load = false 11 | 12 | # Show full error reports. 13 | config.consider_all_requests_local = true 14 | 15 | # Enable server timing. 16 | config.server_timing = true 17 | 18 | # Enable/disable Action Controller caching. By default Action Controller caching is disabled. 19 | # Run rails dev:cache to toggle Action Controller caching. 20 | if Rails.root.join("tmp/caching-dev.txt").exist? 21 | config.action_controller.perform_caching = true 22 | config.action_controller.enable_fragment_cache_logging = true 23 | config.public_file_server.headers = { "cache-control" => "public, max-age=#{2.days.to_i}" } 24 | else 25 | config.action_controller.perform_caching = false 26 | end 27 | 28 | # Change to :null_store to avoid any caching. 29 | config.cache_store = :memory_store 30 | 31 | # Store uploaded files on the local file system (see config/storage.yml for options). 32 | config.active_storage.service = :local 33 | 34 | # Don't care if the mailer can't send. 35 | config.action_mailer.raise_delivery_errors = false 36 | 37 | # Make template changes take effect immediately. 38 | config.action_mailer.perform_caching = false 39 | 40 | # Set localhost to be used by links generated in mailer templates. 41 | config.action_mailer.default_url_options = { host: "localhost", port: 3000 } 42 | 43 | # Print deprecation notices to the Rails logger. 44 | config.active_support.deprecation = :log 45 | 46 | # Raise an error on page load if there are pending migrations. 47 | config.active_record.migration_error = :page_load 48 | 49 | # Highlight code that triggered database queries in logs. 50 | config.active_record.verbose_query_logs = true 51 | 52 | # Append comments with runtime information tags to SQL queries in logs. 53 | config.active_record.query_log_tags_enabled = true 54 | 55 | # Highlight code that enqueued background job in logs. 56 | config.active_job.verbose_enqueue_logs = true 57 | 58 | # Raises error for missing translations. 59 | # config.i18n.raise_on_missing_translations = true 60 | 61 | # Annotate rendered view with file names. 62 | config.action_view.annotate_rendered_view_with_filenames = true 63 | 64 | # Uncomment if you wish to allow Action Cable access from any origin. 65 | # config.action_cable.disable_request_forgery_protection = true 66 | 67 | # Raise error when a before_action's only/except options reference missing actions. 68 | config.action_controller.raise_on_missing_callback_actions = true 69 | 70 | # Apply autocorrection by RuboCop to files generated by `bin/rails generate`. 71 | # config.generators.apply_rubocop_autocorrect_after_generate! 72 | end 73 | -------------------------------------------------------------------------------- /.kamal/hooks/pre-deploy.sample: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | 3 | # A sample pre-deploy hook 4 | # 5 | # Checks the Github status of the build, waiting for a pending build to complete for up to 720 seconds. 6 | # 7 | # Fails unless the combined status is "success" 8 | # 9 | # These environment variables are available: 10 | # KAMAL_RECORDED_AT 11 | # KAMAL_PERFORMER 12 | # KAMAL_VERSION 13 | # KAMAL_HOSTS 14 | # KAMAL_COMMAND 15 | # KAMAL_SUBCOMMAND 16 | # KAMAL_ROLES (if set) 17 | # KAMAL_DESTINATION (if set) 18 | 19 | # Only check the build status for production deployments 20 | if ENV["KAMAL_COMMAND"] == "rollback" || ENV["KAMAL_DESTINATION"] != "production" 21 | exit 0 22 | end 23 | 24 | require "bundler/inline" 25 | 26 | # true = install gems so this is fast on repeat invocations 27 | gemfile(true, quiet: true) do 28 | source "https://rubygems.org" 29 | 30 | gem "octokit" 31 | gem "faraday-retry" 32 | end 33 | 34 | MAX_ATTEMPTS = 72 35 | ATTEMPTS_GAP = 10 36 | 37 | def exit_with_error(message) 38 | $stderr.puts message 39 | exit 1 40 | end 41 | 42 | class GithubStatusChecks 43 | attr_reader :remote_url, :git_sha, :github_client, :combined_status 44 | 45 | def initialize 46 | @remote_url = `git config --get remote.origin.url`.strip.delete_prefix("https://github.com/") 47 | @git_sha = `git rev-parse HEAD`.strip 48 | @github_client = Octokit::Client.new(access_token: ENV["GITHUB_TOKEN"]) 49 | refresh! 50 | end 51 | 52 | def refresh! 53 | @combined_status = github_client.combined_status(remote_url, git_sha) 54 | end 55 | 56 | def state 57 | combined_status[:state] 58 | end 59 | 60 | def first_status_url 61 | first_status = combined_status[:statuses].find { |status| status[:state] == state } 62 | first_status && first_status[:target_url] 63 | end 64 | 65 | def complete_count 66 | combined_status[:statuses].count { |status| status[:state] != "pending"} 67 | end 68 | 69 | def total_count 70 | combined_status[:statuses].count 71 | end 72 | 73 | def current_status 74 | if total_count > 0 75 | "Completed #{complete_count}/#{total_count} checks, see #{first_status_url} ..." 76 | else 77 | "Build not started..." 78 | end 79 | end 80 | end 81 | 82 | 83 | $stdout.sync = true 84 | 85 | begin 86 | puts "Checking build status..." 87 | 88 | attempts = 0 89 | checks = GithubStatusChecks.new 90 | 91 | loop do 92 | case checks.state 93 | when "success" 94 | puts "Checks passed, see #{checks.first_status_url}" 95 | exit 0 96 | when "failure" 97 | exit_with_error "Checks failed, see #{checks.first_status_url}" 98 | when "pending" 99 | attempts += 1 100 | end 101 | 102 | exit_with_error "Checks are still pending, gave up after #{MAX_ATTEMPTS * ATTEMPTS_GAP} seconds" if attempts == MAX_ATTEMPTS 103 | 104 | puts checks.current_status 105 | sleep(ATTEMPTS_GAP) 106 | checks.refresh! 107 | end 108 | rescue Octokit::NotFound 109 | exit_with_error "Build status could not be found" 110 | end 111 | -------------------------------------------------------------------------------- /bin/bundle: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | # frozen_string_literal: true 3 | 4 | # 5 | # This file was generated by Bundler. 6 | # 7 | # The application 'bundle' is installed as part of a gem, and 8 | # this file is here to facilitate running it. 9 | # 10 | 11 | require "rubygems" 12 | 13 | m = Module.new do 14 | module_function 15 | 16 | def invoked_as_script? 17 | File.expand_path($0) == File.expand_path(__FILE__) 18 | end 19 | 20 | def env_var_version 21 | ENV["BUNDLER_VERSION"] 22 | end 23 | 24 | def cli_arg_version 25 | return unless invoked_as_script? # don't want to hijack other binstubs 26 | return unless "update".start_with?(ARGV.first || " ") # must be running `bundle update` 27 | bundler_version = nil 28 | update_index = nil 29 | ARGV.each_with_index do |a, i| 30 | if update_index && update_index.succ == i && a.match?(Gem::Version::ANCHORED_VERSION_PATTERN) 31 | bundler_version = a 32 | end 33 | next unless a =~ /\A--bundler(?:[= ](#{Gem::Version::VERSION_PATTERN}))?\z/ 34 | bundler_version = $1 35 | update_index = i 36 | end 37 | bundler_version 38 | end 39 | 40 | def gemfile 41 | gemfile = ENV["BUNDLE_GEMFILE"] 42 | return gemfile if gemfile && !gemfile.empty? 43 | 44 | File.expand_path("../Gemfile", __dir__) 45 | end 46 | 47 | def lockfile 48 | lockfile = 49 | case File.basename(gemfile) 50 | when "gems.rb" then gemfile.sub(/\.rb$/, ".locked") 51 | else "#{gemfile}.lock" 52 | end 53 | File.expand_path(lockfile) 54 | end 55 | 56 | def lockfile_version 57 | return unless File.file?(lockfile) 58 | lockfile_contents = File.read(lockfile) 59 | return unless lockfile_contents =~ /\n\nBUNDLED WITH\n\s{2,}(#{Gem::Version::VERSION_PATTERN})\n/ 60 | Regexp.last_match(1) 61 | end 62 | 63 | def bundler_requirement 64 | @bundler_requirement ||= 65 | env_var_version || 66 | cli_arg_version || 67 | bundler_requirement_for(lockfile_version) 68 | end 69 | 70 | def bundler_requirement_for(version) 71 | return "#{Gem::Requirement.default}.a" unless version 72 | 73 | bundler_gem_version = Gem::Version.new(version) 74 | 75 | bundler_gem_version.approximate_recommendation 76 | end 77 | 78 | def load_bundler! 79 | ENV["BUNDLE_GEMFILE"] ||= gemfile 80 | 81 | activate_bundler 82 | end 83 | 84 | def activate_bundler 85 | gem_error = activation_error_handling do 86 | gem "bundler", bundler_requirement 87 | end 88 | return if gem_error.nil? 89 | require_error = activation_error_handling do 90 | require "bundler/version" 91 | end 92 | return if require_error.nil? && Gem::Requirement.new(bundler_requirement).satisfied_by?(Gem::Version.new(Bundler::VERSION)) 93 | warn "Activating bundler (#{bundler_requirement}) failed:\n#{gem_error.message}\n\nTo install the version of bundler this project requires, run `gem install bundler -v '#{bundler_requirement}'`" 94 | exit 42 95 | end 96 | 97 | def activation_error_handling 98 | yield 99 | nil 100 | rescue StandardError, LoadError => e 101 | e 102 | end 103 | end 104 | 105 | m.load_bundler! 106 | 107 | if m.invoked_as_script? 108 | load Gem.bin_path("bundler", "bundle") 109 | end 110 | -------------------------------------------------------------------------------- /.github/workflows/ci.yml: -------------------------------------------------------------------------------- 1 | name: CI 2 | 3 | on: 4 | pull_request: 5 | push: 6 | branches: [ main ] 7 | 8 | jobs: 9 | scan_ruby: 10 | runs-on: ubuntu-latest 11 | 12 | steps: 13 | - name: Checkout code 14 | uses: actions/checkout@v4 15 | 16 | - name: Set up Ruby 17 | uses: ruby/setup-ruby@v1 18 | with: 19 | ruby-version: .ruby-version 20 | bundler-cache: true 21 | 22 | - name: Scan for common Rails security vulnerabilities using static analysis 23 | run: bin/brakeman --no-pager 24 | 25 | scan_js: 26 | runs-on: ubuntu-latest 27 | 28 | steps: 29 | - name: Checkout code 30 | uses: actions/checkout@v4 31 | 32 | - name: Set up Ruby 33 | uses: ruby/setup-ruby@v1 34 | with: 35 | ruby-version: .ruby-version 36 | bundler-cache: true 37 | 38 | - name: Scan for security vulnerabilities in JavaScript dependencies 39 | run: bin/importmap audit 40 | 41 | lint: 42 | runs-on: ubuntu-latest 43 | steps: 44 | - name: Checkout code 45 | uses: actions/checkout@v4 46 | 47 | - name: Set up Ruby 48 | uses: ruby/setup-ruby@v1 49 | with: 50 | ruby-version: .ruby-version 51 | bundler-cache: true 52 | 53 | - name: Lint code for consistent style 54 | run: bin/rubocop -f github 55 | 56 | test: 57 | runs-on: ubuntu-latest 58 | 59 | steps: 60 | - name: Install packages 61 | run: sudo apt-get update && sudo apt-get install --no-install-recommends -y build-essential git libyaml-dev pkg-config google-chrome-stable 62 | 63 | - name: Checkout code 64 | uses: actions/checkout@v4 65 | 66 | - name: Set up Ruby 67 | uses: ruby/setup-ruby@v1 68 | with: 69 | ruby-version: .ruby-version 70 | bundler-cache: true 71 | 72 | - name: Run tests 73 | env: 74 | RAILS_ENV: test 75 | run: bin/rails db:test:prepare test test:system 76 | 77 | - name: Keep screenshots from failed system tests 78 | uses: actions/upload-artifact@v4 79 | if: failure() 80 | with: 81 | name: screenshots 82 | path: ${{ github.workspace }}/tmp/screenshots 83 | if-no-files-found: ignore 84 | 85 | image: 86 | needs: [lint, test, scan_ruby, scan_js] 87 | runs-on: ubuntu-latest 88 | if: github.event_name == 'push' && github.ref == 'refs/heads/main' 89 | permissions: 90 | contents: read 91 | packages: write 92 | steps: 93 | - name: Checkout code 94 | uses: actions/checkout@v4 95 | 96 | - name: Login to GitHub Container Registry 97 | uses: docker/login-action@v3 98 | with: 99 | registry: ghcr.io 100 | username: ${{ github.actor }} 101 | password: ${{ secrets.GITHUB_TOKEN }} 102 | 103 | - name: Build the Docker image 104 | run: docker build -t cathop . 105 | 106 | - name: Push the Docker image to GitHub Container Registry 107 | uses: docker/build-push-action@v6 108 | with: 109 | context: . 110 | file: Dockerfile 111 | push: true 112 | tags: | 113 | ghcr.io/sbeltranc/cathop:latest 114 | ghcr.io/sbeltranc/cathop:${{ github.sha }} -------------------------------------------------------------------------------- /app/javascript/controllers/base64_controller.js: -------------------------------------------------------------------------------- 1 | import { Controller } from "@hotwired/stimulus" 2 | 3 | export default class extends Controller { 4 | static targets = ["container"] 5 | 6 | async handle(input) { 7 | if (!input?.trim()) return this.renderError('Input is required') 8 | 9 | try { 10 | return this.renderResponse(input) 11 | } catch (error) { 12 | return this.renderError(error.message) 13 | } 14 | } 15 | 16 | renderResponse(input) { 17 | const container = document.createElement('div') 18 | container.className = 'cat-response' 19 | 20 | const isBase64 = this.isBase64(input) 21 | container.innerHTML = ` 22 |
23 |
24 | Input Type: 25 | ${isBase64 ? 'Base64 Encoded' : 'Plain Text'} 26 |
27 |
28 | Length: 29 | ${input.length} characters 30 |
31 |
32 | ` 33 | 34 | const contentSection = document.createElement('div') 35 | contentSection.className = 'cat-response-content' 36 | 37 | const [original, converted] = isBase64 38 | ? [input, this.decode(input)] 39 | : [input, this.encode(input)] 40 | 41 | contentSection.innerHTML = this.renderPreview(original, converted) 42 | container.appendChild(contentSection) 43 | 44 | return container 45 | } 46 | 47 | renderError(message) { 48 | const container = document.createElement('div') 49 | container.className = 'cat-response error' 50 | container.innerHTML = ` 51 |
52 |
53 | Error: 54 | ${this.escapeHtml(message)} 55 |
56 |
57 | ` 58 | return container 59 | } 60 | 61 | isBase64(str) { 62 | try { 63 | return btoa(atob(str)) === str 64 | } catch { 65 | return false 66 | } 67 | } 68 | 69 | encode(str) { 70 | try { 71 | return btoa(str) 72 | } catch (error) { 73 | throw new Error('Failed to encode text to Base64') 74 | } 75 | } 76 | 77 | decode(str) { 78 | try { 79 | return atob(str) 80 | } catch (error) { 81 | throw new Error('Failed to decode Base64 text') 82 | } 83 | } 84 | 85 | renderPreview(original, converted) { 86 | return ` 87 |
88 |
89 |
Original Text
90 |
91 |
${this.escapeHtml(original)}
92 |
93 |
94 |
95 |
${this.isBase64(original) ? 'Decoded Text' : 'Encoded Text'}
96 |
97 |
${this.escapeHtml(converted)}
98 |
99 |
100 |
101 | ` 102 | } 103 | 104 | escapeHtml(unsafe) { 105 | if (!unsafe) return '' 106 | return String(unsafe) 107 | .replace(/&/g, "&") 108 | .replace(//g, ">") 110 | .replace(/"/g, """) 111 | .replace(/'/g, "'") 112 | } 113 | } -------------------------------------------------------------------------------- /app/javascript/controllers/ip_controller.js: -------------------------------------------------------------------------------- 1 | import { Controller } from "@hotwired/stimulus" 2 | 3 | export default class extends Controller { 4 | static targets = ["container"] 5 | static values = { 6 | mapZoom: { type: Number, default: 0.1 } 7 | } 8 | 9 | async handle(ip) { 10 | if (!ip?.trim()) return this.renderError('IP address is required') 11 | 12 | try { 13 | const data = await this.fetchIpInfo(ip) 14 | return this.renderResponse(data) 15 | } catch (error) { 16 | return this.renderError(error.message) 17 | } 18 | } 19 | 20 | async fetchIpInfo(ip) { 21 | const response = await fetch(`/api/lookup/ip/${ip}`) 22 | const data = await response.json() 23 | 24 | if (data.error) { 25 | throw new Error(data.error || 'Failed to fetch IP information') 26 | } 27 | 28 | return data 29 | } 30 | 31 | renderResponse(data) { 32 | const container = document.createElement('div') 33 | container.className = 'cat-response' 34 | 35 | container.innerHTML = ` 36 |
37 |
38 | IP Address: 39 | ${this.escapeHtml(data.ip)} 40 |
41 |
42 |
43 | ${Object.entries(data) 44 | .filter(([key]) => !['error', 'reason'].includes(key)) 45 | .map(([key, value]) => ` 46 |
47 | ${this.escapeHtml(key)} 48 | ${this.escapeHtml(value)} 49 |
50 | `).join('')} 51 |
52 | ` 53 | 54 | const contentSection = document.createElement('div') 55 | contentSection.className = 'cat-response-content' 56 | contentSection.innerHTML = [ 57 | this.renderMap(data) 58 | ].join('') 59 | 60 | container.appendChild(contentSection) 61 | return container 62 | } 63 | 64 | renderError(message) { 65 | const container = document.createElement('div') 66 | container.className = 'cat-response error' 67 | container.innerHTML = ` 68 |
69 |
70 | Error: 71 | ${this.escapeHtml(message)} 72 |
73 |
74 | ` 75 | return container 76 | } 77 | 78 | renderMap(data) { 79 | if (!data.latitude || !data.longitude) return '' 80 | 81 | const bbox = { 82 | west: data.longitude - this.mapZoomValue, 83 | south: data.latitude - this.mapZoomValue, 84 | east: data.longitude + this.mapZoomValue, 85 | north: data.latitude + this.mapZoomValue 86 | } 87 | 88 | return ` 89 |
90 |
91 |
92 | 100 |
101 |
102 |
103 | ` 104 | } 105 | 106 | escapeHtml(unsafe) { 107 | if (unsafe === undefined || unsafe === null) return '' 108 | return String(unsafe) 109 | .replace(/&/g, "&") 110 | .replace(//g, ">") 112 | .replace(/"/g, """) 113 | .replace(/'/g, "'") 114 | } 115 | } -------------------------------------------------------------------------------- /config/environments/production.rb: -------------------------------------------------------------------------------- 1 | require "active_support/core_ext/integer/time" 2 | 3 | Rails.application.configure do 4 | # Settings specified here will take precedence over those in config/application.rb. 5 | 6 | # Code is not reloaded between requests. 7 | config.enable_reloading = false 8 | 9 | # Eager load code on boot for better performance and memory savings (ignored by Rake tasks). 10 | config.eager_load = true 11 | 12 | # Full error reports are disabled. 13 | config.consider_all_requests_local = false 14 | 15 | # Turn on fragment caching in view templates. 16 | config.action_controller.perform_caching = true 17 | 18 | # Cache assets for far-future expiry since they are all digest stamped. 19 | config.public_file_server.headers = { "cache-control" => "public, max-age=#{1.year.to_i}" } 20 | 21 | # Enable serving of images, stylesheets, and JavaScripts from an asset server. 22 | # config.asset_host = "http://assets.example.com" 23 | 24 | # Store uploaded files on the local file system (see config/storage.yml for options). 25 | config.active_storage.service = :local 26 | 27 | # Assume all access to the app is happening through a SSL-terminating reverse proxy. 28 | config.assume_ssl = true 29 | 30 | # Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies. 31 | config.force_ssl = true 32 | 33 | # Skip http-to-https redirect for the default health check endpoint. 34 | # config.ssl_options = { redirect: { exclude: ->(request) { request.path == "/up" } } } 35 | 36 | # Log to STDOUT with the current request id as a default log tag. 37 | config.log_tags = [ :request_id ] 38 | config.logger = ActiveSupport::TaggedLogging.logger(STDOUT) 39 | 40 | # Change to "debug" to log everything (including potentially personally-identifiable information!) 41 | config.log_level = ENV.fetch("RAILS_LOG_LEVEL", "info") 42 | 43 | # Prevent health checks from clogging up the logs. 44 | config.silence_healthcheck_path = "/up" 45 | 46 | # Don't log any deprecations. 47 | config.active_support.report_deprecations = false 48 | 49 | # Replace the default in-process memory cache store with a durable alternative. 50 | config.cache_store = :solid_cache_store 51 | 52 | # Replace the default in-process and non-durable queuing backend for Active Job. 53 | config.active_job.queue_adapter = :solid_queue 54 | config.solid_queue.connects_to = { database: { writing: :queue } } 55 | 56 | # Ignore bad email addresses and do not raise email delivery errors. 57 | # Set this to true and configure the email server for immediate delivery to raise delivery errors. 58 | # config.action_mailer.raise_delivery_errors = false 59 | 60 | # Set host to be used by links generated in mailer templates. 61 | config.action_mailer.default_url_options = { host: "example.com" } 62 | 63 | # Specify outgoing SMTP server. Remember to add smtp/* credentials via rails credentials:edit. 64 | # config.action_mailer.smtp_settings = { 65 | # user_name: Rails.application.credentials.dig(:smtp, :user_name), 66 | # password: Rails.application.credentials.dig(:smtp, :password), 67 | # address: "smtp.example.com", 68 | # port: 587, 69 | # authentication: :plain 70 | # } 71 | 72 | # Enable locale fallbacks for I18n (makes lookups for any locale fall back to 73 | # the I18n.default_locale when a translation cannot be found). 74 | config.i18n.fallbacks = true 75 | 76 | # Do not dump schema after migrations. 77 | config.active_record.dump_schema_after_migration = false 78 | 79 | # Only use :id for inspections in production. 80 | config.active_record.attributes_for_inspect = [ :id ] 81 | 82 | # Enable DNS rebinding protection and other `Host` header attacks. 83 | config.hosts = [ 84 | "cathop.lat", 85 | /.*\.cathop\.lat/ 86 | ] 87 | # 88 | # Skip DNS rebinding protection for the default health check endpoint. 89 | # config.host_authorization = { exclude: ->(request) { request.path == "/up" } } 90 | end 91 | -------------------------------------------------------------------------------- /app/views/home/index.html.erb: -------------------------------------------------------------------------------- 1 | 2 |
3 | 14 | 15 |
16 |
17 |
18 |
19 |
20 |
21 | <%= image_tag "cathop_logo.png", alt: "Header Image", class: "cat-logo", loading: "eager" %> 22 |
23 |
24 | 72 |
73 | -------------------------------------------------------------------------------- /config/deploy.yml: -------------------------------------------------------------------------------- 1 | # Name of your application. Used to uniquely configure containers. 2 | service: cathop 3 | 4 | # Name of the container image. 5 | image: sbeltranc/cathop 6 | 7 | # Deploy to these servers. 8 | servers: 9 | web: 10 | - 192.168.0.1 11 | # job: 12 | # hosts: 13 | # - 192.168.0.1 14 | # cmd: bin/jobs 15 | 16 | # Enable SSL auto certification via Let's Encrypt and allow for multiple apps on a single web server. 17 | # Remove this section when using multiple web servers and ensure you terminate SSL at your load balancer. 18 | # 19 | # Note: If using Cloudflare, set encryption mode in SSL/TLS setting to "Full" to enable CF-to-app encryption. 20 | proxy: 21 | ssl: true 22 | host: cathop.lat 23 | 24 | # Credentials for your image host. 25 | registry: 26 | # Specify the registry server, if you're not using Docker Hub 27 | # server: registry.digitalocean.com / ghcr.io / ... 28 | username: your-user 29 | 30 | # Always use an access token rather than real password when possible. 31 | password: 32 | - KAMAL_REGISTRY_PASSWORD 33 | 34 | # Inject ENV variables into containers (secrets come from .kamal/secrets). 35 | env: 36 | secret: 37 | - RAILS_MASTER_KEY 38 | clear: 39 | # Run the Solid Queue Supervisor inside the web server's Puma process to do jobs. 40 | # When you start using multiple servers, you should split out job processing to a dedicated machine. 41 | SOLID_QUEUE_IN_PUMA: true 42 | 43 | # Set number of processes dedicated to Solid Queue (default: 1) 44 | # JOB_CONCURRENCY: 3 45 | 46 | # Set number of cores available to the application on each server (default: 1). 47 | # WEB_CONCURRENCY: 2 48 | 49 | # Match this to any external database server to configure Active Record correctly 50 | # Use cathop-db for a db accessory server on same machine via local kamal docker network. 51 | # DB_HOST: 192.168.0.2 52 | 53 | # Log everything from Rails 54 | # RAILS_LOG_LEVEL: debug 55 | 56 | # Aliases are triggered with "bin/kamal ". You can overwrite arguments on invocation: 57 | # "bin/kamal logs -r job" will tail logs from the first server in the job section. 58 | aliases: 59 | console: app exec --interactive --reuse "bin/rails console" 60 | shell: app exec --interactive --reuse "bash" 61 | logs: app logs -f 62 | dbc: app exec --interactive --reuse "bin/rails dbconsole" 63 | 64 | 65 | # Use a persistent storage volume for sqlite database files and local Active Storage files. 66 | # Recommended to change this to a mounted volume path that is backed up off server. 67 | volumes: 68 | - "cathop_storage:/rails/storage" 69 | 70 | 71 | # Bridge fingerprinted assets, like JS and CSS, between versions to avoid 72 | # hitting 404 on in-flight requests. Combines all files from new and old 73 | # version inside the asset_path. 74 | asset_path: /rails/public/assets 75 | 76 | # Configure the image builder. 77 | builder: 78 | arch: amd64 79 | 80 | # # Build image via remote server (useful for faster amd64 builds on arm64 computers) 81 | # remote: ssh://docker@docker-builder-server 82 | # 83 | # # Pass arguments and secrets to the Docker build process 84 | # args: 85 | # RUBY_VERSION: ruby-3.4.4 86 | # secrets: 87 | # - GITHUB_TOKEN 88 | # - RAILS_MASTER_KEY 89 | 90 | # Use a different ssh user than root 91 | # ssh: 92 | # user: app 93 | 94 | # Use accessory services (secrets come from .kamal/secrets). 95 | # accessories: 96 | # db: 97 | # image: mysql:8.0 98 | # host: 192.168.0.2 99 | # # Change to 3306 to expose port to the world instead of just local network. 100 | # port: "127.0.0.1:3306:3306" 101 | # env: 102 | # clear: 103 | # MYSQL_ROOT_HOST: '%' 104 | # secret: 105 | # - MYSQL_ROOT_PASSWORD 106 | # files: 107 | # - config/mysql/production.cnf:/etc/mysql/my.cnf 108 | # - db/production.sql:/docker-entrypoint-initdb.d/setup.sql 109 | # directories: 110 | # - data:/var/lib/mysql 111 | # redis: 112 | # image: redis:7.0 113 | # host: 192.168.0.2 114 | # port: 6379 115 | # directories: 116 | # - data:/data 117 | -------------------------------------------------------------------------------- /test/controllers/api_controller_test.rb: -------------------------------------------------------------------------------- 1 | require "test_helper" 2 | 3 | class ApiControllerTest < ActionDispatch::IntegrationTest 4 | # DOMAIN LOOKUP TESTS 5 | test "should get domain lookup" do 6 | get "/api/lookup/domain/example.com" 7 | json_response = JSON.parse(@response.body) 8 | assert_equal "EXAMPLE.COM", json_response["domain"] 9 | assert_response :success 10 | end 11 | 12 | test "should fail with a invalid domain" do 13 | get "/api/lookup/domain/hahafunnyguy" 14 | assert_response :bad_request 15 | json_response = JSON.parse(@response.body) 16 | assert_equal "The provided domain is invalid, please check if it's a valid domain", json_response["error"] 17 | end 18 | 19 | test "should fail with a non-registered domain" do 20 | get "/api/lookup/domain/asdvaksdasdaspasd.com" 21 | assert_response :internal_server_error 22 | json_response = JSON.parse(@response.body) 23 | assert_equal "No RDAP server responded successfully for this domain", json_response["error"] 24 | end 25 | 26 | # URL LOOKUP TESTS 27 | test "should get url lookup" do 28 | get api_request_url_url(url: "https://example.com") 29 | assert_response :success 30 | json_response = JSON.parse(@response.body) 31 | assert_equal "https://example.com", json_response["url"] 32 | end 33 | 34 | test "should fail with a invalid url" do 35 | get api_request_url_url(url: "asdvaksdpasd://.com") 36 | assert_response :bad_request 37 | json_response = JSON.parse(@response.body) 38 | assert_equal "The provided URL is invalid, please check if it's a valid url", json_response["error"] 39 | end 40 | 41 | test "should not be able to request a url that's not working" do 42 | get api_request_url_url(url: "https://asdvak52b35235b23sdpasd.com") 43 | assert_response :internal_server_error 44 | json_response = JSON.parse(@response.body) 45 | assert_equal "Something went wrong while requesting the URL, are you sure the URL is not down?", json_response["error"] 46 | end 47 | 48 | # IP LOOKUP TESTS 49 | test "should get ip lookup" do 50 | get api_lookup_ip_url(ip: "8.8.8.8") 51 | 52 | json_response = JSON.parse(@response.body) 53 | 54 | assert_equal "8.8.8.8", json_response["ip"] 55 | assert_equal "AS15169", json_response["asn"] 56 | assert_equal "8.8.8.0/24", json_response["range"] 57 | assert_equal "Google LLC", json_response["provider"] 58 | assert_equal "Google LLC", json_response["organisation"] 59 | end 60 | 61 | test "should fail with local ip" do 62 | get api_lookup_ip_url(ip: "127.0.0.1") 63 | assert_response :not_found 64 | json_response = JSON.parse(@response.body) 65 | assert_equal "There was no valid IP Addresses supplied.", json_response["error"] 66 | end 67 | 68 | test "should fail with invalid ip" do 69 | get api_lookup_ip_url(ip: "127.0.0.1.1") 70 | assert_response :not_found 71 | json_response = JSON.parse(@response.body) 72 | assert_equal "There was no valid IP Addresses supplied.", json_response["error"] 73 | end 74 | 75 | # SOUNDCLOUD TRACK INFO TESTS 76 | test "should fail with no url parameter for track info" do 77 | get api_soundcloud_track_info_url 78 | assert_response :bad_request 79 | json_response = JSON.parse(@response.body) 80 | assert_equal "No SoundCloud URL provided. Please add a 'url' query parameter.", json_response["error"] 81 | end 82 | 83 | test "should fail with invalid url for track info" do 84 | get api_soundcloud_track_info_url(url: "https://example.com") 85 | assert_response :bad_request 86 | json_response = JSON.parse(@response.body) 87 | assert_equal "The provided URL is not a valid SoundCloud URL.", json_response["error"] 88 | end 89 | 90 | test "should fail with invalid soundcloud url for track info" do 91 | get api_soundcloud_track_info_url(url: "https://soundcloud.com/invalid-track-url") 92 | assert_response :not_found 93 | json_response = JSON.parse(@response.body) 94 | assert_equal "Could not resolve SoundCloud track. Please check if the URL is valid.", json_response["error"] 95 | end 96 | 97 | # SOUNDCLOUD DOWNLOAD TESTS 98 | test "should fail with no url parameter for download" do 99 | get api_soundcloud_download_url 100 | assert_response :bad_request 101 | json_response = JSON.parse(@response.body) 102 | assert_equal "No SoundCloud URL provided. Please add a 'url' query parameter.", json_response["error"] 103 | end 104 | 105 | test "should fail with invalid url for download" do 106 | get api_soundcloud_download_url(url: "https://example.com") 107 | assert_response :bad_request 108 | json_response = JSON.parse(@response.body) 109 | assert_equal "The provided URL is not a valid SoundCloud URL.", json_response["error"] 110 | end 111 | 112 | test "should fail with invalid soundcloud url for download" do 113 | get api_soundcloud_download_url(url: "https://soundcloud.com/invalid-track-url") 114 | assert_response :not_found 115 | json_response = JSON.parse(@response.body) 116 | assert_equal "Could not resolve SoundCloud track. Please check if the URL is valid.", json_response["error"] 117 | end 118 | end 119 | -------------------------------------------------------------------------------- /public/404.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | The page you were looking for doesn’t exist (404 Not found) 8 | 9 | 10 | 11 | 12 | 13 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 |
104 |
105 | 106 |
107 |
108 |

The page you were looking for doesn’t exist. You may have mistyped the address or the page may have moved. If you’re the application owner check the logs for more information.

109 |
110 |
111 | 112 | 113 | 114 | 115 | -------------------------------------------------------------------------------- /app/assets/stylesheets/services.css: -------------------------------------------------------------------------------- 1 | .cat-search-bar input[type="text"].cat-invalid-url { 2 | color: #A9A9A9; 3 | border-color: #1a1a1a; 4 | background-color: #000000; 5 | } 6 | 7 | .cat-search-bar input[type="text"].cat-unknown-url { 8 | color: #FFFFFF; 9 | border-color: #FFFFFF; 10 | background-color: #1a1a1a; 11 | } 12 | 13 | .cat-search-bar input[type="text"].cat-ip-url { 14 | color: #00ffcc; 15 | border-color: #00ffcc; 16 | } 17 | 18 | .cat-search-bar input[type="text"].cat-youtube-url { 19 | color: #ff6b6b; 20 | border-color: #ff6b6b; 21 | } 22 | 23 | .cat-search-bar input[type="text"].cat-spotify-url { 24 | color: #1DB954; 25 | border-color: #1DB954; 26 | } 27 | 28 | .cat-search-bar input[type="text"].cat-soundcloud-url { 29 | color: #ff7700; 30 | border-color: #ff7700; 31 | } 32 | 33 | .cat-search-bar input[type="text"].cat-roblox-url { 34 | color: #007aff; 35 | border-color: #007aff; 36 | } 37 | 38 | .cat-search-bar input[type="text"].cat-base64-url { 39 | color: #9966ff; 40 | border-color: #9966ff; 41 | } 42 | 43 | .cat-search-bar input[type="text"].cat-domain-url { 44 | color: #ff8c42; 45 | border-color: #ff8c42; 46 | } 47 | 48 | .cat-search-bar input[type="text"].cat-youtube-url::placeholder { 49 | color: rgba(255, 107, 107, 0.6); 50 | } 51 | 52 | .cat-search-bar input[type="text"].cat-spotify-url::placeholder { 53 | color: rgba(29, 185, 84, 0.6); 54 | } 55 | 56 | .cat-search-bar input[type="text"].cat-soundcloud-url::placeholder { 57 | color: rgba(255, 119, 0, 0.6); 58 | } 59 | 60 | .cat-search-bar input[type="text"].cat-roblox-url::placeholder { 61 | color: rgba(0, 122, 255, 0.6); 62 | } 63 | 64 | .cat-search-bar input[type="text"].cat-base64-url::placeholder { 65 | color: rgba(153, 102, 255, 0.6); 66 | } 67 | 68 | .cat-search-bar input[type="text"].cat-domain-url::placeholder { 69 | color: rgba(255, 140, 66, 0.6); 70 | } 71 | 72 | .cat-search-bar input[type="text"].cat-generic-url { 73 | color: #4169e1; 74 | border-color: #4169e1; 75 | } 76 | 77 | .cat-search-bar input[type="text"].cat-generic-url::placeholder { 78 | color: rgba(65, 105, 225, 0.6); 79 | } 80 | 81 | .cat-message.cat-unknown { 82 | color: #FFFFFF; 83 | } 84 | 85 | .cat-message.cat-ip { 86 | color: #00ffcc; 87 | } 88 | 89 | .cat-message.cat-youtube { 90 | color: #ff6b6b; 91 | } 92 | 93 | .cat-message.cat-spotify { 94 | color: #1DB954; 95 | } 96 | 97 | .cat-message.cat-soundcloud { 98 | color: #ff7700; 99 | } 100 | 101 | .cat-message.cat-roblox { 102 | color: #007aff; 103 | } 104 | 105 | .cat-message.cat-base64 { 106 | color: #9966ff; 107 | } 108 | 109 | .cat-message.cat-domain { 110 | color: #ff8c42; 111 | } 112 | 113 | .cat-message.cat-generic { 114 | color: #4169e1; 115 | } 116 | 117 | .cat-message.error { 118 | color: #ff4444; 119 | font-weight: bold; 120 | } 121 | 122 | .cat-soundcloud-track, 123 | .cat-soundcloud-description, 124 | .cat-soundcloud-download { 125 | border-top: 1px solid #333; 126 | padding-top: 1.5rem; 127 | margin-top: 1.5rem; 128 | } 129 | 130 | .cat-track-container { 131 | display: flex; 132 | gap: 1.5rem; 133 | align-items: flex-start; 134 | } 135 | 136 | .cat-track-artwork-container { 137 | flex-shrink: 0; 138 | } 139 | 140 | .cat-track-artwork { 141 | width: 120px; 142 | height: 120px; 143 | object-fit: cover; 144 | border-radius: 4px; 145 | border: 1px solid #444; 146 | } 147 | 148 | .cat-track-artwork-placeholder { 149 | width: 120px; 150 | height: 120px; 151 | background-color: #1a1a1a; 152 | border: 1px solid #444; 153 | border-radius: 4px; 154 | display: flex; 155 | align-items: center; 156 | justify-content: center; 157 | color: #888; 158 | font-size: 0.9rem; 159 | } 160 | 161 | .cat-track-details { 162 | flex-grow: 1; 163 | } 164 | 165 | .cat-track-title { 166 | font-size: 1.5rem; 167 | font-weight: bold; 168 | color: #ff7700; 169 | margin-bottom: 0.75rem; 170 | } 171 | 172 | .cat-track-artist, 173 | .cat-track-duration, 174 | .cat-track-genre { 175 | margin-bottom: 0.35rem; 176 | } 177 | 178 | .cat-track-artist .cat-value { 179 | color: #eee; 180 | font-weight: bold; 181 | } 182 | 183 | .cat-track-stats { 184 | display: flex; 185 | flex-wrap: wrap; 186 | gap: 0.75rem; 187 | margin: 1rem 0; 188 | color: #aaa; 189 | font-size: 0.9rem; 190 | } 191 | 192 | .cat-track-stats .cat-stat { 193 | display: inline-flex; 194 | align-items: center; 195 | } 196 | 197 | .cat-track-metadata { 198 | margin-top: 1rem; 199 | font-size: 0.9rem; 200 | color: #bbb; 201 | } 202 | 203 | .cat-description-content { 204 | margin-top: 0.75rem; 205 | color: #ccc; 206 | white-space: pre-wrap; 207 | line-height: 1.6; 208 | } 209 | 210 | .cat-download-success, 211 | .cat-download-error { 212 | background-color: #1a1a1a; 213 | padding: 1.25rem; 214 | border-radius: 4px; 215 | border: 1px solid #333; 216 | margin-top: 0.75rem; 217 | } 218 | 219 | .cat-download-status { 220 | margin-bottom: 0.75rem; 221 | } 222 | 223 | .cat-download-status .cat-value.success { 224 | color: #28a745; 225 | font-weight: bold; 226 | } 227 | 228 | .cat-download-status .cat-value.error { 229 | color: #ff4444; 230 | font-weight: bold; 231 | } 232 | 233 | .cat-download-url { 234 | margin-bottom: 1.25rem; 235 | } 236 | 237 | .cat-download-url .cat-value { 238 | word-break: break-all; 239 | } 240 | 241 | .cat-download-url a { 242 | color: #ff7700; 243 | text-decoration: none; 244 | } 245 | 246 | .cat-download-url a:hover { 247 | text-decoration: underline; 248 | } 249 | 250 | .cat-download-actions { 251 | display: flex; 252 | gap: 0.75rem; 253 | } 254 | 255 | .cat-button { 256 | display: inline-block; 257 | padding: 0.6rem 1.2rem; 258 | border-radius: 4px; 259 | text-decoration: none; 260 | font-weight: bold; 261 | text-align: center; 262 | transition: background-color 0.2s; 263 | } 264 | 265 | .cat-button-primary { 266 | background-color: #ff7700; 267 | color: #111; 268 | border: 1px solid #ff8800; 269 | } 270 | 271 | .cat-button-primary:hover { 272 | background-color: #ff9933; 273 | } 274 | 275 | .cat-button-secondary { 276 | background-color: transparent; 277 | color: #ff7700; 278 | border: 1px solid #ff7700; 279 | } 280 | 281 | .cat-button-secondary:hover { 282 | background-color: rgba(255, 119, 0, 0.1); 283 | } 284 | 285 | .cat-download-error-message { 286 | color: #ddd; 287 | } -------------------------------------------------------------------------------- /app/javascript/controllers/url_controller.js: -------------------------------------------------------------------------------- 1 | import { Controller } from "@hotwired/stimulus" 2 | 3 | export default class extends Controller { 4 | static targets = ["container"] 5 | 6 | async handle(url) { 7 | if (!url?.trim()) { 8 | return this.#createErrorResponse('Please enter a URL') 9 | } 10 | 11 | try { 12 | const response = await this.#fetchUrl(url) 13 | return this.#handleResponse(response, url) 14 | } catch (error) { 15 | console.error('URL processing error:', error) 16 | return this.#createErrorResponse(error.message) 17 | } 18 | } 19 | 20 | async #fetchUrl(url) { 21 | try { 22 | const response = await fetch(`/api/lookup/url/?url=${encodeURIComponent(url)}`) 23 | const data = await response.json() 24 | 25 | if (!response.ok) { 26 | throw new Error(data.error || `Failed to fetch URL (${response.status})`) 27 | } 28 | 29 | return data 30 | } catch (error) { 31 | if (error instanceof SyntaxError) { 32 | throw new Error('Invalid response format from server') 33 | } 34 | throw error 35 | } 36 | } 37 | 38 | #handleResponse(data, url) { 39 | const container = document.createElement('div') 40 | container.className = 'cat-response' 41 | 42 | this.#appendMetadata(container, { url, status: data.status }) 43 | 44 | if (data.headers) { 45 | this.#appendHeaders(container, data.headers) 46 | } 47 | 48 | this.#appendContent(container, data) 49 | return container 50 | } 51 | 52 | #appendMetadata(container, { url, status }) { 53 | container.innerHTML = ` 54 | 64 | ` 65 | } 66 | 67 | #appendHeaders(container, headers) { 68 | const headerRows = Object.entries(headers) 69 | .map(([key, value]) => ` 70 |
71 | ${this.#escape(key)}: 72 | ${this.#escape(value)} 73 |
74 | `).join('') 75 | 76 | container.innerHTML += ` 77 |
78 |
Headers
79 |
80 | ${headerRows} 81 |
82 |
83 | ` 84 | } 85 | 86 | #appendContent(container, data) { 87 | const contentSection = document.createElement('div') 88 | contentSection.className = 'cat-response-content' 89 | 90 | const contentType = this.#getContentType(data.headers) 91 | contentSection.innerHTML = this.#renderContent(data.body, contentType) 92 | 93 | container.appendChild(contentSection) 94 | } 95 | 96 | #getContentType(headers) { 97 | if (!headers) return null 98 | 99 | const contentTypeHeader = headers['Content-Type'] || headers['content-type'] 100 | if (!contentTypeHeader || typeof contentTypeHeader !== 'string') return null 101 | 102 | return contentTypeHeader.toLowerCase() 103 | } 104 | 105 | #renderContent(content, contentType) { 106 | if (!content || typeof content !== 'string') { 107 | return this.#renderEmptyContent() 108 | } 109 | 110 | if (!contentType || typeof contentType !== 'string') { 111 | return this.#renderTextContent(content) 112 | } 113 | 114 | const type = contentType.toLowerCase() 115 | if (type.includes('image')) return this.#renderImage(content, type) 116 | if (type.includes('video')) return this.#renderVideo(content, type) 117 | if (type.includes('audio')) return this.#renderAudio(content, type) 118 | if (type.includes('json')) return this.#renderJson(content) 119 | 120 | return this.#renderTextContent(content) 121 | } 122 | 123 | #renderEmptyContent() { 124 | return ` 125 |
126 |
No content available
127 |
128 | ` 129 | } 130 | 131 | #renderImage(content, contentType) { 132 | return ` 133 |
134 | Response preview 135 |
136 | ` 137 | } 138 | 139 | #renderVideo(content, contentType) { 140 | return ` 141 |
142 | 146 |
147 | ` 148 | } 149 | 150 | #renderAudio(content, contentType) { 151 | return ` 152 |
153 | 157 |
158 | ` 159 | } 160 | 161 | #renderJson(content) { 162 | try { 163 | const parsed = typeof content === 'string' ? JSON.parse(content) : content 164 | const formatted = JSON.stringify(parsed, null, 2) 165 | return ` 166 |
167 |
${this.#escape(formatted)}
168 |
169 | ` 170 | } catch { 171 | return this.#renderTextContent(content) 172 | } 173 | } 174 | 175 | #renderTextContent(content) { 176 | return ` 177 |
178 |
${this.#escape(content)}
179 |
180 | ` 181 | } 182 | 183 | #createErrorResponse(message) { 184 | const container = document.createElement('div') 185 | container.className = 'cat-response error' 186 | container.innerHTML = ` 187 | 193 | ` 194 | return container 195 | } 196 | 197 | #escape(unsafe) { 198 | if (unsafe == null) return '' 199 | 200 | return String(unsafe) 201 | .replace(/&/g, "&") 202 | .replace(//g, ">") 204 | .replace(/"/g, """) 205 | .replace(/'/g, "'") 206 | } 207 | } -------------------------------------------------------------------------------- /db/queue_schema.rb: -------------------------------------------------------------------------------- 1 | ActiveRecord::Schema[7.1].define(version: 1) do 2 | create_table "solid_queue_blocked_executions", force: :cascade do |t| 3 | t.bigint "job_id", null: false 4 | t.string "queue_name", null: false 5 | t.integer "priority", default: 0, null: false 6 | t.string "concurrency_key", null: false 7 | t.datetime "expires_at", null: false 8 | t.datetime "created_at", null: false 9 | t.index [ "concurrency_key", "priority", "job_id" ], name: "index_solid_queue_blocked_executions_for_release" 10 | t.index [ "expires_at", "concurrency_key" ], name: "index_solid_queue_blocked_executions_for_maintenance" 11 | t.index [ "job_id" ], name: "index_solid_queue_blocked_executions_on_job_id", unique: true 12 | end 13 | 14 | create_table "solid_queue_claimed_executions", force: :cascade do |t| 15 | t.bigint "job_id", null: false 16 | t.bigint "process_id" 17 | t.datetime "created_at", null: false 18 | t.index [ "job_id" ], name: "index_solid_queue_claimed_executions_on_job_id", unique: true 19 | t.index [ "process_id", "job_id" ], name: "index_solid_queue_claimed_executions_on_process_id_and_job_id" 20 | end 21 | 22 | create_table "solid_queue_failed_executions", force: :cascade do |t| 23 | t.bigint "job_id", null: false 24 | t.text "error" 25 | t.datetime "created_at", null: false 26 | t.index [ "job_id" ], name: "index_solid_queue_failed_executions_on_job_id", unique: true 27 | end 28 | 29 | create_table "solid_queue_jobs", force: :cascade do |t| 30 | t.string "queue_name", null: false 31 | t.string "class_name", null: false 32 | t.text "arguments" 33 | t.integer "priority", default: 0, null: false 34 | t.string "active_job_id" 35 | t.datetime "scheduled_at" 36 | t.datetime "finished_at" 37 | t.string "concurrency_key" 38 | t.datetime "created_at", null: false 39 | t.datetime "updated_at", null: false 40 | t.index [ "active_job_id" ], name: "index_solid_queue_jobs_on_active_job_id" 41 | t.index [ "class_name" ], name: "index_solid_queue_jobs_on_class_name" 42 | t.index [ "finished_at" ], name: "index_solid_queue_jobs_on_finished_at" 43 | t.index [ "queue_name", "finished_at" ], name: "index_solid_queue_jobs_for_filtering" 44 | t.index [ "scheduled_at", "finished_at" ], name: "index_solid_queue_jobs_for_alerting" 45 | end 46 | 47 | create_table "solid_queue_pauses", force: :cascade do |t| 48 | t.string "queue_name", null: false 49 | t.datetime "created_at", null: false 50 | t.index [ "queue_name" ], name: "index_solid_queue_pauses_on_queue_name", unique: true 51 | end 52 | 53 | create_table "solid_queue_processes", force: :cascade do |t| 54 | t.string "kind", null: false 55 | t.datetime "last_heartbeat_at", null: false 56 | t.bigint "supervisor_id" 57 | t.integer "pid", null: false 58 | t.string "hostname" 59 | t.text "metadata" 60 | t.datetime "created_at", null: false 61 | t.string "name", null: false 62 | t.index [ "last_heartbeat_at" ], name: "index_solid_queue_processes_on_last_heartbeat_at" 63 | t.index [ "name", "supervisor_id" ], name: "index_solid_queue_processes_on_name_and_supervisor_id", unique: true 64 | t.index [ "supervisor_id" ], name: "index_solid_queue_processes_on_supervisor_id" 65 | end 66 | 67 | create_table "solid_queue_ready_executions", force: :cascade do |t| 68 | t.bigint "job_id", null: false 69 | t.string "queue_name", null: false 70 | t.integer "priority", default: 0, null: false 71 | t.datetime "created_at", null: false 72 | t.index [ "job_id" ], name: "index_solid_queue_ready_executions_on_job_id", unique: true 73 | t.index [ "priority", "job_id" ], name: "index_solid_queue_poll_all" 74 | t.index [ "queue_name", "priority", "job_id" ], name: "index_solid_queue_poll_by_queue" 75 | end 76 | 77 | create_table "solid_queue_recurring_executions", force: :cascade do |t| 78 | t.bigint "job_id", null: false 79 | t.string "task_key", null: false 80 | t.datetime "run_at", null: false 81 | t.datetime "created_at", null: false 82 | t.index [ "job_id" ], name: "index_solid_queue_recurring_executions_on_job_id", unique: true 83 | t.index [ "task_key", "run_at" ], name: "index_solid_queue_recurring_executions_on_task_key_and_run_at", unique: true 84 | end 85 | 86 | create_table "solid_queue_recurring_tasks", force: :cascade do |t| 87 | t.string "key", null: false 88 | t.string "schedule", null: false 89 | t.string "command", limit: 2048 90 | t.string "class_name" 91 | t.text "arguments" 92 | t.string "queue_name" 93 | t.integer "priority", default: 0 94 | t.boolean "static", default: true, null: false 95 | t.text "description" 96 | t.datetime "created_at", null: false 97 | t.datetime "updated_at", null: false 98 | t.index [ "key" ], name: "index_solid_queue_recurring_tasks_on_key", unique: true 99 | t.index [ "static" ], name: "index_solid_queue_recurring_tasks_on_static" 100 | end 101 | 102 | create_table "solid_queue_scheduled_executions", force: :cascade do |t| 103 | t.bigint "job_id", null: false 104 | t.string "queue_name", null: false 105 | t.integer "priority", default: 0, null: false 106 | t.datetime "scheduled_at", null: false 107 | t.datetime "created_at", null: false 108 | t.index [ "job_id" ], name: "index_solid_queue_scheduled_executions_on_job_id", unique: true 109 | t.index [ "scheduled_at", "priority", "job_id" ], name: "index_solid_queue_dispatch_all" 110 | end 111 | 112 | create_table "solid_queue_semaphores", force: :cascade do |t| 113 | t.string "key", null: false 114 | t.integer "value", default: 1, null: false 115 | t.datetime "expires_at", null: false 116 | t.datetime "created_at", null: false 117 | t.datetime "updated_at", null: false 118 | t.index [ "expires_at" ], name: "index_solid_queue_semaphores_on_expires_at" 119 | t.index [ "key", "value" ], name: "index_solid_queue_semaphores_on_key_and_value" 120 | t.index [ "key" ], name: "index_solid_queue_semaphores_on_key", unique: true 121 | end 122 | 123 | add_foreign_key "solid_queue_blocked_executions", "solid_queue_jobs", column: "job_id", on_delete: :cascade 124 | add_foreign_key "solid_queue_claimed_executions", "solid_queue_jobs", column: "job_id", on_delete: :cascade 125 | add_foreign_key "solid_queue_failed_executions", "solid_queue_jobs", column: "job_id", on_delete: :cascade 126 | add_foreign_key "solid_queue_ready_executions", "solid_queue_jobs", column: "job_id", on_delete: :cascade 127 | add_foreign_key "solid_queue_recurring_executions", "solid_queue_jobs", column: "job_id", on_delete: :cascade 128 | add_foreign_key "solid_queue_scheduled_executions", "solid_queue_jobs", column: "job_id", on_delete: :cascade 129 | end 130 | -------------------------------------------------------------------------------- /public/400.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | The server cannot process the request due to a client error (400 Bad Request) 8 | 9 | 10 | 11 | 12 | 13 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 |
104 |
105 | 106 |
107 |
108 |

The server cannot process the request due to a client error. Please check the request and try again. If you’re the application owner check the logs for more information.

109 |
110 |
111 | 112 | 113 | 114 | 115 | -------------------------------------------------------------------------------- /public/406-unsupported-browser.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Your browser is not supported (406 Not Acceptable) 8 | 9 | 10 | 11 | 12 | 13 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 |
104 |
105 | 106 |
107 |
108 |

Your browser is not supported.
Please upgrade your browser to continue.

109 |
110 |
111 | 112 | 113 | 114 | 115 | -------------------------------------------------------------------------------- /lib/soundcloud.rb: -------------------------------------------------------------------------------- 1 | require "stringio" 2 | require "tempfile" 3 | require "aws-sdk-s3" 4 | require "mp3info" 5 | 6 | class Soundcloud 7 | def initialize 8 | @client_version = find_client_version 9 | @client_id = find_client_id 10 | end 11 | 12 | def resolve_short_url(url) 13 | begin 14 | response = HTTParty.get(url, follow_redirects: false) 15 | if [ 301, 302, 303, 307, 308 ].include?(response.code) && response.headers["Location"] 16 | response.headers["Location"] 17 | else 18 | url 19 | end 20 | rescue StandardError => e 21 | Rails.logger.error("Error resolving SoundCloud short URL: #{e.message}") 22 | nil 23 | end 24 | end 25 | 26 | def resolve_track(url) 27 | begin 28 | resolve = HTTParty.get("https://api-v2.soundcloud.com/resolve?url=#{url}&client_id=#{@client_id}") 29 | 30 | if resolve.code == 200 31 | JSON.parse(resolve.body) 32 | else 33 | raise "Error resolving SoundCloud track: #{resolve.code} #{resolve.headers["Content-Type"]}" 34 | end 35 | rescue StandardError => e 36 | Rails.logger.error("Error resolving SoundCloud track: #{e.message}") 37 | nil 38 | end 39 | end 40 | 41 | 42 | def resolve_audio(url) 43 | begin 44 | data = resolve_track(url) 45 | 46 | if data.nil? 47 | Rails.logger.error("Error resolving SoundCloud track: #{url}") 48 | return "fetch.fail" 49 | end 50 | 51 | if data["policy"] == "BLOCK" 52 | return "country.block" 53 | end 54 | 55 | if data["policy"] == "SNIP" 56 | return "paid.content" 57 | end 58 | 59 | stream_link = data["media"]["transcodings"].find { |t| t["preset"] == "mp3_1_0" } 60 | 61 | if stream_link.nil? 62 | return "fetch.fail.no.mp3" 63 | end 64 | 65 | stream_file = HTTParty.get("#{stream_link["url"]}?client_id=#{@client_id}&track_authorization=#{data["track_authorization"]}") 66 | 67 | if stream_file.code == 200 && stream_file.parsed_response["url"] 68 | m3u8_url = stream_file.parsed_response["url"] 69 | m3u8_request = HTTParty.get(m3u8_url) 70 | m3u8_content = m3u8_request.body 71 | 72 | segment_urls = [] 73 | m3u8_content.split("\n").each do |line| 74 | next if line.start_with?("#") || line.strip.empty? 75 | 76 | if line.start_with?("http") 77 | segment_urls << line.strip 78 | else 79 | base_url = m3u8_url.split("/")[0..-2].join("/") 80 | segment_urls << "#{base_url}/#{line.strip}" 81 | end 82 | end 83 | 84 | if segment_urls.empty? 85 | Rails.logger.error("No audio segments found in M3U8 playlist") 86 | return "fetch.fail.no.segments" 87 | end 88 | 89 | Rails.logger.info("Found #{segment_urls.length} audio segments") 90 | 91 | audio_data = [] 92 | segment_urls.each_with_index do |segment_url, index| 93 | begin 94 | Rails.logger.info("Downloading segment #{index + 1}/#{segment_urls.length}") 95 | 96 | response = HTTParty.get(segment_url, { 97 | headers: { 98 | "User-Agent" => "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36" 99 | }, 100 | timeout: 30 101 | }) 102 | 103 | if response.success? 104 | audio_data << response.body.force_encoding("BINARY") 105 | else 106 | Rails.logger.warn("Failed to download segment #{index + 1}: HTTP #{response.code}") 107 | end 108 | rescue => segment_error 109 | Rails.logger.warn("Error downloading segment #{index + 1}: #{segment_error.message}") 110 | end 111 | end 112 | 113 | if audio_data.any? 114 | audio_io = StringIO.new 115 | audio_data.each { |segment| audio_io.write(segment) } 116 | audio_io.rewind 117 | 118 | Tempfile.create([ "audio", ".mp3" ]) do |tempfile| 119 | tempfile.binmode 120 | tempfile.write(audio_io.string) 121 | tempfile.flush 122 | 123 | Mp3Info.open(tempfile.path) do |mp3| 124 | mp3.tag.title = data["title"] if data["title"] 125 | mp3.tag.artist = data.dig("user", "username") 126 | mp3.tag.album = data.dig("publisher_metadata", "album_title") 127 | mp3.tag.genre_s = data["genre"] 128 | mp3.tag.comments = data["description"] 129 | end 130 | 131 | tempfile.rewind 132 | final_mp3 = tempfile.read 133 | 134 | s3 = Aws::S3::Resource.new( 135 | endpoint: ENV.fetch("R2_ENDPOINT"), 136 | access_key_id: ENV.fetch("R2_ACCESS_KEY_ID"), 137 | secret_access_key: ENV.fetch("R2_SECRET_ACCESS_KEY"), 138 | region: ENV.fetch("R2_REGION", "auto") 139 | ) 140 | bucket = s3.bucket(ENV.fetch("R2_BUCKET")) 141 | key = "#{SecureRandom.hex(64)}.mp3" 142 | obj = bucket.object(key) 143 | obj.put(body: final_mp3, content_type: "audio/mpeg") 144 | return "https://cdn.cathop.lat/#{key}" 145 | end 146 | else 147 | Rails.logger.error("No audio segments were successfully downloaded") 148 | "fetch.fail.no.segments.downloaded" 149 | end 150 | else 151 | Rails.logger.error("Failed to get stream URL: HTTP #{stream_file.code}") 152 | "fetch.fail.no.mp3.stream" 153 | end 154 | rescue StandardError => e 155 | Rails.logger.error("Internal error in resolve_audio: #{e.message}") 156 | Rails.logger.error(e.backtrace.join("\n")) 157 | puts e.message 158 | puts e.backtrace 159 | "internal.error" 160 | end 161 | end 162 | 163 | private 164 | 165 | def find_client_version 166 | begin 167 | soundcloud = HTTParty.get("https://soundcloud.com/") 168 | version = String(soundcloud.body.match(/