mirror of
https://codeberg.org/rimu/pyfedi
synced 2025-02-02 16:21:32 -08:00
cope with uppercase letters in file extensions
This commit is contained in:
parent
45c214b844
commit
80c85761fb
6 changed files with 28 additions and 11 deletions
|
@ -85,6 +85,7 @@ class EditCommunityForm(FlaskForm):
|
|||
|
||||
class EditTopicForm(FlaskForm):
|
||||
name = StringField(_l('Name'), validators=[DataRequired()])
|
||||
add_community = SelectField(_l('Community to add'), coerce=int, validators=[Optional()])
|
||||
submit = SubmitField(_l('Save'))
|
||||
|
||||
|
||||
|
|
|
@ -195,6 +195,14 @@ def topics_for_form():
|
|||
return result
|
||||
|
||||
|
||||
def communities_for_form():
|
||||
communities = Community.query.order_by(Community.title).all()
|
||||
result = [(0, _('None'))]
|
||||
for community in communities:
|
||||
result.append((community.id, community.title))
|
||||
return result
|
||||
|
||||
|
||||
@bp.route('/community/<int:community_id>/edit', methods=['GET', 'POST'])
|
||||
@login_required
|
||||
@permission_required('administer all communities')
|
||||
|
@ -326,9 +334,13 @@ def admin_topic_add():
|
|||
def admin_topic_edit(topic_id):
|
||||
form = EditTopicForm()
|
||||
topic = Topic.query.get_or_404(topic_id)
|
||||
form.add_community.choices = communities_for_form()
|
||||
if form.validate_on_submit():
|
||||
topic.name = form.name.data
|
||||
topic.num_communities = topic.communities.count()
|
||||
topic.num_communities = topic.communities.count() + 1
|
||||
if form.add_community.data:
|
||||
community = Community.query.get(form.add_community.data)
|
||||
community.topic_id = topic.id
|
||||
db.session.commit()
|
||||
flash(_('Saved'))
|
||||
return redirect(url_for('admin.admin_topics'))
|
||||
|
|
|
@ -183,7 +183,7 @@ def save_post(form, post: Post):
|
|||
valid_extensions = {'.jpg', '.jpeg', '.png', '.gif', '.webp'}
|
||||
unused, file_extension = os.path.splitext(form.link_url.data) # do not use _ here instead of 'unused'
|
||||
# this url is a link to an image - generate a thumbnail of it
|
||||
if file_extension in valid_extensions:
|
||||
if file_extension.lower() in valid_extensions:
|
||||
file = url_to_thumbnail_file(form.link_url.data)
|
||||
if file:
|
||||
post.image = file
|
||||
|
@ -213,8 +213,7 @@ def save_post(form, post: Post):
|
|||
|
||||
# check if this is an allowed type of file
|
||||
file_ext = os.path.splitext(uploaded_file.filename)[1]
|
||||
if file_ext.lower() not in allowed_extensions or file_ext != validate_image(
|
||||
uploaded_file.stream):
|
||||
if file_ext.lower() not in allowed_extensions or file_ext.lower() != validate_image(uploaded_file.stream):
|
||||
abort(400)
|
||||
new_filename = gibberish(15)
|
||||
|
||||
|
@ -282,8 +281,7 @@ def remove_old_file(file_id):
|
|||
def save_icon_file(icon_file, directory='communities') -> File:
|
||||
# check if this is an allowed type of file
|
||||
file_ext = os.path.splitext(icon_file.filename)[1]
|
||||
if file_ext.lower() not in allowed_extensions or file_ext != validate_image(
|
||||
icon_file.stream):
|
||||
if file_ext.lower() not in allowed_extensions or file_ext.lower() != validate_image(icon_file.stream):
|
||||
abort(400)
|
||||
new_filename = gibberish(15)
|
||||
|
||||
|
@ -325,7 +323,7 @@ def save_icon_file(icon_file, directory='communities') -> File:
|
|||
def save_banner_file(banner_file, directory='communities') -> File:
|
||||
# check if this is an allowed type of file
|
||||
file_ext = os.path.splitext(banner_file.filename)[1]
|
||||
if file_ext.lower() not in allowed_extensions or file_ext != validate_image(
|
||||
if file_ext.lower() not in allowed_extensions or file_ext.lower() != validate_image(
|
||||
banner_file.stream):
|
||||
abort(400)
|
||||
new_filename = gibberish(15)
|
||||
|
|
|
@ -114,8 +114,13 @@
|
|||
{% endfor %}
|
||||
</ul>
|
||||
{% endif %}
|
||||
<p class="mt-4">
|
||||
<a class="no-underline" href="{{ rss_feed }}" rel="nofollow"><span class="fe fe-rss"></span> RSS feed</a>
|
||||
{% if not community.is_local() %}
|
||||
<p>
|
||||
<a href="{{ community.profile_id() }}">View community on original server</a>
|
||||
</p>
|
||||
{% endif %}
|
||||
<p>
|
||||
<a class="no-underline" href="{{ rss_feed }}" rel="nofollow"><span class="fe fe-rss"></span> </a><a href="{{ rss_feed }}" rel="nofollow">RSS feed</a>
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
@ -22,9 +22,9 @@
|
|||
{{ render_field(form.matrix_user_id) }}
|
||||
<small class="field_hint">e.g. @something:matrix.org. Include leading @ and use : before server</small>
|
||||
{{ render_field(form.profile_file) }}
|
||||
<small class="field_hint">Provide a square image that looks good when small.</small>
|
||||
<small class="field_hint">Provide a square image that looks good when small. <strong>Bug: file extension must be lower case</strong>, for some reason</small>
|
||||
{{ render_field(form.banner_file) }}
|
||||
<small class="field_hint">Provide a wide image - letterbox orientation.</small>
|
||||
<small class="field_hint">Provide a wide image - letterbox orientation. <strong>Bug: file extension must be lower case</strong></small>
|
||||
<hr />
|
||||
{{ render_field(form.bot) }}
|
||||
{{ render_field(form.submit) }}
|
||||
|
|
|
@ -112,6 +112,7 @@ def edit_profile(actor):
|
|||
if file:
|
||||
current_user.cover = file
|
||||
current_user.flush_cache()
|
||||
|
||||
db.session.commit()
|
||||
|
||||
flash(_('Your changes have been saved.'), 'success')
|
||||
|
|
Loading…
Add table
Reference in a new issue