Commit Graph

281 Commits

Author SHA1 Message Date
Michael Manganiello
3eb9d902d6 misc: Remove print leftover in CallbackIO class 2024-12-16 22:50:28 -03:00
Michael Manganiello
477d9b1744 feat: Add streaming support for 7zip hashing
At the moment, 7zip files are generating memory issues and even OOM
errors on user installations. This is because the current stable release
of `py7zr` does not support decompression streaming, and RomM needs to
decompress the each 7zip file in the library into memory to be able to
calculate hashes.

This change introduces a `py7zr` fork I created to have a stable commit
SHA to refer to in case upstream gets any forced pushes. It includes the
contents of the pull request the `py7zr` creator is working on to
support decompression streaming [1].

The way decompression streaming is implemented in `py7zr` is different
than the other compression utilities. Instead of being able to provide a
`bytes` iterator, we need to provide a `Py7zIO` implementation that
will call a callback on each read and write operation.

[1] https://github.com/miurahr/py7zr/pull/620
2024-11-08 21:31:11 -03:00
Michael Manganiello
60ff832663 fix: Escape URLs when files are served by nginx
When serving files using the `X-Accel-Redirect` header in nginx, the
header values must be URL-encoded. Otherwise, nginx will not be able
to serve the files if they contain special characters.

This commit adds a new `FileRedirectResponse` class to the `utils.nginx`
module, to simplify the creation of responses that serve files using the
`X-Accel-Redirect` header.

Fixes #1212, #1223.
2024-10-06 13:29:42 -03:00
Georges-Antoine Assi
38d5ec13a5 compile regexes 2024-08-26 13:02:50 -04:00
Georges-Antoine Assi
c8b8bcabc8 Replace illegal fs chars in filenames 2024-08-21 22:26:56 -04:00
Michael Manganiello
0fad8ac282 feat: Use nginx mod_zip to generate multi-file zip downloads
This change installs and configures the `mod_zip` nginx module [1],
which allows nginx to stream ZIP files directly.

It includes a workaround needed to correctly calculate CRC-32 values for
included files, by including a new `server` section listening at port
8081, only used for the file requests to be upstream subrequests that
correctly trigger the CRC-32 calculation logic.

Also, to be able to provide a `m3u` file generated on the fly, we add a
`/decode` endpoint fully implemented in nginx using NJS, which receives
a `value` URL param, and decodes it using base64. The decoded value is
returned as the response.

That way, the contents of the `m3u` file is base64-encoded, and set as
part of the response, for `mod_zip` to include it in the ZIP file.

[1] https://github.com/evanmiller/mod_zip
2024-08-20 22:39:33 -03:00
Michael Manganiello
0fdbbe4625 misc: Upgrade Python to v3.12 and Alpine to v3.20
Included upgrades:
* Python: v3.12
* Alpine: v3.20 (which uses Python 3.12)
* nginx: v1.27.1
2024-08-15 20:14:32 -03:00
Michael Manganiello
95a66a182e misc: Improve typing for feed schemas
* Add typing for nested objects in Tinfoil and Webrcade feed schemas.
* Do not send Rom background and thumbnail, if not available.
* Correctly build URLs using `starlette` utils.
* Deprecate the `ROMM_HOST` setting, no longer needed.
* Fix FastAPI custom router to prefer routes without trailing slash.
* Fix Webrcade background URL pointing to gallery screenshot.
2024-08-07 22:56:16 -03:00
Michael Manganiello
8abbae4c02 misc: Make backend handle URLs with trailing slash
According to multiple FastAPI discussions [1], FastAPI only includes a
built-in mechanism to redirect requests including a trailing slash, to
its variation without slash, using a `307` status code.

This can be an issue when certain clients do not send the same headers
on the redirected request.

This change adds a custom FastAPI `APIRouter`, that registers both route
path variations (with and without trailing slash), while only marking
the path without slash for being included in the OpenAPI schema.

[1] https://github.com/fastapi/fastapi/discussions/7298
2024-08-07 00:22:21 -03:00
Georges-Antoine Assi
7555c0607a [ROMM-1025] Replace game-and-watch with g-and-w 2024-07-25 14:26:06 -04:00
Michael Manganiello
7c6dfa8e50 feat: Use ContextVar to share httpx AsyncClient instance between requests 2024-07-23 01:29:32 -03:00
Michael Manganiello
f20a9ffe34 fix: Avoid recursive os.walk calls
`os.walk` is a generator that can iteratively navigate from the
specified path, top-bottom. However, most of the calls to `os.walk` in
the project cast the call to `list()`, which makes it traverse the path
and recursively find all nested directories.

This is commonly not needed, as we end up just using a `[0]` index to
only access the root path.

