mirror of
https://github.com/rickbarrette/simple-aircraft-manager-rails.git
synced 2026-11-17 15:50:36 -05:00
- Admin -> Settings: maximum upload size per file (1-1024 MB, default 50), stored in a new settings table and read on each use, so a change applies to every process at once - Enforced by attachment validation and the direct-upload endpoint; upload forms, bulk upload and Admin -> About show the current limit - .sam.zip import accepts files up to 1 GB to match Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
26 lines
1007 B
Ruby
26 lines
1007 B
Ruby
# Direct uploads (the browser sends each file straight to storage, then submits
|
|
# only its signed id). Active Storage's own endpoint lets anyone create blobs;
|
|
# this one requires a signed-in user and applies the upload rules up front.
|
|
class DirectUploadsController < ActiveStorage::DirectUploadsController
|
|
include Authentication
|
|
before_action :check_upload, only: :create
|
|
|
|
private
|
|
|
|
def blob_args
|
|
@blob_args ||= super.tap do |args|
|
|
args[:content_type] = Marcel::MimeType.for(name: args[:filename].to_s) if args[:content_type].blank?
|
|
end
|
|
end
|
|
|
|
def check_upload
|
|
error =
|
|
if !UploadValidation::ALLOWED_CONTENT_TYPES.include?(blob_args[:content_type])
|
|
"#{blob_args[:filename]} isn't an allowed file type"
|
|
elsif blob_args[:byte_size].to_i > UploadValidation.max_size
|
|
"#{blob_args[:filename]} is over the #{UploadValidation.max_size / 1.megabyte} MB upload limit"
|
|
end
|
|
render json: { error: error }, status: :unprocessable_entity if error
|
|
end
|
|
end
|