Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
mastodon
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Pierre Boudes
mastodon
Commits
1899cf5f
Commit
1899cf5f
authored
7 years ago
by
Yamagishi Kazutoshi
Committed by
Eugen Rochko
7 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Detect extension for preview card (#2679)
* Detect extension for preview card * next
parent
5259319c
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
app/models/account.rb
+1
-15
1 addition, 15 deletions
app/models/account.rb
app/models/concerns/attachmentable.rb
+21
-0
21 additions, 0 deletions
app/models/concerns/attachmentable.rb
app/models/preview_card.rb
+2
-0
2 additions, 0 deletions
app/models/preview_card.rb
with
24 additions
and
15 deletions
app/models/account.rb
+
1
−
15
View file @
1899cf5f
...
...
@@ -21,7 +21,7 @@ class Account < ApplicationRecord
validates_attachment_content_type
:header
,
content_type:
IMAGE_MIME_TYPES
validates_attachment_size
:header
,
less_than:
2
.
megabytes
before_post_process
:set_file_extensions
include
Attachmentable
# Local user profile validations
validates
:display_name
,
length:
{
maximum:
30
},
if:
'local?'
...
...
@@ -363,18 +363,4 @@ class Account < ApplicationRecord
self
.
domain
=
TagManager
.
instance
.
normalize_domain
(
domain
)
end
def
set_file_extensions
unless
avatar
.
blank?
extension
=
Paperclip
::
Interpolations
.
content_type_extension
(
avatar
,
:original
)
basename
=
Paperclip
::
Interpolations
.
basename
(
avatar
,
:original
)
avatar
.
instance_write
:file_name
,
[
basename
,
extension
].
delete_if
(
&
:empty?
).
join
(
'.'
)
end
unless
header
.
blank?
extension
=
Paperclip
::
Interpolations
.
content_type_extension
(
header
,
:original
)
basename
=
Paperclip
::
Interpolations
.
basename
(
header
,
:original
)
header
.
instance_write
:file_name
,
[
basename
,
extension
].
delete_if
(
&
:empty?
).
join
(
'.'
)
end
end
end
This diff is collapsed.
Click to expand it.
app/models/concerns/attachmentable.rb
0 → 100644
+
21
−
0
View file @
1899cf5f
# frozen_string_literal: true
module
Attachmentable
extend
ActiveSupport
::
Concern
included
do
before_post_process
:set_file_extensions
end
private
def
set_file_extensions
self
.
class
.
attachment_definitions
.
each_key
do
|
attachment_name
|
attachment
=
send
(
attachment_name
)
next
if
attachment
.
blank?
extension
=
Paperclip
::
Interpolations
.
content_type_extension
(
attachment
,
:original
)
basename
=
Paperclip
::
Interpolations
.
basename
(
attachment
,
:original
)
attachment
.
instance_write
:file_name
,
[
basename
,
extension
].
delete_if
(
&
:empty?
).
join
(
'.'
)
end
end
end
This diff is collapsed.
Click to expand it.
app/models/preview_card.rb
+
2
−
0
View file @
1899cf5f
...
...
@@ -11,6 +11,8 @@ class PreviewCard < ApplicationRecord
has_attached_file
:image
,
styles:
{
original:
'120x120#'
},
convert_options:
{
all:
'-quality 80 -strip'
}
include
Attachmentable
validates
:url
,
presence:
true
validates_attachment_content_type
:image
,
content_type:
IMAGE_MIME_TYPES
validates_attachment_size
:image
,
less_than:
1
.
megabytes
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment