matrix-art

An image gallery for Matrix
git clone git://archive.git.mtrnord.blog/MTRNord/matrix-art.git
Log | Files | Refs | README | LICENSE

commit 64ac64fabfcbbb1ae873c7659190adeb56824fe6
parent ac008daf69eea8f3ffe62bed8387b232427c5e12
Author: MTRNord <mtrnord1@gmail.com>
Date:   Fri, 14 Jan 2022 14:53:05 +0100

Add thumnail to metadata

Diffstat:
Mhelpers/matrix_client.ts | 9++++-----
Mpages/index.tsx | 18+++++++++++++++++-
Mpages/post/[id].tsx | 18+++++++++++++++++-
3 files changed, 38 insertions(+), 7 deletions(-)

diff --git a/helpers/matrix_client.ts b/helpers/matrix_client.ts @@ -252,23 +252,22 @@ export default class MatrixClient { downloadLink(mxcUri: string): string | undefined { if (!mxcUri) { - return undefined; + return; } if (mxcUri.indexOf("mxc://") !== 0) { - return undefined; + return; } return constMatrixArtServer + "/_matrix/media/r0/download/" + mxcUri.split("mxc://")[1]; } - thumbnailLink(mxcUri: string, method: string, width: number, height: number) { + thumbnailLink(mxcUri: string, method: string, width: number, height: number): string | undefined { if (!mxcUri) { return; } if (mxcUri.indexOf("mxc://") !== 0) { return; } - const mediaUrl = this.serverUrl?.slice(0, -1 * "/client".length); - return `${mediaUrl}/media/r0/thumbnail/${mxcUri.split("mxc://")[1] + return `${constMatrixArtServer}/_matrix/media/r0/thumbnail/${mxcUri.split("mxc://")[1] }?method=${encodeURIComponent(method)}&width=${encodeURIComponent( width )}&height=${encodeURIComponent(height)}`; diff --git a/pages/index.tsx b/pages/index.tsx @@ -37,13 +37,21 @@ class Home extends PureComponent<Props, State>{ <div>Error: {error.message}</div> ); } else { - const metadata: { "@context": string; "@type": string; contentUrl: string; license: string; }[] = image_events.flatMap(event => { + const metadata: { "@context": string; "@type": string; contentUrl: string; license: string; thumbnail: any; }[] = image_events.flatMap(event => { if (isImageGalleryEvent(event)) { return event.content['m.image_gallery'].map(image => { return { "@context": "https://schema.org/", "@type": "ImageObject", "contentUrl": this.context.client?.downloadLink(image['m.file'].url)!, + "thumbnail": { + "@context": "https://schema.org/", + "@type": "ImageObject", + "contentUrl": this.context.client?.downloadLink(image['m.thumbnail'][0].url)!, + "license": "https://creativecommons.org/licenses/by-nc-nd/4.0/", + "author": event.content.displayname, + "name": image['m.text'] + }, // TODO get this from the event itself "license": "https://creativecommons.org/licenses/by-nc-nd/4.0/", "author": event.content.displayname, @@ -55,6 +63,14 @@ class Home extends PureComponent<Props, State>{ "@context": "https://schema.org/", "@type": "ImageObject", "contentUrl": this.context.client?.downloadLink(event.content['m.file'].url)!, + "thumbnail": { + "@context": "https://schema.org/", + "@type": "ImageObject", + "contentUrl": this.context.client?.downloadLink(event.content['m.thumbnail'][0].url)!, + "license": "https://creativecommons.org/licenses/by-nc-nd/4.0/", + "author": event.content.displayname, + "name": event.content['m.text'] + }, // TODO get this from the event itself "license": "https://creativecommons.org/licenses/by-nc-nd/4.0/", "author": event.content.displayname, diff --git a/pages/post/[id].tsx b/pages/post/[id].tsx @@ -242,6 +242,14 @@ class Post extends PureComponent<Props, State> { "@context": "https://schema.org/", "@type": "ImageObject", contentUrl: url, + "thumbnail": { + "@context": "https://schema.org/", + "@type": "ImageObject", + "contentUrl": this.context.client?.downloadLink(imageEvent.content['m.thumbnail'][0].url)!, + "license": "https://creativecommons.org/licenses/by-nc-nd/4.0/", + "author": imageEvent.content.displayname, + "name": imageEvent.content['m.text'] + }, // TODO get this from the event itself license: "https://creativecommons.org/licenses/by-nc-nd/4.0/", author: this.state.displayname, @@ -289,7 +297,7 @@ class Post extends PureComponent<Props, State> { } renderImageGalleryEvent(imageEvent: ImageGalleryEvent, caption: string) { - const metadata: { "@context": string; "@type": string; contentUrl: string; license: string; author: string; name: string; }[] = []; + const metadata: { "@context": string; "@type": string; contentUrl: string; license: string; author: string; name: string; thumbnail: any; }[] = []; const images = imageEvent.content['m.image_gallery'].map(image => { const url = this.context.client?.downloadLink(image["m.file"].url); const thumbnail_url = this.context.client?.downloadLink(image['m.thumbnail'][0].url); @@ -300,6 +308,14 @@ class Post extends PureComponent<Props, State> { "@context": "https://schema.org/", "@type": "ImageObject", contentUrl: url, + "thumbnail": { + "@context": "https://schema.org/", + "@type": "ImageObject", + "contentUrl": this.context.client?.downloadLink(image['m.thumbnail'][0].url)!, + "license": "https://creativecommons.org/licenses/by-nc-nd/4.0/", + "author": imageEvent.content.displayname, + "name": image['m.text'] + }, // TODO get this from the event itself license: "https://creativecommons.org/licenses/by-nc-nd/4.0/", author: this.state.displayname!,