diff --git a/lib/client.js b/lib/client.js index c984b5295..b5b1ea66b 100644 --- a/lib/client.js +++ b/lib/client.js @@ -1448,6 +1448,23 @@ MatrixClient.prototype.getCurrentUploads = function() { return this._http.getCurrentUploads(); }; +/** + * Get a preview of the given URL as OpenGraph metadata + * @param {module:client.callback} callback Optional. + * @return {module:client.Promise} Resolves: Object of OG metadata. + * @return {module:http-api.MatrixError} Rejects: with an error response. + * May return synthesized attributes if the URL lacked OG meta. + */ +MatrixClient.prototype.getUrlPreview = function(url, callback) { + // FIXME: maintain a clientside cache to stop hammering synapse + // especially as synapse doesn't cache yet + return this._http.authedRequestWithPrefix( + callback, "GET", "/preview_url", { + url: url + }, undefined, httpApi.PREFIX_MEDIA_R0 + ); +}; + /** * @param {string} roomId * @param {boolean} isTyping diff --git a/lib/http-api.js b/lib/http-api.js index 9d7edbc70..92fdd085a 100644 --- a/lib/http-api.js +++ b/lib/http-api.js @@ -47,6 +47,11 @@ module.exports.PREFIX_UNSTABLE = "/_matrix/client/unstable"; */ module.exports.PREFIX_IDENTITY_V1 = "/_matrix/identity/api/v1"; +/** + * URI path for the media repo API + */ +module.exports.PREFIX_MEDIA_R0 = "/_matrix/media/r0"; + /** * Construct a MatrixHttpApi. * @constructor