Fix Thumbnail.from_bytes()
This commit is contained in:
parent
24180fc346
commit
f9f558cd34
2
TODO.md
2
TODO.md
|
@ -153,8 +153,6 @@
|
||||||
|
|
||||||
## Backend
|
## Backend
|
||||||
|
|
||||||
- Have a `Thubmnail.from_existing_file()` to be called after generating and
|
|
||||||
and uploading a thumbnail, like the equivalent `Media.from_existing_file()`
|
|
||||||
- Saving the room settings
|
- Saving the room settings
|
||||||
- Refetch profile after manual profile change, don't wait for a room event
|
- Refetch profile after manual profile change, don't wait for a room event
|
||||||
|
|
||||||
|
|
|
@ -471,8 +471,7 @@ class MatrixClient(nio.AsyncClient):
|
||||||
|
|
||||||
thumb_url, _, thumb_crypt_dict = await self.upload(
|
thumb_url, _, thumb_crypt_dict = await self.upload(
|
||||||
lambda *_: thumb_data,
|
lambda *_: thumb_data,
|
||||||
filename =
|
filename = f"{path.stem}_sample{path.suffix}",
|
||||||
f"{path.stem}_sample{''.join(path.suffixes)}",
|
|
||||||
filesize = thumb_info.size,
|
filesize = thumb_info.size,
|
||||||
encrypt = encrypt,
|
encrypt = encrypt,
|
||||||
monitor = monitor,
|
monitor = monitor,
|
||||||
|
@ -489,6 +488,7 @@ class MatrixClient(nio.AsyncClient):
|
||||||
await Thumbnail.from_bytes(
|
await Thumbnail.from_bytes(
|
||||||
self.backend.media_cache,
|
self.backend.media_cache,
|
||||||
thumb_url,
|
thumb_url,
|
||||||
|
path.name,
|
||||||
thumb_data,
|
thumb_data,
|
||||||
wanted_size = (content["info"]["w"],
|
wanted_size = (content["info"]["w"],
|
||||||
content["info"]["h"]),
|
content["info"]["h"]),
|
||||||
|
|
|
@ -193,13 +193,14 @@ class Media:
|
||||||
cls,
|
cls,
|
||||||
cache: "MediaCache",
|
cache: "MediaCache",
|
||||||
mxc: str,
|
mxc: str,
|
||||||
|
filename: str,
|
||||||
data: bytes,
|
data: bytes,
|
||||||
overwrite: bool = False,
|
overwrite: bool = False,
|
||||||
**kwargs,
|
**kwargs,
|
||||||
) -> "Media":
|
) -> "Media":
|
||||||
"""Create a cached file from bytes data and return a `Media` for it."""
|
"""Create a cached file from bytes data and return a `Media` for it."""
|
||||||
|
|
||||||
media = cls(cache, mxc, {}, **kwargs) # type: ignore
|
media = cls(cache, mxc, filename, {}, **kwargs) # type: ignore
|
||||||
media.local_path.parent.mkdir(parents=True, exist_ok=True)
|
media.local_path.parent.mkdir(parents=True, exist_ok=True)
|
||||||
|
|
||||||
if not media.local_path.exists() or overwrite:
|
if not media.local_path.exists() or overwrite:
|
||||||
|
|
Loading…
Reference in New Issue
Block a user