Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
funkwhale
funkwhale
Commits
ad7274ff
Verified
Commit
ad7274ff
authored
Nov 27, 2019
by
Eliot Berriot
Browse files
Fix
#976
: fix cover attachment migration under S3
parent
73e72113
Pipeline
#7861
passed with stages
in 4 minutes and 22 seconds
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
api/funkwhale_api/music/migrations/0043_album_cover_attachment.py
View file @
ad7274ff
...
...
@@ -13,17 +13,24 @@ def create_attachments(apps, schema_editor):
if
path
.
lower
().
endswith
(
'.png'
):
return
"image/png"
return
"image/jpeg"
for
album
in
Album
.
objects
.
filter
(
attachment_cover
=
None
).
exclude
(
cover
=
""
).
exclude
(
cover
=
None
):
try
:
album_attachment_mapping
[
album
]
=
Attachment
(
file
=
album
.
cover
,
size
=
album
.
cover
.
size
,
mimetype
=
get_mimetype
(
album
.
cover
.
path
),
)
except
FileNotFoundError
:
print
(
'Skipping missing cover file {}'
.
format
(
album
.
cover
.
path
))
qs
=
Album
.
objects
.
filter
(
attachment_cover
=
None
).
exclude
(
cover
=
""
).
exclude
(
cover
=
None
)
total
=
qs
.
count
()
print
(
'Creating attachments for {} album covers, this may take a while…'
.
format
(
total
))
from
django.core.files.storage
import
FileSystemStorage
for
i
,
album
in
enumerate
(
qs
):
if
isinstance
(
album
.
cover
.
storage
.
_wrapped
,
FileSystemStorage
):
try
:
size
=
album
.
cover
.
size
except
FileNotFoundError
:
# can occur when file isn't found on disk or S3
print
(
" Warning: cover file wasn't found in storage: {}"
.
format
(
e
.
__class__
))
size
=
None
album_attachment_mapping
[
album
]
=
Attachment
(
file
=
album
.
cover
,
size
=
None
,
mimetype
=
get_mimetype
(
album
.
cover
.
name
),
)
print
(
'Commiting changes…'
)
Attachment
.
objects
.
bulk_create
(
album_attachment_mapping
.
values
(),
batch_size
=
2000
)
# map each attachment to the corresponding album
# and bulk save
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment