Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

File upload support #189

Merged
merged 91 commits into from
Aug 5, 2022
Merged

File upload support #189

merged 91 commits into from
Aug 5, 2022

Conversation

dantownsend
Copy link
Member

@dantownsend dantownsend commented Jul 30, 2022

Based on #182

@sinisaos I've done a bunch of work on this.

The main changes are:

  • Added extra security based on this OWASP doc
  • It now supports all kinds of files - e.g. video as well
  • Added a media preview window, so the user can see the full sized image or video within Piccolo Admin
  • Array, Varchar, and Text columns can all be used as media columns

You can see the changes here:

Screen.Recording.2022-07-30.at.22.26.37.mp4

The biggest change from the original PR is it saves a unique identifier for the file in the database, rather than the URL. There are two reasons for this:

  • If the user decides to host their media files somewhere else, they don't have to update anything in the database.
  • It's the only way to get it working with S3. Each time someone accesses a file in S3 we need to generate a signed URL, which is only valid for a short period of time, so we can't store the URL in the database.

I think it's about 80% done. It's a massive feature, but a really cool one.

Things that need doing still:

  • Update the docs
  • I need to add your file upload button back - it looks nicer than what's there now
  • Add links on the row detail page for viewing images
  • Maybe add S3 support, so we know the API works properly with it before releasing it
  • The media is always served from /api/media-files/ at the moment. It's ignoring the media_url setting in LocalStorage. That needs some thinking about.
  • We used to have media_columns and media_storage arguments in TableConfig. I changed it slightly (now there's just media_columns, which maps a column to a MediaStorage) because I can imagine use cases where you want some columns to store files in one place, and other columns to store files in another place. Also, you might only allow images in some columns, and videos in other columns. It still needs a bit of thinking about.
  • I might move a bunch of the logic to Piccolo API, so it can also be used with PiccoloCRUD standalone.

I removed your image previews from RowListing.vue for now. I liked the way they looked, but because we're not creating thumbnails for the images, if the page is showing 100 rows, it will pull down 100 full sizes images, which would slow things down too much. Once we work out thumbnails I would like to add it back.

@dantownsend dantownsend added the enhancement New feature or request label Jul 30, 2022
@dantownsend dantownsend added this to In progress in Enhancements via automation Jul 30, 2022
@codecov-commenter
Copy link

codecov-commenter commented Jul 30, 2022

Codecov Report

Merging #189 (60ce88e) into master (26f0d07) will increase coverage by 0.17%.
The diff coverage is 96.40%.

@@            Coverage Diff             @@
##           master     #189      +/-   ##
==========================================
+ Coverage   96.06%   96.23%   +0.17%     
==========================================
  Files           5        8       +3     
  Lines         254      558     +304     
==========================================
+ Hits          244      537     +293     
- Misses         10       21      +11     
Impacted Files Coverage Δ
piccolo_admin/endpoints.py 93.90% <87.27%> (-1.67%) ⬇️
piccolo_admin/media/base.py 96.55% <96.55%> (ø)
piccolo_admin/media/s3.py 98.88% <98.88%> (ø)
piccolo_admin/media/local.py 100.00% <100.00%> (ø)

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

@dantownsend
Copy link
Member Author

dantownsend commented Aug 3, 2022

My god, this is turning into a huge PR.

Things left to do now:

  • Add @sinisaos code for viewing array items
  • Consider whether to move some of this logic to Piccolo API
  • Add support for S3 folders. At the moment, the docs suggest that each column uses its own bucket, which is a bit unrealistic.
  • In some places I use 'file_key' and in others 'file_id' - should make it consistent.

Half of the codebase used `file_id`, and half of it used `file_key`. It has now been standardised as `file_key`.
@sinisaos
Copy link
Member

sinisaos commented Aug 3, 2022

My god, this is turning into a huge PR.

That's true, but you covered all the possible combinations and obstacles (file names, file extensions, S3 upload, LocalMedia upload, deleting unused files etc. - I must stop here because list of features is really big :) ) I can only say BRAVO, because this is going to be really cool. I think with this Piccolo Admin will be the best and richest admin UI I have ever seen. The amount of built-in features is huge.

@lgtm-com
Copy link
Contributor

lgtm-com bot commented Aug 4, 2022

This pull request introduces 2 alerts when merging 9827a44 into 26f0d07 - view on LGTM.com

new alerts:

  • 1 for `__eq__` not overridden when adding attributes
  • 1 for Inconsistent equality and hashing

This makes it easier for people to override `generate_file_key` if they want to.
It was a bit overwhelming having it in the main media storage page. Most people don't have to worry about it.
Provides some visual feedback when uploading a file.
@dantownsend dantownsend marked this pull request as ready for review August 5, 2022 20:40
@dantownsend
Copy link
Member Author

@sinisaos I'm going to merge this in now. It's not 100% perfect, but the rest can be picked up in future PRs.

@dantownsend dantownsend merged commit e2b17a0 into master Aug 5, 2022
Enhancements automation moved this from In progress to Done Aug 5, 2022
@sinisaos
Copy link
Member

sinisaos commented Aug 5, 2022

@dantownsend I think this is pretty good. Well done.

@dantownsend
Copy link
Member Author

@sinisaos Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
Development

Successfully merging this pull request may close these issues.

None yet

3 participants