This change adds a few utils that simplifies listing files/directories,
and by default does it non-recursively. Performance gains shouldn't be
noticeable in systems with high-speed storage, but we can avoid the edge
cases of users having too many nested directories, by avoiding unneeded
I/O.
2024-07-13 15:30:04 -03:00
Michael Manganiello
e1bcd9cc06 misc: Use Python future annotations
Simplify annotations by using `__future__.annotations`, so there's no
need to add typing using types as strings.
2024-06-30 12:19:37 -03:00
Michael Manganiello
3bd37165d4 fix: Call Redis HSET in bulk 2024-06-26 00:17:49 -03:00
Michael Manganiello
3d4a66cbca misc: Remove mentions to unneeded Poetry mention
Poetry 1.8.0 already includes support for `package-mode = false`, so
there's no need to install a Poetry fork anymore.
2024-06-24 07:38:27 -03:00
Georges-Antoine Assi
7635bbeac2 run trunk fixes 2024-05-24 16:59:54 -04:00
Georges-Antoine Assi
b075e93321 Merge branch 'master' into trunk-io 2024-05-24 16:47:19 -04:00
Georges-Antoine Assi
f73a6f48b9 more refactoring 2024-05-23 21:13:17 -04:00
Georges-Antoine Assi
2b60402a04 start fixing mypy issues 2024-05-21 19:22:14 -04:00
Georges-Antoine Assi
a7cf0d389a run trunk format on all files 2024-05-21 10:18:13 -04:00
Georges-Antoine Assi
880345f20c ruff-only pre-commit 2024-05-18 12:05:57 -04:00
Georges-Antoine Assi
9ad28f3294 more refactoring again 2024-05-05 16:32:40 -04:00
Georges-Antoine Assi
6d3bcff4f1 move files to utils 2024-04-03 22:33:41 -04:00
Zurdi
956a9fb647 clean utils folder 2024-02-06 23:03:44 +01:00
Georges-Antoine Assi
885ae3fa06 second attempt to fix tests 2024-02-05 17:41:17 -05:00
Georges-Antoine Assi
018652fb67 fix tests 2024-02-05 17:16:44 -05:00
Zurdi
3de72d075c fixed tests 2024-02-05 11:28:39 +01:00
Zurdi
066f640089 fixed tests 2024-02-01 09:48:47 +01:00
Zurdi
37c359fa97 path_cover and url_cover refactored 2024-02-01 00:22:44 +01:00
Georges-Antoine Assi
0ca6d74c26 Add file_name_no_ext column 2024-01-20 15:09:11 -05:00
Zurdi
720a9617bc fixed unit tests 2024-01-19 15:10:01 +01:00
Georges-Antoine Assi
81b5bcf9ba refactor handler names 2024-01-18 14:04:35 -05:00
Georges-Antoine Assi
86b55c68a3 fix circular import + migration 15 downgrade 2024-01-18 13:44:07 -05:00
Georges-Antoine Assi
eaad1f2353 small fixes 2024-01-17 21:22:07 -05:00
Georges-Antoine Assi
9495942084 Fix the rest of the tests 2024-01-17 10:57:07 -05:00
Georges-Antoine Assi
7963e243dc Fix batch of test fixes 2024-01-17 10:26:37 -05:00
Zurdi
77694c6f0e Merge remote-tracking branch 'origin/stats-endpoint' into refactor/backend 2024-01-16 22:25:27 +01:00
Georges-Antoine Assi
33645641b8 Add stats endpoint + refactor rom file size 2024-01-16 11:06:05 -05:00
Zurdi
1d2c9e7d05 standarized GET endpoints for roms and platforms 2024-01-14 02:34:37 +01:00
Zurdi
93f6cb7651 Merge branch 'feature/manage_config_from_ui' into refactor/backend 2024-01-13 02:17:19 +01:00
Zurdi
4b9e76f550 backend structure refactor 2024-01-12 23:44:27 +01:00
Zurdi
180d6e8b91 added create exclusion button 2024-01-11 20:41:06 +01:00
Zurdi
47a83a525b config is loaded dinamycally and platform bindings can be removed from UI 2024-01-11 15:26:41 +01:00
Zurdi
fb1c02459e added methods to add and remove platforms bindings to config manager 2024-01-11 00:29:41 +01:00
Zurdi
06d041fa30 catch timeout from check new version 2024-01-10 15:17:51 +01:00
Georges-Antoine Assi
f5996b94eb dialog to delete from fs 2024-01-09 22:23:50 -05:00
Zurdi
5b51bb150f generated new types 2024-01-09 21:40:19 +01:00
Georges-Antoine Assi
ffd9a2570e Fix tests 2024-01-09 13:34:47 -05:00
Georges-Antoine Assi
5762270f62 Merge branch 'master' into romm-55 2024-01-09 13:06:51 -05:00
Zurdi
cda45e6d9c Merge remote-tracking branch 'origin/master' 2024-01-09 16:26:43 +01:00