Commit Graph

50 Commits

Author SHA1 Message Date
Claudio Costa
38307c0b73 [MM-27293] Remove heap pre-allocation for file uploads (#15143)
* Validate Content-Length

* Avoid pre-allocating memory for file uploads

* Add small pre-allocation to help mitigate small uploads performance
2020-08-03 08:25:47 +02:00
Arianna Vespri
2135096d88 Convert bool string comparisons to strconv.ParseBool for REST parameters (#13650)
* Convert bool string comparisons to strconv.ParseBool for REST parameters

* Log failed bool conversions

* Rename errors, changed log levels

* drop strconv.ParseBool error handling

If the query string parameter is omitted, strconv.ParseBool returns an error for the empty strings, which spams the logs. Instead, just assume the default semantics of a `false` return value if an error occurs.

* allow randomized Client4 booleans

It's hard to test api4's handling of the various boolean input values
accepted. Extend Client4 with support for overriding how it builds those
strings, and pick a random value on test startup.

* gofmt -s

Co-authored-by: mattermod <mattermod@users.noreply.github.com>
Co-authored-by: Ben Schumacher <ben.schumacher@mattermost.com>
Co-authored-by: Jesse Hallam <jesse.hallam@gmail.com>
2020-05-24 05:01:31 +08:00
Doug Lauder
6a27ed4a1d MM-22785 audit server CLI (#14144)
Add auditing to server CLI.

Also:
- simplify auditing in API layer
- reduce number of AddMeta calls
- have models serialize themselves
- more consistent field naming
2020-04-08 00:52:30 -04:00
Doug Lauder
4ac0619c90 MM-22273 New auditing system (phase 1) (#13967)
* New auditing API outputting to syslog via TLS

* New config section for specifying remote syslog server IP, port, and cert.

* Legacy audit API retained for access history feature
2020-03-12 15:50:21 -04:00
Eli Yukelzon
17523fa5d9 MM-21898 - Part 1: Generate and use an interface instead of *A… (#13840)
* Generate and use an interface instead of *App
2020-02-13 13:26:58 +01:00
Jesús Espino
a63684fcb5 Consistent license message for all the go files (#13235)
* Consistent license message for all the go files

* Fixing the last set of unconsistencies with the license headers

* Addressing PR review comments

* Fixing busy.go and busy_test.go license header
2019-11-29 12:59:40 +01:00
Miguel de la Cruz
2259b7f2a8 [MM-19948] Set version on module file and internal paths (#13186)
* [MM-19948] Set version on module file and internal paths

* Fixes after merge

* Fix i18n checker error
2019-11-28 14:39:38 +01:00
Ben Schumacher
fdcda20fe4 Cleanup dead code (#12929)
* Cleanup dead code

* Remove unneeded translation string
2019-10-28 19:12:50 +01:00
Jesús Espino
edd3cc890f MM-15480: Add server support for Range on files (#10892) 2019-05-23 16:46:28 +02:00
Daniel Schalla
3e6fed8df4 [MM-15641] Set stricter caching policy for file downloads (#10857)
* Set stricter caching policy for file downloads

* Add private directive back to caching header for file downloads
2019-05-21 17:10:39 +02:00
Joram Wilander
1a4ea94805 When gzipping file responses add header for uncompressed content length (#10836) 2019-05-14 13:42:48 -04:00
Angela Chang
1018ead619 [MM-8421] Fix tiff preview - backend (#10170) 2019-02-21 09:06:59 +01:00
Joram Wilander
2ca222033c MM-10658 Change config fields to pointers (#9033)
* MM 10658 Change config fields to pointers (#8898)

* Change fields of config structs to pointers and set defaults

MM-10658 https://github.com/mattermost/mattermost-server/issues/8841

* Fix tests that go broken during switching config structs to pointers

MM-10658 https://github.com/mattermost/mattermost-server/issues/8841

* Apply changes of current master while switching config structs to pointers

MM-10658 https://github.com/mattermost/mattermost-server/issues/8841

* Fix new config pointer uses

* Fix app tests

* Fix mail test

* remove debugging statement

* fix TestUpdateConfig

* assign config consistently

* initialize AmazonS3Region in TestS3TestConnection

* initialize fields for TestEmailTest

* fix TestCheckMandatoryS3Fields
2019-01-31 08:12:01 -05:00
Hanzei
cebfa38a64 Fix shadowed variables in api4 package (#10010) 2018-12-18 14:06:44 +01:00
Lev
fae4f60b33 MM-7633: Optimize memory utilization during file uploads (#9835)
* MM-7633: Optimize memory utilization during file uploads

Refactored the file upload code to reduce redundant buffering and stream
directly to the file store. Added tests.

Benchmark results:
```
levs-mbp:mattermost-server levb$  go test -v -run nothing -bench Upload -benchmem ./app
...
BenchmarkUploadFile/random-5Mb-gif-raw-ish_DoUploadFile-4         	      10	 122598031 ns/op	21211370 B/op	    1008 allocs/op
BenchmarkUploadFile/random-5Mb-gif-raw_UploadFileTask-4           	     100	  20211926 ns/op	 5678750 B/op	     126 allocs/op
BenchmarkUploadFile/random-5Mb-gif-UploadFiles-4                  	       2	1037051184 ns/op	81806360 B/op	 3705013 allocs/op
BenchmarkUploadFile/random-5Mb-gif-UploadFileTask-4               	       2	 933644431 ns/op	67015868 B/op	 3704410 allocs/op
BenchmarkUploadFile/random-2Mb-jpg-raw-ish_DoUploadFile-4         	     100	  13110509 ns/op	 6032614 B/op	    8052 allocs/op
BenchmarkUploadFile/random-2Mb-jpg-raw_UploadFileTask-4           	     100	  10729867 ns/op	 1738303 B/op	     125 allocs/op
BenchmarkUploadFile/random-2Mb-jpg-UploadFiles-4                  	       2	 925274912 ns/op	70326352 B/op	 3718856 allocs/op
BenchmarkUploadFile/random-2Mb-jpg-UploadFileTask-4               	       2	 995033336 ns/op	58113796 B/op	 3710943 allocs/op
BenchmarkUploadFile/zero-10Mb-raw-ish_DoUploadFile-4              	      30	  50777211 ns/op	54791929 B/op	    2714 allocs/op
BenchmarkUploadFile/zero-10Mb-raw_UploadFileTask-4                	      50	  36387339 ns/op	10503920 B/op	     126 allocs/op
BenchmarkUploadFile/zero-10Mb-UploadFiles-4                       	      30	  48657678 ns/op	54791948 B/op	    2719 allocs/op
BenchmarkUploadFile/zero-10Mb-UploadFileTask-4                    	      50	  37506467 ns/op	31492060 B/op	     131 allocs/op
...
```

https://mattermost.atlassian.net/browse/MM-7633 https://github.com/mattermost/mattermost-server/issues/7801

[Place an '[x]' (no spaces) in all applicable fields. Please remove unrelated fields.]
- [x] Added or updated unit tests (required for all new features)
- [ ] Added API documentation (required for all new APIs)
- [ ] All new/modified APIs include changes to the drivers
  *N/A*???
- [x] Includes text changes and localization file ([.../i18n/en.json](https://github.com/mattermost/mattermost-server/blob/master/i18n/en.json)) updates

Overview of changes:
- api4
    - Replaced `uploadFile` handler with `uploadFileStream` that reduces
      unnecessary buffering.
    - Added/refactored tests for the new API.
    - Refactored apitestlib/Check...Status functions.
- app
    - Added App.UploadFileTask, a more efficient refactor of UploadFile.
    - Consistently set `FileInfo.HasPreviewImage`
    - Added benchmarks for the new and prior implementations
    - Replaced passing around `*image.Image` with `image.Image` in the
      existing code.
- model
    - Added a more capable `client4.UploadFiles` API to match the new server
      API’s capabilities.
- I18n
    - Replaced `api.file.upload_file.bad_parse.app_error` with a more generic
      `api.file.upload_file.read_request.app_error`
- plugin
    - Removed type `plugin.multiPluginHookRunnerFunc` in favor of using
      `func(hooks Hooks) bool` explicitly, to help with testing
- tests
    - Added test files for testing images

Still remaining, but can be separate PRs - please let me know the preferred
course of action
    - Investigate JS client API - how does it do multipart?
    - Performance loss from old code on (small) image processing?
    - Deprecate the old functions, change other API implementations to use
      UploadFileTask

Definitely separate future PRs - should I file tickets foe these?
    - Only invoke t.readAll() if there are indeed applicable plugins to run
    - Find a way to leverage goexif buffer rather than re-reading

Suggested long-term improvements - should I file separate tickets for these?
- Actually allow uploading of large (GB-sized) files. This may require a
  change in how the file is passed to plugins.
- (Many) api4 tests should probably be subtests and share a server setup -
  will be much faster
- Performance improvements in image processing (goexif/thumbnail/preview)
  (maybe use https://mattermost.atlassian.net/browse/MM-10188 for this)

Questions:
1. I am commiting MBs of test images, are there better alternatives? I can
   probably create much less dense images that would take up considerably less
   space, even at pretty large sizes
2. I18n: Do I need to do anything special for the string change? Or just wait
   until it gets picked up and translated/updated?
3. The image dimensions are flipped in resulting FileInfo to match the actual
   orientation. Is this by design? Should add a test for it, perhaps?
4. What to do in the case of partial success? S3 but not DB, some files but not
   others? For now, just doing what the old code did, I think.
5. Make maxUploadDrainBytes configurable? Also, should this be the systemic
   behavior of all APIs with non-empty body? Otherwise dropped altogether?
   Check all other ioutil.ReadAll() from sockets. Find a way to set a total
   byte limit on request Body?

* WIP - Fixed for GetPluginsEnvironment() changes

* WIP - PR feedback

1. Refactored checkHTTPStatus to improve failure messages
2. Use `var name []type` rather than `name := ([]type)(nil)`
3. Replaced single-letter `p` with a more intention-revealing `part`
4. Added tests for full image size, `HasPreviewImage`

* WIP - rebased (c.Session->c.App.Session)

* WIP - PR feedback: eliminated use of Request.MultipartReader

Instead of hacking the request object to use r.MultipartReader now have own
functions `parseMultipartRequestHeader` and `multipartReader` eliminating the
need to hack the request object to use Request.MultipartReader limitations.

* WIP - PR feedback: UploadFileX with functional options

* WIP - PR feedback: style

* WIP - PR feedback: errors cleanup

* WIP - clarified File Upload benchmarks

* WIP - PR feedback: display the value of erroneous formname

* WIP - PR feedback: fixed handling of multiple channel_ids

* WIP - rebased from master - fixed tests

* PR Feedback

* PR feedback - moved client4.UploadFiles to _test for now
2018-12-13 22:32:07 +01:00
Christopher Speller
da265fbaf7 Moving app from singular to being created for every request (#9889)
* Moving app from singular to being created for every request.

* Automatic refactor

* Adding license header

* Feedback fixes
2018-11-28 10:56:21 -08:00
Vasily Naumkin
74c92237c0 Do not force downloading of shared public files (#9412)
I believe we don't need to force downloading of shared public files, because `writeFileResponse` method will compare its MIME type with `MEDIA_CONTENT_TYPES` and output it inline or as attachment automatically.

Usually we are share images and it is much more convenient to see them without downloading.
2018-09-21 08:22:23 -07:00
Christopher Speller
bb605a6b91 Changing comparison method. (#9383) 2018-09-10 15:19:29 +02:00
Jesús Espino
5fbec91c35 MM-9747: Small fixes for attachments import (#9225)
* MM-9747: Small fixes for attachments import

* Adding unit test RootId check in replies
2018-08-08 12:10:05 +02:00
Saturnino Abril
51dc5fa36e [MM-10621] Set createAt timestamp on file upload api call to secure upload order of files (#9170)
* set createAt timestamp on file upload api call to secure upload order of files

* fix test on plugin hooks
2018-07-28 14:27:55 +08:00
Christopher Speller
90e5e279c1 Fix file streaming to close files. (#9168) 2018-07-26 10:52:24 -07:00
Hyeseong Kim
8387d92ea2 MM-10381: Change the file downloading API to stream file (#9144)
* Change the file downloading to stream file

* Change file downloading to chunk only for preview

* Remove unnecessary else case
2018-07-24 11:23:54 -07:00
Jesús Espino
b367b1ff40 Do not close the connection abruptly on too big file uploads (#9083) 2018-07-18 10:07:00 +02:00
Jesse Hallam
dd35ad43ca MM-10370: serve subpath (#8968)
* factor out GetSubpathFromConfig

* mv web/subpath.go to utils/subpath.go

* serve up web, api and ws on /subpath if configured

* pass config to utils.RenderWeb(App)?Error

This allows the methods to extract the configured subpath and redirect
to the appropriate `/subpath/error` handler.

* ensure GetSubpathFromConfig returns trailing slashes deterministically

* fix error 404 handling

* redirect /subpath to /subpath/

This is necessary for the static handler to match, otherwise none of the
registered routes find anything. This also makes it no longer necessary
to add trailing slashes in the root router.
2018-06-21 11:31:51 -07:00
Harrison Healey
babd795d79 MM-9556 Added ability to upload files without a multipart request (#8306)
* MM-9556 Added ability to upload files without a multipart request

* MM-9556 Handled some unusual test behaviour
2018-02-20 10:41:00 -05:00
Chris
eff65aa05c ABC-132: sign error page parameters (#8197)
* sign error page parameters

* add comments
2018-02-07 12:05:46 -05:00
Chris
91bfc72a99 Reduce logging data races, fix MySQL test race condition (#7994)
* fix races

* revert unintentional change

* fix test as intended
2017-12-22 12:09:33 +00:00
Chris
eb1a00ef5f Reorganize file util functionality (#7848)
* reorganize file util functionality

* fix api test compilation

* fix rebase issue
2017-11-16 16:04:27 -05:00
Chris
10c5a927cb more global config ref cleanup (#7802) 2017-11-09 14:46:20 -06:00
Joram Wilander
cbb18479e9 PLT-7740 Update encoding of filename in file headers (#7552)
* Remove URL escaping of filename in file headers

* Add encoding for filename
2017-10-19 15:01:45 -04:00
Chris
8e19ba029f Reduce utils.Cfg references (#7650)
* app.UpdateConfig method

* test fix

* another test fix

* the config override option as-was is just error prone, remove it for now

* derp
2017-10-18 15:36:43 -07:00
Chris
dcf9e96a0b remove global refs from api/api4 (#7496) 2017-09-22 13:54:27 -04:00
Saturnino Abril
0643bf5159 generate web error when opening an invalid public file link (#7475) 2017-09-19 08:58:20 -04:00
Christopher Speller
29fca51821 Renaming repo 2017-09-06 23:11:59 -07:00
Chris
1adfd0e9be app type transition (#7167) 2017-09-06 17:12:54 -05:00
George Goldberg
63b10be020 APIv4: NewLocAppError -> NewAppError (#7328) 2017-08-31 10:03:16 -04:00
George Goldberg
50fc6e1e9e PLT-???? Prepare file upload infrastructure for Data Retention. (#7266)
* Prepare file upload infrastructure for Data Retention.

This commit prepares the file upload infrastructure for the data
retention feature that is under construction. Changes are:

* Move file management code to utils to allow access to it from jobs.

* From now on, store all file uploads in a top level folder which is the
  date of the day on which they were uploaded.

This commit is based on Harrison Healey's branch, but updated to work
with the latest master.

* Use NewAppError
2017-08-25 10:38:13 -04:00
Harrison Healey
885c7e277d PLT-7261 Fixed incorrect content type for preview and thumbnail images (#7119) 2017-08-04 09:05:16 -04:00
Harrison Healey
a20ddb4047 Fixed downloading of image files (#6934)
* Fixed downloading of image files

* Fixed captitalization

* Fixed missing import

* Rename image to media
2017-07-15 02:42:08 +08:00
Harrison Healey
4d4f2cea86 PLT-6678 Change Cache-Control to private for files (#6660) 2017-06-16 09:35:15 -07:00
Joram Wilander
49481caf6d PLT-6262 Add config setting to disable file attachments (#6301)
* Add config setting to disable file attachments

* Add unit tests

* Updating UI for no attachments (#6312)

* Update UI text on file upload System Console setting (#6313)

* Update storage_settings.jsx

* Update en.json
2017-05-04 15:45:19 -04:00
Carlos Tadeu Panato Junior
c94754e94f [PLT-6288] add way to view in the browser and not download in apiV4 (#6062)
* add way to view in the browser and not download

* add DetectContentType to get the contenttype for the file

* update per review
2017-04-20 16:34:07 +01:00
Harrison Healey
fb6f2a123c PLT-5860 Updated copyright date (#6058)
* PLT-5860 Updated copyright date in about modal

* PLT-5860 Updated copyright notice in JSX files

* PLT-5860 Updated copyright notice in go files

* Fixed misc copyright dates

* Fixed component snapshots
2017-04-12 08:27:57 -04:00
Harrison Healey
c7bdce8a66 PLT-5900 Removed automatic configuration of SiteURL (#5952)
* Revert "PLT-5765 Passed SiteURL to SendNotifications (#5705)"

This reverts commit a8e68bd890.

* Removed automatic configuration of SiteURL

* Reverted unintentional config changes

* Updated help text

* Added link to docs in Site URL warning

* Fixed merge conflict
2017-04-04 11:54:52 -04:00
Saturnino Abril
aafc63933a APIv4: GET /files/{file_id}/public (#5665) 2017-03-13 17:13:48 -04:00
Saturnino Abril
3cbe05e0f4 APIv4: GET /files/{file_id}/info (#5591) 2017-03-13 16:34:43 -04:00
Saturnino Abril
8b59a2a291 APIv4: GET /files/{file_id}/preview (#5568)
patch 1
2017-03-13 15:40:32 -04:00
Saturnino Abril
d32334cdfb Endpoint for APIv4: /files/{file_id}/link (#5607)
* APIv4: /files/{file_id}/link

* updated public link
2017-03-11 19:24:44 -03:00
Saturnino Abril
28c218db3b Implementation endpoint of APIv4: GET /files/{file_id}/thumbnail (#5553)
* APIv4: GET /files/{file_id}/thumbnail

* added delay time
2017-02-28 22:18:36 -03:00
Joram Wilander
91fe8bb2c0 Implement upload and get file endpoints for APIv4 (#5396)
* Implement POST /files endpoint for APIv4

* Implement GET /files/{file_id} endpoint for APIv4
2017-02-17 10:31:21 -05:00