Commit Graph

114 Commits

Author SHA1 Message Date
Helmut K. C. Tessarek 4774de6652
refactor(server): use more specific HTTP status codes (#262)
* refactor(server): use more specific http status codes

* fix: clippy error - oops missed that one

* test(fixtures): add check for status code
2024-03-11 14:00:45 +01:00
Helmut K. C. Tessarek 4987cfe5e5
fix(upload): error on upload with the same filename (#258) 2024-03-08 14:47:13 +01:00
Helmut K. C. Tessarek fa5105deab
test(upload): update the hash of the example file (#254)
changed at source
2024-03-06 05:57:59 +01:00
Jake Howard dae00c42b5
feat(server): do path joins more safely (#247)
* Do path joins more safely

* Improve path cleaning and tests

* Lower-case error message

Co-authored-by: Orhun Parmaksız <orhunparmaksiz@gmail.com>

* Correct handle potential errors in `get_path`

* Use `expect` in tests, rather than `unwrap`

* Correctly handle invalid upload path without panic

* Correctly handle filesystem create errors

* Use result rather than option to allow easier error handling

---------

Co-authored-by: Orhun Parmaksız <orhunparmaksiz@gmail.com>
2024-03-06 05:55:59 +01:00
Orhun Parmaksız 12f0e8f3a7
chore(server): gracefully exit when there is no config file found 2024-03-01 22:17:17 +03:00
Helmut K. C. Tessarek db971e6434
feat(server): allow to override filename when using random_url (#233)
* feat(server): allow to override filename when using random_url

* docs(README): remove line from features

* refactor(header): make const private
2024-02-12 13:06:12 +01:00
Helmut K. C. Tessarek 8e6393c6f4
fix(server): return the correct file on multiple files with same name (#234)
* fix(server): file not found, even though on server and not expired

* test: rename test
2024-02-09 21:38:33 +01:00
Helmut K. C. Tessarek 48a3626c7d
fix(server): improve logging for deleted file (#235) 2024-01-31 21:25:04 +01:00
Orhun Parmaksız 274bbd3307
fix(lints): apply clippy suggestions 2023-12-31 14:06:46 +03:00
Helmut K. C. Tessarek ec9b55f3e2
fix(auth): remove excessive warning and typo (#210) 2023-12-20 18:47:51 +01:00
Artem Medvedev e21f99ac4a
refactor(server)!: cleanup authorization boilerplate (#199)
* refactor!: use `actix-web-grants` to protect endpoints

* fix: filter out blank strings

* doc: add documentation for a function

* fix: don't return body for not exposed endpoints

* test: add fixtures

* test: fix naming

* test: remove extra step in teardown
2023-12-12 19:21:29 +01:00
Orhun Parmaksız d4b02eca91
fix(shuttle): fix Shuttle entrypoint 2023-12-05 15:22:10 +03:00
Orhun Parmaksız ef08b9e838
refactor(tracing): use macros from tracing crate 2023-12-05 15:12:48 +03:00
dependabot[bot] a291307bec
chore(deps): bump byte-unit from 4.0.19 to 5.0.3 (#192)
* chore(deps): bump byte-unit from 4.0.19 to 5.0.3

Bumps [byte-unit](https://github.com/magiclen/byte-unit) from 4.0.19 to 5.0.3.
- [Commits](https://github.com/magiclen/byte-unit/compare/v4.0.19...v5.0.3)

---
updated-dependencies:
- dependency-name: byte-unit
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>

* fix(deps): update codebase accordingly to the new version of byte-unit

* fix(fixtures): use more precise byte comparison

---------

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Orhun Parmaksız <orhunparmaksiz@gmail.com>
2023-12-05 13:08:22 +01:00
Orhun Parmaksız eee3355107
fix(lib): fix typos 2023-11-02 23:58:46 +01:00
Jean SIMARD 70541bb842
feat(log): switch to `tracing` for logging (#163)
* feat(log): use 'tracing-subscriber' instead of 'env_logger'

resolves #161

* feat: use 'tracing' instead of 'log'

* feat: make 'INFO' the default log level
2023-10-20 23:30:16 +02:00
Orhun Parmaksız c60b548cc7
fix(lints): apply clippy suggestions 2023-10-07 14:40:05 +03:00
Orhun Parmaksız 86759450b9
chore(deps): bump shuttle dependencies to 0.27.0 2023-09-22 15:01:20 +03:00
Helmut K. C. Tessarek cc9633cc95
refactor(server): change response to 'file deleted' (#137) 2023-09-04 11:09:29 +02:00
Andy Baird 27e3be5a2d
feat(server): add delete endpoint (#136)
* Delete endpoint implementation with delete_tokens configuration

* style(server): remove empty line, add dot at end of doc comment

* test(fixtures): add fixture test for file delete

* refactor(config): add delete_tokens to config.toml

* docs(readme): add info on how to delete file from server

* Update README.md

Co-authored-by: Orhun Parmaksız <orhunparmaksiz@gmail.com>

* Update README.md

Co-authored-by: Orhun Parmaksız <orhunparmaksiz@gmail.com>

* refactor(server): use log::error! and return 500

Co-authored-by: Helmut K. C. Tessarek <tessarek@evermeet.cx>

* test(server): add test_delete_file_without_token_in_config

* refactor(server): use one function to retrieve auth/delete tokens

Co-authored-by: Helmut K. C. Tessarek <tessarek@evermeet.cx>

* test(config): add test_get_tokens

* test(config): improve test_get_tokens

* feat(config): disallow empty tokens

* feat(server): update the messages for delete endpoint

---------

Co-authored-by: Helmut K. C. Tessarek <tessarek@evermeet.cx>
Co-authored-by: Orhun Parmaksız <orhunparmaksiz@gmail.com>
2023-09-03 17:47:52 +02:00
Ömer Üstün 95379c9f66
feat(server): support handling spaces in filenames (#107)
* feat(server): add url encoding

- Introduced an option to enable encoding for filenames in the returned URL.
- Modified the encoding approach to specifically target whitespaces, replacing them with `%20`.
- Included unit tests to validate this encoding approach.
- Added fixture tests for broader functional verification.
- Removed the `urlencoding` dependency from `Cargo.toml`.

* Refactor code and fixtures for better compliance and consistency

- Fixed errors in the fixture configuration to ensure tests run as expected.
- Reformatted line endings for consistency across the codebase.
- Made necessary adjustments to adhere to Clippy's recommendations.

* Enhance whitespace handling options for filenames

- Implemented a configuration choice for space handling in filenames: encode, replace with underscores or none.
- Added corresponding unit and fixture tests.

* Remove redundant function call

Fixed misplaced line as per @tessus's review feedback, preventing duplicate handling of spaces in filenames.

* Delete test file with spaces.txt

* Refactor filename space handling

- Introduced `SpaceHandling` enum to manage filename spaces.
- Updated server.rs and paste.rs to utilize the new method.
- Added unit tests for the new filename handling method.
- Adjusted fixture tests to reflect these changes.

* Move filename processing into `SpaceHandling` enum

- Relocated filename processing logic to reside within the `SpaceHandling` enum, enhancing encapsulation.
- Updated calls in `server.rs` and `paste.rs` to use the new method structure.
- Adjusted unit tests to align with the refactored function location and call pattern.

* Refactor based on review suggestions

- Incorporated the inline suggestions made by @tessus, removing the unnecessary one-line assignments.
- Ensured the code adheres to Rust guidelines by running clippy and fmt.

* chore(deps): revert changes in Cargo.lock

* chore(config): replace spaces as default

* refactor(config): move SpaceHandling to config module

---------

Co-authored-by: Orhun Parmaksız <orhunparmaksiz@gmail.com>
2023-08-26 14:35:13 +02:00
Helmut K. C. Tessarek d2d07ad345
feat(server): improve random_url config handling (#122)
* feat(server): improve random_url config handling

* log deprecation warnings after hot reload of config

* refactor(config): adjust config files

* tests(config): add test for deprecation codepath

* remove unnecessary to_string()

* style: delete empty line

* refactor(server): clean up random_url config handling

* refactor(config): update configs accordingly to deprecated random_url.enabled

---------

Co-authored-by: Orhun Parmaksız <orhunparmaksiz@gmail.com>
2023-08-20 20:32:41 +02:00
Helmut K. C. Tessarek 9145c46e18
fix(server): don't log invalid token in release builds (#112)
* fix(server): don't log invalid token in release builds

* refactor(auth): use inline formatting for auth logs

---------

Co-authored-by: Orhun Parmaksız <orhunparmaksiz@gmail.com>
2023-08-14 14:05:34 +02:00
Helmut K. C. Tessarek 17ed34fc12
fix(server): do not list expired files (#109)
* fix(server): do not list expired files

* refactor(server): simplify list files function

* add test case

---------

Co-authored-by: Orhun Parmaksız <orhunparmaksiz@gmail.com>
2023-08-11 14:23:07 +02:00
Andy Baird d0a67751dc
feat(server): add an endpoint for retrieving a list of files (#94)
* Start

* Wip

* Implement path based JSON index

* Remove json_index_path

* Return datetime stamp instead of relative time

* Add file size to list item

* Add auth check when retrieving JSON index

* Make json index path hardcoded

* Test (currently failing)

* Fix test for test_json_list

* Clippy fix

* Revert cargo to original versions with only needed changes

* Add detail about auth guard affecting list route

* Change json_index_path to expose_list

* Remove unneeded linebreak

* Remove unnecessary import

* Remove unnecessary space at end of line

* Move config check after auth check

* Use new auth check syntax, add docs to struct, rename test_json_list to test_list

* Replace chrono usage with uts2ts

* Check list result in test

* Add example to README

* Upgrade serde_json to 1.0.103

* Add linebreak

* Remove unneeded clone

* Remove extra nl

* Update README.md

* Update README.md

Co-authored-by: Orhun Parmaksız <orhunparmaksiz@gmail.com>

* Update README.md

Co-authored-by: Orhun Parmaksız <orhunparmaksiz@gmail.com>

* Remove serde_json

* Set default config to false for expose_list

* Apply suggestions from code review

Co-authored-by: Orhun Parmaksız <orhunparmaksiz@gmail.com>

* Check that option is value in test_list

* Update Cargo.toml

Co-authored-by: Helmut K. C. Tessarek <tessarek@evermeet.cx>

* Update cargo.lock

* Use expect() to check file name

* Remove underscore from list item struct

* Keep comma after last line

* refactor(server): rename ListItem fields

* test(fixtures): add fixture test for listing files

* test push

* remove file again

* chop off ts from filename and minor refactor

* update README

* docs(readme): fix capitalization

* refactor(server): clean up list implementation

---------

Co-authored-by: Orhun Parmaksız <orhunparmaksiz@gmail.com>
Co-authored-by: Helmut K. C. Tessarek <tessarek@evermeet.cx>
2023-08-07 12:55:13 +02:00
Helmut K. C. Tessarek 33e038cd4b
style(server): add new line char to most prominent messages (#97) 2023-07-22 10:12:04 +02:00
Helmut K. C. Tessarek 0d4808880f
feat(server): support multiple auth tokens (#84)
* feat(server): support multiple auth tokens

Example:

```toml
[server]
auth_tokens = [
  "super_secret_token1",
  "super_secret_token2",
]
```

The previously used `AUTH_TOKEN` environment variable can still be used
and will be evaluated as well.

* fixtures: add all tokens in array to the test

* add deprecation warning for auth_token

* also add deprecation warnings at server startup

* fix formatting

* fixed tests, so that we do not use deprecated config options

* use bash array

* refactor: use separate function

* refactor: check auth tokens

* Update fixtures/test-server-auth-multiple-tokens/test.sh

Co-authored-by: Orhun Parmaksız <orhunparmaksiz@gmail.com>

* refactor: convert functions to methods

* refactor: check function

* refactor: get_tokens method

* style(format): add newline between functions

* refactor(server): print deprecation warnings once

---------

Co-authored-by: Orhun Parmaksız <orhunparmaksiz@gmail.com>
2023-07-21 12:28:17 +02:00
Orhun Parmaksız 936feaedd5
fix(server): allow using deprecated landing page fields
This is a hotfix commit which allows the use of [server.landing_page]
fields even when the [landing_page] section does not exist in the
configuration file.
2023-07-01 17:28:56 +03:00
Helmut K. C. Tessarek 62bbfef6a3
feat(server): add random suffix mode (#69)
* add random suffix mode

* fix linter issues

* add test case

* fix linter issues

* add comments, remove empty lines and single line declarations

* more test cases

* refactor(config): rename suffix_mode to random_suffix

* refactor(paste): clean up the random suffix logic

* chore(config): add random suffix example to default config

* docs(readme): mention random suffix feature

* test(fixtures): add fixture test for random suffix mode

* random_suffix -> suffix_mode

* fix default extension for .dotfile w/o extension

* fix formatting

* style(format): fix the indentation for random suffix fixture

---------

Co-authored-by: Orhun Parmaksız <orhunparmaksiz@gmail.com>
2023-07-01 00:11:16 +02:00
Ömer Furkan Demircioğlu d51b68da10
style(server): add new line character to 404 message (#72) 2023-06-27 15:08:46 +02:00
Orhun Parmaksız 40a87c586b
fix(config): warn about the deprecated fields even though the section does not exist 2023-06-24 09:29:05 +03:00
Orhun Parmaksız 4df136870a
fix(deploy): use the static folder for config (#70) 2023-06-23 18:33:05 +03:00
Helmut K. C. Tessarek aa1734b3f8
refactor(config): use a separate section for the landing page (#65)
* add [landing_page] section to config

Migration path:

Old:

```
[server]
landing_page = "Landing page text."
landing_page_file = "index.html"
landing_page_content_type = "text/html; charset=utf-8"
```

New:

```
[landing_page]
text = "Landing page text."
file = "index.html"
content_type = "text/html; charset=utf-8"
```

* fix typo and remove comments

* make the section optional

* make the section optional

* test(server): fix landing page related test failures

* also change html_form.toml

* do not break current config

* refactor(config): deprecate server.landing_page config fields

---------

Co-authored-by: Orhun Parmaksız <orhunparmaksiz@gmail.com>
2023-06-23 17:20:24 +02:00
Orhun Parmaksız ff9fd68e89
chore(deps): bump shuttle dependencies to 0.19.0 2023-06-20 23:13:00 +03:00
Helmut K. C. Tessarek e0d6712dd3
feat(server): support a file for the landing page (#64)
* implemented landing_page_file

* fixed issues found by linter

* fixed formatting

* refactor(config): refactor landing page file handling

* add tests

* fix unnecessary conversion

* fix formatting

* remove comment

---------

Co-authored-by: Orhun Parmaksız <orhunparmaksiz@gmail.com>
2023-06-16 16:21:44 +02:00
Helmut K. C. Tessarek f7beaef502
feat(server): honor X-Forward-* headers (#61)
* honor X-Forward-* headers

Behind a reverse proxy, the log entries always showed the IP address of the reverse proxy.
With this change the real IP address of the client is shown.
Since the IP address is only used for info in the log, there are no security implications.

* style(format): apply formatting

---------

Co-authored-by: Orhun Parmaksız <orhunparmaksiz@gmail.com>
2023-06-13 01:00:55 +02:00
dependabot[bot] 07ec392867
chore(deps): bump hotwatch from 0.4.6 to 0.5.0 (#55)
Bumps [hotwatch](https://github.com/francesca64/hotwatch) from 0.4.6 to 0.5.0.
- [Release notes](https://github.com/francesca64/hotwatch/releases)
- [Changelog](https://github.com/francesca64/hotwatch/blob/main/CHANGELOG.md)
- [Commits](https://github.com/francesca64/hotwatch/compare/v0.4.6...v0.5.0)

---
updated-dependencies:
- dependency-name: hotwatch
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-06-05 23:15:30 +02:00
Orhun Parmaksız 19cb7cccb7
refactor(middleware): polish the ContentLengthLimiter implementation 2023-06-05 23:02:10 +03:00
Orhun Parmaksız 1670a71cdd
feat(server): implement middleware for limiting the content length (#53) 2023-06-05 22:49:26 +03:00
Orhun Parmaksız a13c0f123a
fix(hotwatch): do not drop the config watcher 2023-06-04 14:43:08 +03:00
Orhun Parmaksız 1a9163639c
chore(log): add startup log for showing the server address 2023-05-31 00:53:59 +03:00
Rahul Garg bd88146430
feat(server): support one shot URLs (#46)
* Add support for OneshotUrl

* Review cmt: Update README

* docs(oneshot): update documentation about oneshot URLs

* Review cmt: revert fmt

* test(fixtures): add fixture test for oneshot URLs

---------

Co-authored-by: Orhun Parmaksız <orhunparmaksiz@gmail.com>
2023-05-28 22:09:14 +02:00
Chris Jones 9d153ad907
feat(server): allow configuring the content type for landing page (#48)
* Allow user configuration of content type

* style(format): apply formatting

---------

Co-authored-by: Orhun Parmaksız <orhunparmaksiz@gmail.com>
2023-05-28 00:16:46 +02:00
Orhun Parmaksız 29ddef8df0
feat(deploy): deploy on shuttle.rs (#36)
* feat(deploy): deploy on shuttle.rs

* chore(deploy): add automated shuttle deploy workflow

* style(readme): update the formatting in README.md

* chore(deploy): optimize shuttle workflow

* fix(deploy): start the project

* fix(deploy): remove start step

This reverts commit 4f25921aeb.

* chore(deploy): expose the version for the public instance

* docs(lib): update the comment for shuttle entry-point

* chore(deploy): run the shuttle deployment on new tag
2023-05-14 18:03:53 +02:00
Orhun Parmaksız 4a4301ee72
style(server): make the default landing page fancier 2023-05-14 01:56:57 +03:00
Orhun Parmaksız 607f07b6e1
feat(server): support server-side default expiry time 2023-05-14 01:30:35 +03:00
Orhun Parmaksız 9ea7d5de8a
feat(config): support overriding the server URL 2023-05-13 23:20:52 +03:00
Orhun Parmaksız 99ac6156a8
feat(server): allow downloading files via `?download=true` parameter (#24) 2023-01-31 21:03:00 +03:00
Orhun Parmaksız 8bac3cc91f
fix(lints): apply clippy suggestions for tests 2022-12-18 23:43:58 +03:00
Orhun Parmaksız e83b8e6f4a
fix(lints): apply clippy suggestions 2022-12-18 23:12:28 +03:00