source stringclasses 1
value | repo stringlengths 5 63 | repo_url stringlengths 24 82 | path stringlengths 5 167 | language stringclasses 1
value | license stringclasses 5
values | stars int64 10 51.4k | ref stringclasses 23
values | size_bytes int64 200 258k | text stringlengths 137 258k |
|---|---|---|---|---|---|---|---|---|---|
github | grosser/parallel | https://github.com/grosser/parallel | lib/parallel.rb | Ruby | mit | 4,248 | master | 22,193 | # frozen_string_literal: true
require 'rbconfig'
require 'parallel/version'
require 'parallel/serializer'
module Parallel
Stop = Object.new.freeze
class DeadWorker < StandardError
end
class Break < StandardError
attr_reader :value
def initialize(value = nil)
super()
@value = value
en... |
github | grosser/parallel | https://github.com/grosser/parallel | lib/parallel/serializer.rb | Ruby | mit | 4,248 | master | 1,956 | # frozen_string_literal: true
require 'openssl'
require 'securerandom'
module Parallel
# Pluggable wire serializers. Each must respond to `dump(data, io)` /
# `load(io)` (used directly by Worker) and `dump(data)` / `load(string)`
# (used by wrappers like Hmac).
module Serializer
# Raw Marshal. Fast but tru... |
github | blackcandy-org/blackcandy | https://github.com/blackcandy-org/blackcandy | Gemfile | Ruby | mit | 4,176 | master | 3,005 | source "https://rubygems.org"
git_source(:github) { |repo| "https://github.com/#{repo}.git" }
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem "rails", "~> 8.1.0"
# Deliver assets for Rails
gem "propshaft", "~> 1.1.0"
# Install Turbo on Rails
gem "turbo-rails", "~> 2.0.0"
# Install Stimulus on Ra... |
github | blackcandy-org/blackcandy | https://github.com/blackcandy-org/blackcandy | lib/tasks/lint.rake | Ruby | mit | 4,176 | master | 572 | # frozen_string_literal: true
unless Rails.env.production?
namespace :lint do
task :js do
abort("rails lint:js failed") unless system("npx standard 'app/javascript/**/*.js'")
end
task :css do
abort("rails lint:css failed") unless system("npx stylelint 'app/assets/stylesheets/**/*.scss'")
... |
github | blackcandy-org/blackcandy | https://github.com/blackcandy-org/blackcandy | lib/puma/plugin/media_listener.rb | Ruby | mit | 4,176 | master | 305 | # frozen_string_literal: true
require "puma/plugin"
Puma::Plugin.create do
def start(launcher)
launcher.events.on_booted { MediaListener.start if Setting.enable_media_listener? }
launcher.events.on_stopped { MediaListener.stop }
launcher.events.on_restart { MediaListener.stop }
end
end |
github | blackcandy-org/blackcandy | https://github.com/blackcandy-org/blackcandy | lib/black_candy/errors.rb | Ruby | mit | 4,176 | master | 504 | # frozen_string_literal: true
module BlackCandy
CustomError = Data.define(:type, :message)
class BaseError < StandardError
def type
self.class.name.split("::").last
end
end
class Forbidden < BaseError
def message
I18n.t("error.forbidden")
end
end
class InvalidCredential < Bas... |
github | blackcandy-org/blackcandy | https://github.com/blackcandy-org/blackcandy | lib/black_candy/configurable.rb | Ruby | mit | 4,176 | master | 2,032 | # frozen_string_literal: true
module BlackCandy
module Configurable
def self.included(base)
base.class_variable_set(:@@config, Config.new)
base.extend ClassMethods
end
class Config
class ValidationError < StandardError; end
attr_accessor :validate_blocks
def initialize
... |
github | blackcandy-org/blackcandy | https://github.com/blackcandy-org/blackcandy | lib/black_candy/version.rb | Ruby | mit | 4,176 | master | 787 | # frozen_string_literal: true
module BlackCandy
module Version
MAJOR = 3
MINOR = 2
PATCH = 0
PRE = ""
class << self
def to_s
return "version: edge(#{commit_hash.first(7)})" if edge_release?
"v#{version}"
end
def link
return "https://github.com/blackcand... |
github | blackcandy-org/blackcandy | https://github.com/blackcandy-org/blackcandy | config/puma.rb | Ruby | mit | 4,176 | master | 1,842 | require_relative "../lib/puma/plugin/media_listener"
# Puma starts a configurable number of processes (workers) and each process
# serves each request in a thread from an internal thread pool.
#
# The ideal number of threads per worker depends both on how much time the
# application spends waiting for IO operations an... |
github | blackcandy-org/blackcandy | https://github.com/blackcandy-org/blackcandy | config/ci.rb | Ruby | mit | 4,176 | master | 802 | # Run using bin/ci
CI.run do
step "Setup", "bin/setup --skip-server"
step "Style: Ruby", "bin/rubocop"
step "Security: Importmap vulnerability audit", "bin/importmap audit"
step "Security: Brakeman code analysis", "bin/brakeman --quiet --no-pager --exit-on-warn --exit-on-error"
step "Tests: Rails", "bin/r... |
github | blackcandy-org/blackcandy | https://github.com/blackcandy-org/blackcandy | config/routes.rb | Ruby | mit | 4,176 | master | 3,332 | Rails.application.routes.draw do
root "home#index"
resources :sessions, only: [ :new, :create, :destroy ]
resource :setting, only: [ :show, :update ]
resource :library, only: [ :show ]
resources :artists, only: [ :index, :show, :update ]
resources :songs, only: [ :index ]
resources :albums, only: [ :ind... |
github | blackcandy-org/blackcandy | https://github.com/blackcandy-org/blackcandy | config/boot.rb | Ruby | mit | 4,176 | master | 207 | ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../Gemfile", __dir__)
require "bundler/setup" # Set up gems listed in the Gemfile.
require "bootsnap/setup" # Speed up boot time by caching expensive operations. |
github | blackcandy-org/blackcandy | https://github.com/blackcandy-org/blackcandy | config/application.rb | Ruby | mit | 4,176 | master | 2,618 | require_relative "boot"
require "rails"
# Pick the frameworks you want:
require "active_model/railtie"
require "active_job/railtie"
require "active_record/railtie"
require "active_storage/engine"
require "action_controller/railtie"
# require "action_mailer/railtie"
# require "action_mailbox/engine"
# require "action_t... |
github | blackcandy-org/blackcandy | https://github.com/blackcandy-org/blackcandy | config/initializers/content_security_policy.rb | Ruby | mit | 4,176 | master | 1,334 | # Be sure to restart your server when you modify this file.
# Define an application-wide content security policy.
# See the Securing Rails Applications Guide for more information:
# https://guides.rubyonrails.org/security.html#content-security-policy-header
# Rails.application.configure do
# config.content_security... |
github | blackcandy-org/blackcandy | https://github.com/blackcandy-org/blackcandy | config/initializers/pagy.rb | Ruby | mit | 4,176 | master | 9,717 | # frozen_string_literal: true
# Pagy initializer file (9.3.3)
# Customize only what you really need and notice that the core Pagy works also without any of the following lines.
# Should you just cherry pick part of this file, please maintain the require-order of the extras
# Pagy Variables
# See https://ddnexus.gith... |
github | blackcandy-org/blackcandy | https://github.com/blackcandy-org/blackcandy | config/initializers/filter_parameter_logging.rb | Ruby | mit | 4,176 | master | 468 | # Be sure to restart your server when you modify this file.
# Configure parameters to be partially matched (e.g. passw matches password) and filtered from the log file.
# Use this to limit dissemination of sensitive information.
# See the ActiveSupport::ParameterFilter documentation for supported notations and behavio... |
github | blackcandy-org/blackcandy | https://github.com/blackcandy-org/blackcandy | config/initializers/assets.rb | Ruby | mit | 4,176 | master | 296 | # Be sure to restart your server when you modify this file.
# Version of your assets, change this if you want to expire all your assets.
Rails.application.config.assets.version = "1.0"
# Add additional assets to the asset load path.
# Rails.application.config.assets.paths << Emoji.images_path |
github | blackcandy-org/blackcandy | https://github.com/blackcandy-org/blackcandy | config/initializers/inflections.rb | Ruby | mit | 4,176 | master | 749 | # Be sure to restart your server when you modify this file.
# Add new inflection rules using the following format. Inflections
# are locale specific, and you may define rules for as many different
# locales as you wish. All of these examples are active by default:
# ActiveSupport::Inflector.inflections(:en) do |inflec... |
github | blackcandy-org/blackcandy | https://github.com/blackcandy-org/blackcandy | config/environments/test.rb | Ruby | mit | 4,176 | master | 2,369 | # The test environment is used exclusively to run your application's
# test suite. You never need to work with it otherwise. Remember that
# your test database is "scratch space" for the test suite and is wiped
# and recreated between test runs. Don't rely on the data there!
Rails.application.configure do
# Settings... |
github | blackcandy-org/blackcandy | https://github.com/blackcandy-org/blackcandy | config/environments/development.rb | Ruby | mit | 4,176 | master | 3,129 | require "active_support/core_ext/integer/time"
Rails.application.configure do
# Settings specified here will take precedence over those in config/application.rb.
# In the development environment your application's code is reloaded any time
# it changes. This slows down response time but is perfect for developme... |
github | blackcandy-org/blackcandy | https://github.com/blackcandy-org/blackcandy | config/environments/production.rb | Ruby | mit | 4,176 | master | 4,372 | require "active_support/core_ext/integer/time"
Rails.application.configure do
# Settings specified here will take precedence over those in config/application.rb.
# Code is not reloaded between requests.
config.enable_reloading = false
# Eager load code on boot. This eager loads most of Rails and
# your app... |
github | blackcandy-org/blackcandy | https://github.com/blackcandy-org/blackcandy | app/controllers/playlists_controller.rb | Ruby | mit | 4,176 | master | 1,137 | # frozen_string_literal: true
class PlaylistsController < ApplicationController
before_action :find_playlist, only: [ :destroy, :update ]
before_action :get_sort_option, only: [ :index ]
def index
@pagy, @playlists = pagy(Current.user.playlists_with_favorite.sort_records(*sort_params))
end
def create
... |
github | blackcandy-org/blackcandy | https://github.com/blackcandy-org/blackcandy | app/controllers/songs_controller.rb | Ruby | mit | 4,176 | master | 527 | # frozen_string_literal: true
class SongsController < ApplicationController
before_action :get_sort_option, only: [ :index ]
def index
records = Song.includes(:artist, :album)
.filter_records(filter_params)
.sort_records(*sort_params)
@pagy, @songs = pagy(records)
end
private
def filt... |
github | blackcandy-org/blackcandy | https://github.com/blackcandy-org/blackcandy | app/controllers/libraries_controller.rb | Ruby | mit | 4,176 | master | 264 | # frozen_string_literal: true
class LibrariesController < ApplicationController
def show
@albums_count = Album.count
@artists_count = Artist.count
@songs_count = Song.count
@playlists_count = Current.user.playlists_with_favorite.count
end
end |
github | blackcandy-org/blackcandy | https://github.com/blackcandy-org/blackcandy | app/controllers/application_controller.rb | Ruby | mit | 4,176 | master | 3,669 | # frozen_string_literal: true
class ApplicationController < ActionController::Base
include Pagy::Backend
include SessionsHelper
helper_method :native_app?, :need_transcode?, :render_flash, :mobile?, :dialog?
before_action :find_current_session
before_action :find_current_request_details
before_action :re... |
github | blackcandy-org/blackcandy | https://github.com/blackcandy-org/blackcandy | app/controllers/albums_controller.rb | Ruby | mit | 4,176 | master | 1,054 | # frozen_string_literal: true
class AlbumsController < ApplicationController
before_action :require_admin, only: [ :update ]
before_action :find_album, except: [ :index ]
before_action :get_sort_option, only: [ :index ]
def index
records = Album.includes(:artist)
.with_attached_cover_image
.fi... |
github | blackcandy-org/blackcandy | https://github.com/blackcandy-org/blackcandy | app/controllers/home_controller.rb | Ruby | mit | 4,176 | master | 304 | # frozen_string_literal: true
class HomeController < ApplicationController
def index
@recently_added_albums = Album.includes(:artist).with_attached_cover_image.order(created_at: :desc).limit(10)
@recently_played_albums = Current.user.recently_played_albums.with_attached_cover_image
end
end |
github | blackcandy-org/blackcandy | https://github.com/blackcandy-org/blackcandy | app/controllers/sessions_controller.rb | Ruby | mit | 4,176 | master | 713 | # frozen_string_literal: true
class SessionsController < ApplicationController
layout "plain"
skip_before_action :require_login
before_action :find_session, only: [ :destroy ]
def new
redirect_to root_path if logged_in?
end
def create
session = Session.build_from_credential(session_params)
... |
github | blackcandy-org/blackcandy | https://github.com/blackcandy-org/blackcandy | app/controllers/artists_controller.rb | Ruby | mit | 4,176 | master | 1,004 | # frozen_string_literal: true
class ArtistsController < ApplicationController
before_action :require_admin, only: [ :update ]
before_action :find_artist, except: [ :index ]
before_action :get_sort_option, only: [ :index ]
def index
records = Artist.sort_records(*sort_params).with_attached_cover_image
... |
github | blackcandy-org/blackcandy | https://github.com/blackcandy-org/blackcandy | app/controllers/search_controller.rb | Ruby | mit | 4,176 | master | 1,031 | # frozen_string_literal: true
class SearchController < ApplicationController
SEARCH_RESULT_MAX_AMOUNT = 10
def index
searched_albums = Album.search(params[:query]).includes(:artist).with_attached_cover_image
searched_artists = Artist.search(params[:query]).with_attached_cover_image
searched_playlists ... |
github | blackcandy-org/blackcandy | https://github.com/blackcandy-org/blackcandy | app/controllers/media_syncing_controller.rb | Ruby | mit | 4,176 | master | 298 | # frozen_string_literal: true
class MediaSyncingController < ApplicationController
before_action :require_admin
def create
if Media.syncing?
flash[:error] = t("error.syncing_in_progress")
redirect_to setting_path
else
MediaSyncAllJob.perform_later
end
end
end |
github | blackcandy-org/blackcandy | https://github.com/blackcandy-org/blackcandy | app/controllers/errors_controller.rb | Ruby | mit | 4,176 | master | 394 | # frozen_string_literal: true
class ErrorsController < ApplicationController
layout "plain"
skip_before_action :require_login
def forbidden
render status: :forbidden
end
def not_found
render status: :not_found
end
def unprocessable_entity
render status: :unprocessable_entity
end
def ... |
github | blackcandy-org/blackcandy | https://github.com/blackcandy-org/blackcandy | app/controllers/settings_controller.rb | Ruby | mit | 4,176 | master | 482 | # frozen_string_literal: true
class SettingsController < ApplicationController
before_action :require_admin, only: [ :update ]
def show
@user = Current.user
end
def update
setting = Setting.instance
if setting.update(setting_params)
flash.now[:success] = t("notice.updated")
else
f... |
github | blackcandy-org/blackcandy | https://github.com/blackcandy-org/blackcandy | app/controllers/users_controller.rb | Ruby | mit | 4,176 | master | 1,268 | # frozen_string_literal: true
class UsersController < ApplicationController
before_action :require_admin, only: [ :index, :create, :new, :destroy ]
before_action :find_user, only: [ :edit, :update, :destroy ]
before_action :auth_user, only: [ :edit, :update ]
def index
@users = User.where.not(id: Current.... |
github | blackcandy-org/blackcandy | https://github.com/blackcandy-org/blackcandy | app/controllers/dialog/playlists_controller.rb | Ruby | mit | 4,176 | master | 351 | # frozen_string_literal: true
module Dialog
class PlaylistsController < DialogController
def index
@pagy, @playlists = pagy(Current.user.playlists_with_favorite.order(created_at: :desc))
end
def new
@playlist = Playlist.new
end
def edit
@playlist = Current.user.playlists.find(... |
github | blackcandy-org/blackcandy | https://github.com/blackcandy-org/blackcandy | app/controllers/concerns/transcoded_stream_concern.rb | Ruby | mit | 4,176 | master | 1,622 | # frozen_string_literal: true
module TranscodedStreamConcern
extend ActiveSupport::Concern
included do
before_action :find_stream
before_action :find_cache
end
# Similar to send_file in rails, but let response_body to be a stream object.
# The instance of Stream can respond to each() method. So the... |
github | blackcandy-org/blackcandy | https://github.com/blackcandy-org/blackcandy | app/controllers/concerns/stream_concern.rb | Ruby | mit | 4,176 | master | 969 | # frozen_string_literal: true
module StreamConcern
extend ActiveSupport::Concern
included do
before_action :find_stream
end
def new
send_local_file @stream.file_path
end
private
def find_stream
@stream = Stream.new(Song.find(params[:song_id]))
end
def thruster_sendfile?
Rails.con... |
github | blackcandy-org/blackcandy | https://github.com/blackcandy-org/blackcandy | app/controllers/api/v1/systems_controller.rb | Ruby | mit | 4,176 | master | 229 | # frozen_string_literal: true
module Api
module V1
class SystemsController < ApiController
skip_before_action :find_current_session
skip_before_action :require_login
def show
end
end
end
end |
github | blackcandy-org/blackcandy | https://github.com/blackcandy-org/blackcandy | app/controllers/api/v1/authentications_controller.rb | Ruby | mit | 4,176 | master | 627 | # frozen_string_literal: true
module Api
module V1
class AuthenticationsController < ApiController
skip_before_action :find_current_session, only: [ :create ]
skip_before_action :require_login, only: [ :create ]
def create
@session = Session.build_from_credential(session_params)
... |
github | blackcandy-org/blackcandy | https://github.com/blackcandy-org/blackcandy | app/controllers/api/v1/api_controller.rb | Ruby | mit | 4,176 | master | 427 | # frozen_string_literal: true
module Api
module V1
class ApiController < ApplicationController
skip_before_action :verify_authenticity_token
private
def find_current_session
authenticate_with_http_token do |token, _|
Current.session = Session.find_signed(token)
end
... |
github | blackcandy-org/blackcandy | https://github.com/blackcandy-org/blackcandy | app/controllers/api/v1/current_playlist/songs_controller.rb | Ruby | mit | 4,176 | master | 1,361 | # frozen_string_literal: true
module Api
module V1
class CurrentPlaylist::SongsController < ApiController
before_action :find_playlist
before_action :find_song, only: [ :destroy, :move ]
def index
@songs = @playlist.songs_with_favorite
end
def destroy
@playlist.son... |
github | blackcandy-org/blackcandy | https://github.com/blackcandy-org/blackcandy | app/controllers/api/v1/current_playlist/songs/playlists_controller.rb | Ruby | mit | 4,176 | master | 528 | # frozen_string_literal: true
module Api
module V1
class CurrentPlaylist::Songs::PlaylistsController < ApiController
before_action :find_current_playlist
before_action :find_playlist
def update
@current_playlist.replace(@playlist.song_ids)
end
private
def find_curre... |
github | blackcandy-org/blackcandy | https://github.com/blackcandy-org/blackcandy | app/controllers/api/v1/current_playlist/songs/albums_controller.rb | Ruby | mit | 4,176 | master | 646 | # frozen_string_literal: true
module Api
module V1
class CurrentPlaylist::Songs::AlbumsController < ApiController
before_action :find_current_playlist
before_action :find_album
after_action :add_to_recently_played, only: [ :update ]
def update
@current_playlist.replace(@album.son... |
github | blackcandy-org/blackcandy | https://github.com/blackcandy-org/blackcandy | app/controllers/api/v1/favorite_playlist/songs_controller.rb | Ruby | mit | 4,176 | master | 704 | # frozen_string_literal: true
module Api
module V1
class FavoritePlaylist::SongsController < ApiController
before_action :find_playlist
before_action :find_song, only: [ :destroy ]
def create
@song = Song.find(params[:song_id])
@playlist.playlists_songs.create(song_id: @song.id... |
github | blackcandy-org/blackcandy | https://github.com/blackcandy-org/blackcandy | app/controllers/users/settings_controller.rb | Ruby | mit | 4,176 | master | 513 | # frozen_string_literal: true
class Users::SettingsController < ApplicationController
before_action :find_user
before_action :auth_user
def update
return unless @user.update(user_setting_params)
flash.now[:success] = t("notice.updated")
end
private
def user_setting_params
params.require(:use... |
github | blackcandy-org/blackcandy | https://github.com/blackcandy-org/blackcandy | app/controllers/favorite_playlist/songs_controller.rb | Ruby | mit | 4,176 | master | 241 | # frozen_string_literal: true
class FavoritePlaylist::SongsController < Playlists::SongsController
skip_before_action :redirect_to_built_in_playlist
private
def find_playlist
@playlist = Current.user.favorite_playlist
end
end |
github | blackcandy-org/blackcandy | https://github.com/blackcandy-org/blackcandy | app/controllers/playlists/songs_controller.rb | Ruby | mit | 4,176 | master | 1,575 | # frozen_string_literal: true
class Playlists::SongsController < ApplicationController
before_action :find_playlist
before_action :find_song, only: [ :move, :destroy ]
before_action :redirect_to_built_in_playlist, only: [ :index ]
def index
@pagy, @songs = pagy(@playlist.songs.includes(:artist))
end
... |
github | blackcandy-org/blackcandy | https://github.com/blackcandy-org/blackcandy | app/controllers/current_playlist/songs_controller.rb | Ruby | mit | 4,176 | master | 1,082 | # frozen_string_literal: true
class CurrentPlaylist::SongsController < Playlists::SongsController
layout "playlist"
skip_before_action :redirect_to_built_in_playlist
def index
@songs = @playlist.songs_with_favorite
@should_play = params[:should_play] == "true"
@should_play_song_id = params[:song_id... |
github | blackcandy-org/blackcandy | https://github.com/blackcandy-org/blackcandy | app/controllers/current_playlist/songs/albums_controller.rb | Ruby | mit | 4,176 | master | 674 | # frozen_string_literal: true
class CurrentPlaylist::Songs::AlbumsController < ApplicationController
before_action :find_current_playlist
before_action :find_album
after_action :add_to_recently_played, only: [ :update ]
def update
@current_playlist.replace(@album.song_ids)
redirect_to current_playlis... |
github | blackcandy-org/blackcandy | https://github.com/blackcandy-org/blackcandy | app/controllers/current_playlist/songs/playlists_controller.rb | Ruby | mit | 4,176 | master | 571 | # frozen_string_literal: true
class CurrentPlaylist::Songs::PlaylistsController < ApplicationController
before_action :find_current_playlist
before_action :find_playlist
def update
@current_playlist.replace(@playlist.song_ids)
redirect_to current_playlist_songs_path(
should_play: params[:should_pl... |
github | blackcandy-org/blackcandy | https://github.com/blackcandy-org/blackcandy | app/models/artist.rb | Ruby | mit | 4,176 | master | 1,001 | # frozen_string_literal: true
class Artist < ApplicationRecord
UNKNOWN_NAME = "Unknown Artist"
VARIOUS_NAME = "Various Artists"
include SearchableConcern
include ImageableConcern
include SortableConcern
after_initialize :set_default_name, if: :new_record?
validates :name, presence: true
has_many :a... |
github | blackcandy-org/blackcandy | https://github.com/blackcandy-org/blackcandy | app/models/playlist.rb | Ruby | mit | 4,176 | master | 841 | # frozen_string_literal: true
class Playlist < ApplicationRecord
include SearchableConcern
include SortableConcern
validates :name, presence: true, if: :require_name?
has_many :playlists_songs
has_many :songs, -> { order "playlists_songs.position" }, through: :playlists_songs
belongs_to :user
search_b... |
github | blackcandy-org/blackcandy | https://github.com/blackcandy-org/blackcandy | app/models/current.rb | Ruby | mit | 4,176 | master | 223 | # frozen_string_literal: true
class Current < ActiveSupport::CurrentAttributes
attribute :setting
attribute :session
attribute :ip_address
attribute :user_agent
delegate :user, to: :session, allow_nil: true
end |
github | blackcandy-org/blackcandy | https://github.com/blackcandy-org/blackcandy | app/models/current_playlist.rb | Ruby | mit | 4,176 | master | 458 | # frozen_string_literal: true
class CurrentPlaylist < Playlist
def songs_with_favorite
favorite_playlist = Current.user.favorite_playlist
songs.includes(:artist, album: { cover_image_attachment: :blob })
.joins("Left JOIN playlists_songs T1 ON songs.id = T1.song_id AND T1.playlist_id = #{favorite_play... |
github | blackcandy-org/blackcandy | https://github.com/blackcandy-org/blackcandy | app/models/session.rb | Ruby | mit | 4,176 | master | 882 | class Session < ApplicationRecord
before_create :find_current_info
belongs_to :user
def self.build_from_credential(credential)
user = User.find_by(email: credential[:email])
# User authentication has been migrated from Authlogic to has_secure_password, so for backward compatibility
# we need to chec... |
github | blackcandy-org/blackcandy | https://github.com/blackcandy-org/blackcandy | app/models/user.rb | Ruby | mit | 4,176 | master | 2,465 | # frozen_string_literal: true
class User < ApplicationRecord
AVAILABLE_THEME_OPTIONS = %w[dark light auto].freeze
DEFAULT_THEME = "auto"
RECENTLY_PLAYED_LIMIT = 10
include ScopedSettingConcern
has_secure_password
has_setting :theme, default: DEFAULT_THEME
serialize :recently_played_album_ids, type: Arr... |
github | blackcandy-org/blackcandy | https://github.com/blackcandy-org/blackcandy | app/models/setting.rb | Ruby | mit | 4,176 | master | 1,581 | # frozen_string_literal: true
class Setting < ApplicationRecord
include GlobalSettingConcern
AVAILABLE_BITRATE_OPTIONS = [ 128, 192, 320 ].freeze
has_setting :media_path, default: proc { BlackCandy.config.media_path }
has_setting :discogs_token
has_setting :transcode_bitrate, type: :integer, default: 128
... |
github | blackcandy-org/blackcandy | https://github.com/blackcandy-org/blackcandy | app/models/media.rb | Ruby | mit | 4,176 | master | 2,951 | # frozen_string_literal: true
class Media
include Singleton
include Turbo::Broadcastable
extend ActiveModel::Naming
class << self
def sync(type, file_paths = [])
return if file_paths.blank?
case type
when :added
add_files(file_paths)
when :removed
remove_files(file... |
github | blackcandy-org/blackcandy | https://github.com/blackcandy-org/blackcandy | app/models/media_file.rb | Ruby | mit | 4,176 | master | 2,523 | # frozen_string_literal: true
class MediaFile
SUPPORTED_FORMATS = WahWah.support_formats.freeze
class << self
def file_paths(media_path)
return [] if media_path.blank?
absolute_media_path = File.expand_path(media_path)
# Because Ruby ignores the FNM_CASEFOLD flag in Dir.glob, case sensitiv... |
github | blackcandy-org/blackcandy | https://github.com/blackcandy-org/blackcandy | app/models/sort_option.rb | Ruby | mit | 4,176 | master | 328 | class SortOption
extend Forwardable
attr_accessor :values
def_delegators :@values, :push, :include?
def initialize
@values = []
@default = nil
end
def default
@default || SortValue.new(@values.first)
end
def set_default(value, direction)
@default = SortValue.new(value, direction)
... |
github | blackcandy-org/blackcandy | https://github.com/blackcandy-org/blackcandy | app/models/album.rb | Ruby | mit | 4,176 | master | 935 | # frozen_string_literal: true
class Album < ApplicationRecord
UNKNOWN_NAME = "Unknown Album"
include SearchableConcern
include ImageableConcern
include FilterableConcern
include SortableConcern
after_initialize :set_default_name, if: :new_record?
validates :name, presence: true
has_many :songs, -> ... |
github | blackcandy-org/blackcandy | https://github.com/blackcandy-org/blackcandy | app/models/song.rb | Ruby | mit | 4,176 | master | 957 | # frozen_string_literal: true
class Song < ApplicationRecord
include SearchableConcern
include FilterableConcern
include SortableConcern
validates :name, :file_path, :file_path_hash, :md5_hash, presence: true
belongs_to :album, touch: true
belongs_to :artist, touch: true
has_many :playlists_songs
has... |
github | blackcandy-org/blackcandy | https://github.com/blackcandy-org/blackcandy | app/models/stream.rb | Ruby | mit | 4,176 | master | 1,231 | # frozen_string_literal: true
class Stream
extend Forwardable
WEB_SUPPORTED_FORMATS = MediaFile::SUPPORTED_FORMATS - %w[wma]
SAFARI_SUPPORTED_FORMATS = MediaFile::SUPPORTED_FORMATS - %w[ogg opus oga]
IOS_SUPPORTED_FORMATS = SAFARI_SUPPORTED_FORMATS
ANDROID_SUPPORTED_FORMATS = WEB_SUPPORTED_FORMATS
TRANSC... |
github | blackcandy-org/blackcandy | https://github.com/blackcandy-org/blackcandy | app/models/media_listener.rb | Ruby | mit | 4,176 | master | 1,017 | # frozen_string_literal: true
class MediaListener
include Singleton
include BlackCandy::Configurable
SERVICE_PATH = File.join(Rails.root, "lib", "daemons", "media_listener_service")
has_config :service_name, default: "media_listener_service", env_prefix: "media_listener"
has_config :pid_dir, default: File.... |
github | blackcandy-org/blackcandy | https://github.com/blackcandy-org/blackcandy | app/models/integrations/service.rb | Ruby | mit | 4,176 | master | 868 | # frozen_string_literal: true
require "open-uri"
class Integrations::Service
include HTTParty
def request(path, options = {}, method = :get)
response = self.class.send(method, path, options)
raise TooManyRequests if response.code.to_i == 429
parse_json(response)
end
def download_image(url)
... |
github | blackcandy-org/blackcandy | https://github.com/blackcandy-org/blackcandy | app/models/integrations/discogs.rb | Ruby | mit | 4,176 | master | 952 | # frozen_string_literal: true
class Integrations::Discogs < Integrations::Service
base_uri "https://api.discogs.com"
def initialize(token = Setting.discogs_token)
self.class.headers "Authorization" => "Discogs token=#{token}"
end
def cover_image(object)
case object
when Artist
artist_cover_... |
github | blackcandy-org/blackcandy | https://github.com/blackcandy-org/blackcandy | app/models/concerns/scoped_setting_concern.rb | Ruby | mit | 4,176 | master | 727 | # frozen_string_literal: true
module ScopedSettingConcern
extend ActiveSupport::Concern
included do
const_set(:AVAILABLE_SETTINGS, [])
end
class_methods do
def has_setting(setting, type: :string, default: nil)
self::AVAILABLE_SETTINGS.push(setting)
store :settings, accessors: setting
... |
github | blackcandy-org/blackcandy | https://github.com/blackcandy-org/blackcandy | app/models/concerns/searchable_concern.rb | Ruby | mit | 4,176 | master | 841 | # frozen_string_literal: true
module SearchableConcern
extend ActiveSupport::Concern
class_methods do
def search_by(attr, options = {})
associations = Hash(options[:associations])
associations_attrs = associations.map { |name, attr| "#{name}_#{attr}" }
predicate = [ attr ].push(*associations... |
github | blackcandy-org/blackcandy | https://github.com/blackcandy-org/blackcandy | app/models/concerns/filterable_concern.rb | Ruby | mit | 4,176 | master | 1,110 | # frozen_string_literal: true
module FilterableConcern
extend ActiveSupport::Concern
included do
const_set(:VALID_FILTERS, [])
end
class_methods do
def filter_by(*attributes)
attributes.each do |attr|
scope "filter_by_#{attr}", ->(value) { where(attr => value) }
self::VALID_FILT... |
github | blackcandy-org/blackcandy | https://github.com/blackcandy-org/blackcandy | app/models/concerns/sortable_concern.rb | Ruby | mit | 4,176 | master | 1,288 | # frozen_string_literal: true
module SortableConcern
extend ActiveSupport::Concern
included do
const_set(:SORT_OPTION, SortOption.new)
end
class_methods do
def sort_by(*attributes)
attributes.each do |attr|
scope "sort_by_#{attr}", ->(direction) { order(attr => direction) }
self... |
github | blackcandy-org/blackcandy | https://github.com/blackcandy-org/blackcandy | app/models/concerns/imageable_concern.rb | Ruby | mit | 4,176 | master | 734 | module ImageableConcern
extend ActiveSupport::Concern
ALLOWED_IMAGE_CONTENT_TYPES = %w[image/jpeg image/png].freeze
included do
has_one_attached :cover_image do |attachable|
attachable.variant :small, resize_to_fill: [ 200, 200 ]
attachable.variant :medium, resize_to_fill: [ 400, 400 ], preproce... |
github | blackcandy-org/blackcandy | https://github.com/blackcandy-org/blackcandy | app/models/concerns/global_setting_concern.rb | Ruby | mit | 4,176 | master | 1,196 | # frozen_string_literal: true
module GlobalSettingConcern
extend ActiveSupport::Concern
included do
# Ensures only one Settings row is created
validates :singleton_guard, inclusion: { in: [ 0 ] }
const_set(:AVAILABLE_SETTINGS, [])
end
class_methods do
delegate :update, to: :instance
def ... |
github | blackcandy-org/blackcandy | https://github.com/blackcandy-org/blackcandy | app/helpers/sessions_helper.rb | Ruby | mit | 4,176 | master | 426 | # frozen_string_literal: true
module SessionsHelper
def logged_in?
Current.session.present?
end
def is_admin?
Current.user.is_admin
end
def login(session)
cookies.signed[:session_id] = { value: session.id, expires: 1.year.from_now, httponly: true, secure: BlackCandy.config.force_ssl? }
end
... |
github | blackcandy-org/blackcandy | https://github.com/blackcandy-org/blackcandy | app/helpers/song_helper.rb | Ruby | mit | 4,176 | master | 1,052 | # frozen_string_literal: true
module SongHelper
def song_json_builder(song, for_api: false)
stream_url = for_api ? new_api_v1_stream_url(song_id: song.id) : new_stream_url(song_id: song.id)
transcoded_stream_url = for_api ? new_api_v1_transcoded_stream_url(song_id: song.id) : new_transcoded_stream_url(song_i... |
github | blackcandy-org/blackcandy | https://github.com/blackcandy-org/blackcandy | app/helpers/application_helper.rb | Ruby | mit | 4,176 | master | 2,625 | # frozen_string_literal: true
module ApplicationHelper
include Pagy::Frontend
def avatar_tag(user)
hash = Digest::MD5.hexdigest(user.email)
image_tag "https://www.gravatar.com/avatar/#{hash}", class: "c-avatar"
end
def icon_tag(name, options = {})
return if name.blank?
size = options.delete(... |
github | blackcandy-org/blackcandy | https://github.com/blackcandy-org/blackcandy | app/presenters/filter_sort_presenter.rb | Ruby | mit | 4,176 | master | 636 | # frozen_string_literal: true
class FilterSortPresenter
def initialize(params)
@params = params
end
def has_filter?
params[:filter].present?
end
def filter_value(key)
params[:filter].fetch(key, nil)
end
def sort_value
params[:sort]
end
def sort_direction_value
params[:sort_dir... |
github | blackcandy-org/blackcandy | https://github.com/blackcandy-org/blackcandy | app/jobs/attach_cover_image_from_discogs_job.rb | Ruby | mit | 4,176 | master | 488 | # frozen_string_literal: true
require "open-uri"
class AttachCoverImageFromDiscogsJob < ApplicationJob
retry_on Integrations::Service::TooManyRequests, wait: 1.minute, attempts: :unlimited
queue_as :default
def perform(imageable)
return if imageable.has_cover_image?
discogs_client = Integrations::Disco... |
github | blackcandy-org/blackcandy | https://github.com/blackcandy-org/blackcandy | app/jobs/media_sync_all_job.rb | Ruby | mit | 4,176 | master | 846 | # frozen_string_literal: true
class MediaSyncAllJob < MediaSyncJob
def perform(dir = Setting.media_path)
file_paths = MediaFile.file_paths(dir)
file_md5_hashes = Parallel.map(file_paths, in_processes: self.class.parallel_processor_count) do |file_path|
MediaFile.get_md5_hash(file_path, with_mtime: true... |
github | blackcandy-org/blackcandy | https://github.com/blackcandy-org/blackcandy | app/jobs/media_sync_job.rb | Ruby | mit | 4,176 | master | 1,313 | # frozen_string_literal: true
class MediaSyncJob < ApplicationJob
include BlackCandy::Configurable
has_config :parallel_processor_count, default: Parallel.processor_count, env_prefix: "media_sync"
queue_as :critical
# Limits the concurrency to 1 to prevent inconsistent media syncing data.
limits_concurren... |
github | blackcandy-org/blackcandy | https://github.com/blackcandy-org/blackcandy | db/cache_schema.rb | Ruby | mit | 4,176 | master | 1,323 | # This file is auto-generated from the current state of the database. Instead
# of editing this file, please use the migrations feature of Active Record to
# incrementally modify your database, and then regenerate this schema definition.
#
# This file is the source Rails uses to define your schema when running `bin/rai... |
github | blackcandy-org/blackcandy | https://github.com/blackcandy-org/blackcandy | db/schema.rb | Ruby | mit | 4,176 | master | 5,095 | # This file is auto-generated from the current state of the database. Instead
# of editing this file, please use the migrations feature of Active Record to
# incrementally modify your database, and then regenerate this schema definition.
#
# This file is the source Rails uses to define your schema when running `bin/rai... |
github | blackcandy-org/blackcandy | https://github.com/blackcandy-org/blackcandy | db/cable_schema.rb | Ruby | mit | 4,176 | master | 1,255 | # This file is auto-generated from the current state of the database. Instead
# of editing this file, please use the migrations feature of Active Record to
# incrementally modify your database, and then regenerate this schema definition.
#
# This file is the source Rails uses to define your schema when running `bin/rai... |
github | blackcandy-org/blackcandy | https://github.com/blackcandy-org/blackcandy | db/queue_schema.rb | Ruby | mit | 4,176 | master | 6,224 | ActiveRecord::Schema[7.1].define(version: 1) do
create_table "solid_queue_blocked_executions", force: :cascade do |t|
t.bigint "job_id", null: false
t.string "queue_name", null: false
t.integer "priority", default: 0, null: false
t.string "concurrency_key", null: false
t.datetime "expires_at", nul... |
github | blackcandy-org/blackcandy | https://github.com/blackcandy-org/blackcandy | db/seeds.rb | Ruby | mit | 4,176 | master | 444 | # This file should contain all the record creation needed to seed the database with its default values.
# The data can then be loaded with the rails db:seed command (or created alongside the database with db:setup).
#
# Examples:
#
# movies = Movie.create([{ name: 'Star Wars' }, { name: 'Lord of the Rings' }])
# Ch... |
github | blackcandy-org/blackcandy | https://github.com/blackcandy-org/blackcandy | db/migrate/20240202024632_add_key_hash_and_byte_size_indexes_and_null_constraints_to_solid_cache_entries.solid_cache.rb | Ruby | mit | 4,176 | master | 437 | # This migration comes from solid_cache (originally 20240110111600)
class AddKeyHashAndByteSizeIndexesAndNullConstraintsToSolidCacheEntries < ActiveRecord::Migration[7.1]
def change
change_table :solid_cache_entries, bulk: true do |t|
t.change_null :key_hash, false
t.change_null :byte_size, false
... |
github | blackcandy-org/blackcandy | https://github.com/blackcandy-org/blackcandy | db/migrate/20240115051630_create_solid_queue_tables.solid_queue.rb | Ruby | mit | 4,176 | master | 3,778 | # This migration comes from solid_queue (originally 20231211200639)
class CreateSolidQueueTables < ActiveRecord::Migration[7.0]
def change
create_table :solid_queue_jobs do |t|
t.string :queue_name, null: false
t.string :class_name, null: false, index: true
t.text :arguments
t.integer :pri... |
github | blackcandy-org/blackcandy | https://github.com/blackcandy-org/blackcandy | db/migrate/20241016135211_drop_solid_cache_entries_table.rb | Ruby | mit | 4,176 | master | 654 | class DropSolidCacheEntriesTable < ActiveRecord::Migration[7.2]
def change
drop_table :solid_cache_entries do |t|
t.binary "key", limit: 1024, null: false
t.binary "value", limit: 536870912, null: false
t.datetime "created_at", null: false
t.integer "key_hash", limit: 8, null: false
... |
github | blackcandy-org/blackcandy | https://github.com/blackcandy-org/blackcandy | db/migrate/20240103072942_add_default_name_to_unknown_albums.rb | Ruby | mit | 4,176 | master | 242 | class AddDefaultNameToUnknownAlbums < ActiveRecord::Migration[7.1]
def up
Album.where(name: [ nil, "" ]).update_all(name: Album::UNKNOWN_NAME)
end
def down
Album.where(name: Album::UNKNOWN_NAME).update_all(name: nil)
end
end |
github | blackcandy-org/blackcandy | https://github.com/blackcandy-org/blackcandy | db/migrate/20240103085953_add_default_name_to_artists.rb | Ruby | mit | 4,176 | master | 340 | class AddDefaultNameToArtists < ActiveRecord::Migration[7.1]
def up
Artist.where(is_various: true).update_all(name: Artist::VARIOUS_NAME)
Artist.where(name: [ nil, "" ]).update_all(name: Artist::UNKNOWN_NAME)
end
def down
Artist.where(name: [ Artist::UNKNOWN_NAME, Artist::VARIOUS_NAME ]).update_all(n... |
github | blackcandy-org/blackcandy | https://github.com/blackcandy-org/blackcandy | db/migrate/20201208090137_add_position_playlists_songs.rb | Ruby | mit | 4,176 | master | 757 | class AddPositionPlaylistsSongs < ActiveRecord::Migration[6.0]
def up
add_column :playlists_songs, :id, :primary_key
add_column :playlists_songs, :position, :integer
execute <<-SQL
UPDATE playlists_songs
SET position = mapping.new_position
FROM (
SELECT
id,
R... |
github | blackcandy-org/blackcandy | https://github.com/blackcandy-org/blackcandy | db/migrate/20220705083238_add_file_path_hash_to_songs.rb | Ruby | mit | 4,176 | master | 391 | class AddFilePathHashToSongs < ActiveRecord::Migration[7.0]
def change
add_column :songs, :file_path_hash, :string
add_index :songs, :file_path_hash
add_index :songs, :md5_hash
reversible do |dir|
dir.up do
Song.find_each do |song|
song.update_column(:file_path_hash, MediaFile... |
github | blackcandy-org/blackcandy | https://github.com/blackcandy-org/blackcandy | db/migrate/20200915090637_use_hstore_for_settings.rb | Ruby | mit | 4,176 | master | 2,417 | class UseHstoreForSettings < ActiveRecord::Migration[6.0]
def up
enable_extension "hstore" if adapter_name.downcase == "postgresql" && !extension_enabled?("hstore")
add_column :settings, :values, :hstore
add_column :settings, :singleton_guard, :integer
add_column :users, :settings, :hstore
add_ind... |
github | blackcandy-org/blackcandy | https://github.com/blackcandy-org/blackcandy | db/migrate/20221115062920_change_array_value_to_text.rb | Ruby | mit | 4,176 | master | 297 | class ChangeArrayValueToText < ActiveRecord::Migration[7.0]
def up
change_column :users, :recently_played_album_ids, :text
User.update_all(recently_played_album_ids: [])
end
def down
change_column :users, :recently_played_album_ids, :integer, array: true, default: []
end
end |
github | blackcandy-org/blackcandy | https://github.com/blackcandy-org/blackcandy | db/migrate/20210607030347_add_authlogic_to_user.rb | Ruby | mit | 4,176 | master | 294 | class AddAuthlogicToUser < ActiveRecord::Migration[6.1]
def change
rename_column :users, :password_digest, :crypted_password
add_column :users, :password_salt, :string
add_column :users, :persistence_token, :string
add_index :users, :persistence_token, unique: true
end
end |
github | blackcandy-org/blackcandy | https://github.com/blackcandy-org/blackcandy | db/migrate/20231101052018_create_sessions.rb | Ruby | mit | 4,176 | master | 229 | class CreateSessions < ActiveRecord::Migration[7.1]
def change
create_table :sessions do |t|
t.references :user, null: false
t.string :user_agent
t.string :ip_address
t.timestamps
end
end
end |
github | blackcandy-org/blackcandy | https://github.com/blackcandy-org/blackcandy | db/migrate/20240206051609_add_unique_index_on_song_md5_hash.rb | Ruby | mit | 4,176 | master | 356 | class AddUniqueIndexOnSongMd5Hash < ActiveRecord::Migration[7.1]
def up
# Remove duplicate songs
Song.where.not(id: Song.group(:md5_hash).select("min(id)")).destroy_all
remove_index :songs, :md5_hash
add_index :songs, :md5_hash, unique: true
end
def down
remove_index :songs, :md5_hash
ad... |
github | blackcandy-org/blackcandy | https://github.com/blackcandy-org/blackcandy | db/migrate/20200424065813_init_tables.rb | Ruby | mit | 4,176 | master | 1,416 | class InitTables < ActiveRecord::Migration[6.0]
def change
create_table :users do |t|
t.string :email, null: false
t.string :password_digest, null: false
t.boolean :is_admin, default: false
t.timestamps
t.index :email, unique: true
end
create_table :albums do |t|
t.str... |
github | blackcandy-org/blackcandy | https://github.com/blackcandy-org/blackcandy | db/migrate/20240202024631_add_key_hash_and_byte_size_to_solid_cache_entries.solid_cache.rb | Ruby | mit | 4,176 | master | 337 | # This migration comes from solid_cache (originally 20240108155507)
class AddKeyHashAndByteSizeToSolidCacheEntries < ActiveRecord::Migration[7.1]
def change
change_table :solid_cache_entries do |t|
t.column :key_hash, :integer, null: true, limit: 8
t.column :byte_size, :integer, null: true, limit: 4
... |
github | blackcandy-org/blackcandy | https://github.com/blackcandy-org/blackcandy | db/migrate/20240202024633_remove_key_index_from_solid_cache_entries.solid_cache.rb | Ruby | mit | 4,176 | master | 257 | # This migration comes from solid_cache (originally 20240110111702)
class RemoveKeyIndexFromSolidCacheEntries < ActiveRecord::Migration[7.1]
def change
change_table :solid_cache_entries do |t|
t.remove_index :key, unique: true
end
end
end |
github | blackcandy-org/blackcandy | https://github.com/blackcandy-org/blackcandy | db/migrate/20240115122443_migrate_images_from_artists.rb | Ruby | mit | 4,176 | master | 615 | class MigrateImagesFromArtists < ActiveRecord::Migration[7.1]
def up
Artist.where.not(image: nil).find_each do |artist|
image_path = Rails.root.join("public", "uploads", "artist", "image", artist.id.to_s, artist.image)
image_format = File.extname(image_path).downcase.delete(".")
next unless Fil... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.