mirror of
https://github.com/commetchat/encrypted_url_preview.git
synced 2026-11-04 02:35:58 +00:00
Hides url preview content from matrix homeserver
- Dart 100%
| Filename | Latest commit message | Latest commit date |
|---|---|---|
| lib | ||
| test | ||
| .gitattributes | ||
| .gitignore | ||
| ABOUT.md | ||
| analysis_options.yaml | ||
| CHANGELOG.md | ||
| LICENSE | ||
| pubspec.yaml | ||
| README.md | ||
Provides a Utility to construct and handle encryption for Commet's encrypted url previews.
This is still experimental and should not be used in a production project.
Getting started
This package is intended to be used in conjunction with a matrix client.
Usage
final encryptedPreviewGetter = EncryptedUrlPreview(
proxyServerUrl: Uri.parse("https://telescope.commet.chat"),
// Server public key
publicKeyPem: """-----BEGIN PUBLIC KEY-----
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAz+sAi8PsT4QwjV/+xXK0
vwavZJEjkwJyFODGWkoo7qB87Y2yU6/C4csul6kQpxBFu9ID7mCavAlr93/c70Qm
sgX791W7oOSpvyeffJe5iluzaglZ/KWYo6Bc0QajKT8rLdI5vUljVMyx/nR9rIhY
PvSJhSFLC2ZyUhhTb/ZeLm0arEtGeyfo1V3nLGsJZJx12UK8E0FpKP14S7Wke9zM
e05PDCU/llEQpUgQOJI9Vnji71Fgocii76aSULhXalGjQIzBGKib5MIYlb0Zgf8k
wKkRg6IrNt5kjad4PoRKocxj3ylvuxEtMN582ni3lO4gi1uzzVvFtJBzrhNMjTPC
pQIDAQAB
-----END PUBLIC KEY-----""");
var contentKey = urlGetter.getNextKey();
var proxyUrl = encryptedPreviewGetter!.getProxyUrl(url, contentKey);
var response = await client.request(
matrix.RequestType.GET, "/media/v3/preview_url",
query: {"url": proxyUrl.toString()});
var title = response['og:title'] as String?;
var imageUrl = response['og:image'] as String?;
ImageProvider? image;
if (imageUrl != null) {
var mxcUri = Uri.parse(imageUrl);
if (mxcUri.scheme == "mxc") {
var response =
await client.httpClient.get(mxcUri.getDownloadLink(client));
var bytes = response.bodyBytes;
var decrypted = encryptedPreviewGetter!.decryptContent(bytes, contentKey);
image = Image.memory(decrypted).image;
}
}
if (title != null)
title = encryptedPreviewGetter!.decryptContentString(title, contentKey);
How does it work?
See ABOUT.md