David Mehren
4f3ef414d4
Add E2E tests for the /media
route
...
Signed-off-by: David Mehren <git@herrmehren.de>
2020-10-24 11:50:45 +02:00
David Mehren
5030a6d814
AppModule: Remove unused imports
...
Signed-off-by: David Mehren <git@herrmehren.de>
2020-10-24 11:49:19 +02:00
David Mehren
0711dbb6ff
MediaService: Simplify saveFile
signature
...
As the `saveFile` method only really uses the files `Buffer`, this commit changes the signature so it directly gets a `Buffer` instead of a complicated `MulterFile` object. This also simplifies testing.
Signed-off-by: David Mehren <git@herrmehren.de>
2020-10-24 11:49:01 +02:00
David Mehren
9aa2a64a53
UserEntity: Fix column types for create/update dates
...
Signed-off-by: David Mehren <git@herrmehren.de>
2020-10-24 11:34:49 +02:00
David Mehren
5f13c34a07
UsersService: Improve logging in getNoteByIdOrAlias
...
Signed-off-by: David Mehren <git@herrmehren.de>
2020-10-24 11:34:16 +02:00
David Mehren
560efc71d8
Use useStaticAssets
instead of @nestjs/serve-static
...
`serve-static` does not work with `createTestingModule` and is not recommended when "just" serving a few images.
See https://github.com/nestjs/serve-static/issues/240
Signed-off-by: David Mehren <git@herrmehren.de>
2020-10-24 11:32:23 +02:00
David Mehren
e2696e647b
Merge pull request #534 from codimd/media-controller
2020-10-19 21:07:13 +02:00
David Mehren
a728866ebb
Public API: Add media deletion
...
Signed-off-by: David Mehren <git@herrmehren.de>
2020-10-17 21:55:05 +02:00
David Mehren
3686685f08
MediaController: Add DELETE /{filename}
route
...
Signed-off-by: David Mehren <git@herrmehren.de>
2020-10-17 21:54:44 +02:00
David Mehren
9e7e15a20a
MediaService: Implement delete feature
...
Signed-off-by: David Mehren <git@herrmehren.de>
2020-10-17 21:54:08 +02:00
David Mehren
db869418d4
FilesystemBackend: ESLint fixes
...
Signed-off-by: David Mehren <git@herrmehren.de>
2020-10-17 21:53:34 +02:00
David Mehren
6e6ab84391
UsersService: Wait for the DB to find a user
...
Signed-off-by: David Mehren <git@herrmehren.de>
2020-10-17 21:52:59 +02:00
David Mehren
16b5f3a5c8
Use POST /media
for file upload
...
The old `/media/upload` subpath does not follow the convention of REST APIs.
Signed-off-by: David Mehren <git@herrmehren.de>
2020-10-17 20:58:10 +02:00
David Mehren
e0f8031fab
Public API: Update /media/upload
route with supported content-types
...
Signed-off-by: David Mehren <git@herrmehren.de>
2020-10-17 20:55:48 +02:00
David Mehren
ffef4425f5
MediaService: Only allow upload of common image formats and PDFs
...
Signed-off-by: David Mehren <git@herrmehren.de>
2020-10-17 20:50:20 +02:00
David Mehren
ed142815e3
Add various missing imports and provider ovverides in unit tests
...
Signed-off-by: David Mehren <git@herrmehren.de>
2020-10-17 20:24:07 +02:00
David Mehren
4cd80a3212
MediaController: Handle errors when trying to save file
...
Signed-off-by: David Mehren <git@herrmehren.de>
2020-10-17 20:24:07 +02:00
David Mehren
8e662167dc
MediaService: Improve error handling and logging
...
Add debug logging to `saveFile` method and throw the proper errors when problems with the mime type are encountered
Signed-off-by: David Mehren <git@herrmehren.de>
2020-10-17 20:24:07 +02:00
David Mehren
7997a0955a
UsersService: Add methods to find, create and delete users
...
Signed-off-by: David Mehren <git@herrmehren.de>
2020-10-17 20:24:07 +02:00
David Mehren
ec8cf6d33e
NotesService: Throw NotInDBError
when the note wasn't found
...
Signed-off-by: David Mehren <git@herrmehren.de>
2020-10-17 20:23:28 +02:00
David Mehren
dea3c1d393
MediaController: Get parent note from HedgeDoc-Note
header
...
Signed-off-by: David Mehren <git@herrmehren.de>
2020-10-17 19:58:22 +02:00
David Mehren
3da16baeae
FilesystemBackend: Implement deleteFile
and getFileURL
.
...
We use `fs.unlink` instead of `fs.rm`, as the latter is only available in the fsPromises API since Node 14.14
Signed-off-by: David Mehren <git@herrmehren.de>
2020-10-17 19:58:22 +02:00
David Mehren
9743018591
Use serve-static
to serve uploaded files.
...
Add `@nestjs/serve-static` to serve uploaded media from the upload directory on the local filesystem.
Signed-off-by: David Mehren <git@herrmehren.de>
2020-10-17 19:58:22 +02:00
David Mehren
8e234962d6
MediaController: Use MediaService
to store media
...
Signed-off-by: David Mehren <git@herrmehren.de>
2020-10-17 19:58:22 +02:00
David Mehren
7a6c06d068
Add MediaService
...
This service is responsible for operations regarding uploaded media. It should perform save, get and delete operations with the configured backend.
The service also checks, if the mime type of the uploaded media is allowed.
Signed-off-by: David Mehren <git@herrmehren.de>
2020-10-17 19:58:22 +02:00
David Mehren
f3e093c715
Do not save file extension as a separate field.
...
It turned out that saving the file extension in a separate field is not necessary. Instead, the extension is saved in the complete filename in the `id` field.
Signed-off-by: David Mehren <git@herrmehren.de>
2020-10-17 19:58:22 +02:00
David Mehren
3689741ad9
Implement filesystem media backend
...
This backend stores uploaded media into files on the local filesystem.
This commit also adds a `BackendType` enum, which can be used to distinguish different media backends.
Signed-off-by: David Mehren <git@herrmehren.de>
2020-10-17 19:58:22 +02:00
David Mehren
9d8086bf3e
Define a MediaBackend interface
...
This interface defines the functionality that all media backends (like S3 or Azure) must implement.
Signed-off-by: David Mehren <git@herrmehren.de>
2020-10-17 19:58:22 +02:00
David Mehren
f01c7dbbe2
Add MediaUpload entity & Media module
...
Signed-off-by: David Mehren <git@herrmehren.de>
2020-10-17 19:58:22 +02:00
David Mehren
0a0732049a
DB Schema: Add MediaUpload entity
...
MediaUpload stores the uploading user, the note the media was uploaded to and backend data.
Signed-off-by: David Mehren <git@herrmehren.de>
2020-10-17 19:58:22 +02:00
David Mehren
b0b9b75e65
Public API: /media/upload returns the URL of the uploaded file
...
Signed-off-by: David Mehren <git@herrmehren.de>
2020-10-17 19:58:22 +02:00
Yannick Bungers
493bc393ee
Merge pull request #526 from jfowl/monitoring-source-version-from-package-json
...
Source version from package.json
2020-10-11 20:46:46 +02:00
Jonas Zohren
8fbca1bf79
Source version from package.json
...
Signed-off-by: Jonas Zohren <jonas.zohren@adesso.de>
2020-10-09 22:40:45 +02:00
Yannick Bungers
feb42b6d63
Merge pull request #515 from codimd/coverage-for-e2e
...
Collect coverage information for E2E tests
2020-10-05 19:42:20 +02:00
Yannick Bungers
e158982490
Merge pull request #513 from codimd/fix/log-stacktrace
...
Fix stack trace logging
2020-10-03 18:31:39 +02:00
David Mehren
98e2bf106e
Collect coverage information for E2E tests
...
As proposed in https://github.com/nestjs/nest/issues/3169#issuecomment-588287478
Signed-off-by: David Mehren <git@herrmehren.de>
2020-10-03 18:00:12 +02:00
David Mehren
6af4379a27
NestConsoleLoggerService: Propagate trace
parameter to consoleLoggerService
...
Signed-off-by: David Mehren <git@herrmehren.de>
2020-10-03 15:54:00 +02:00
David Mehren
9786f07a61
Merge pull request #507 from codimd/routes/notes/plainBody
...
Routes/notes/plain body parsing
2020-10-02 21:43:07 +02:00
Yannick Bungers
258dd1db56
Added markdownbody-decorator
...
which puts the markdown text directly to a variable in the route function.
Content-type of the http request is checked to be text/markdown because we dealing with markdown. Technically by now there can be any content which can be encoded. There could be features in the software which do not work properly if the text can't be parsed as markdown.
Signed-off-by: Yannick Bungers <git@innay.de>
2020-10-02 21:31:10 +02:00
Yannick Bungers
0dec095ed7
Merge pull request #502 from codimd/custom-logger
...
Use custom logger
2020-10-02 21:05:06 +02:00
David Mehren
b299fa553e
Merge pull request #511 from codimd/docs/dev/public_api/fix
...
Fixes types of timestamps and property name
2020-10-02 19:10:21 +02:00
Yannick Bungers
e86898ce18
Fixes types of timestamps and property name
...
Signed-off-by: Yannick Bungers <git@innay.de>
2020-10-01 13:11:47 +02:00
David Mehren
bf2532f7c3
Merge pull request #504 from codimd/routes/user/tests
2020-09-27 21:56:44 +02:00
David Mehren
d7f407da2d
Switch to using the new custom logger
...
Signed-off-by: David Mehren <git@herrmehren.de>
2020-09-27 21:48:42 +02:00
David Mehren
1a2959f6dc
Add logger module and custom logger implementation
...
ConsoleLoggerService is based on the default Nest LoggerService, but adds the ability to give context about the function that is logging something. It also removes the `[Nest]` string and the PID at the beginning of each log line.
NestConsoleLoggerService is a wrapper around ConsoleLoggerService and makes it possible to use our implementation as a default Nest LoggerService
Signed-off-by: David Mehren <git@herrmehren.de>
2020-09-27 21:43:52 +02:00
Yannick Bungers
fe66add8e0
Changed let to const to make eslint happy
...
Signed-off-by: Yannick Bungers <git@innay.de>
2020-09-26 23:47:51 +02:00
Yannick Bungers
64a064f9b6
Added await to wait for completion of note creation in tests
...
Signed-off-by: Yannick Bungers <git@innay.de>
2020-09-26 23:40:15 +02:00
Yannick Bungers
bf1081bcf6
Added tests test functions for /me routes
...
Note that they don't contain the functions from the services yet.
Signed-off-by: Yannick Bungers <git@innay.de>
2020-09-26 23:30:49 +02:00
David Mehren
d07d8fe278
Merge pull request #500 from codimd/routes/notes/services
2020-09-26 18:03:42 +02:00
David Mehren
a0740ffdf7
NotesService: Add TODO that createNote
still needs to calculate a proper patch
...
Signed-off-by: David Mehren <git@herrmehren.de>
2020-09-26 16:01:01 +02:00