UNPKG

6.17 kBSource Map (JSON)View Raw
1{"version":3,"sources":["../src/content-repo.js"],"names":["utils","require","module","exports","getHttpUriForMxc","baseUrl","mxc","width","height","resizeMethod","allowDirectLinks","indexOf","serverAndMediaId","slice","prefix","params","method","keys","length","fragmentOffset","fragment","substr","encodeParams","getIdenticonUri","identiconString","path","encodeUri","$ident"],"mappings":";;AAAA;;;;;;;;;;;;;;;AAeA;;;AAGA,IAAMA,QAAQC,QAAQ,SAAR,CAAd;;AAEA;AACAC,OAAOC,OAAP,GAAiB;AACb;;;;;;;;;;;;;;AAcAC,sBAAkB,0BAASC,OAAT,EAAkBC,GAAlB,EAAuBC,KAAvB,EAA8BC,MAA9B,EACSC,YADT,EACuBC,gBADvB,EACyC;AACvD,YAAI,OAAOJ,GAAP,KAAe,QAAf,IAA2B,CAACA,GAAhC,EAAqC;AACjC,mBAAO,EAAP;AACH;AACD,YAAIA,IAAIK,OAAJ,CAAY,QAAZ,MAA0B,CAA9B,EAAiC;AAC7B,gBAAID,gBAAJ,EAAsB;AAClB,uBAAOJ,GAAP;AACH,aAFD,MAEO;AACH,uBAAO,EAAP;AACH;AACJ;AACD,YAAIM,mBAAmBN,IAAIO,KAAJ,CAAU,CAAV,CAAvB,CAXuD,CAWlB;AACrC,YAAIC,SAAS,6BAAb;AACA,YAAMC,SAAS,EAAf;;AAEA,YAAIR,KAAJ,EAAW;AACPQ,mBAAOR,KAAP,GAAeA,KAAf;AACH;AACD,YAAIC,MAAJ,EAAY;AACRO,mBAAOP,MAAP,GAAgBA,MAAhB;AACH;AACD,YAAIC,YAAJ,EAAkB;AACdM,mBAAOC,MAAP,GAAgBP,YAAhB;AACH;AACD,YAAIT,MAAMiB,IAAN,CAAWF,MAAX,EAAmBG,MAAnB,GAA4B,CAAhC,EAAmC;AAC/B;AACA;AACAJ,qBAAS,8BAAT;AACH;;AAED,YAAMK,iBAAiBP,iBAAiBD,OAAjB,CAAyB,GAAzB,CAAvB;AACA,YAAIS,WAAW,EAAf;AACA,YAAID,kBAAkB,CAAtB,EAAyB;AACrBC,uBAAWR,iBAAiBS,MAAjB,CAAwBF,cAAxB,CAAX;AACAP,+BAAmBA,iBAAiBS,MAAjB,CAAwB,CAAxB,EAA2BF,cAA3B,CAAnB;AACH;AACD,eAAOd,UAAUS,MAAV,GAAmBF,gBAAnB,IACFZ,MAAMiB,IAAN,CAAWF,MAAX,EAAmBG,MAAnB,KAA8B,CAA9B,GAAkC,EAAlC,GACA,MAAMlB,MAAMsB,YAAN,CAAmBP,MAAnB,CAFJ,IAEmCK,QAF1C;AAGH,KAvDY;;AAyDb;;;;;;;;AAQAG,qBAAiB,yBAASlB,OAAT,EAAkBmB,eAAlB,EAAmCjB,KAAnC,EAA0CC,MAA1C,EAAkD;AAC/D,YAAI,CAACgB,eAAL,EAAsB;AAClB,mBAAO,IAAP;AACH;AACD,YAAI,CAACjB,KAAL,EAAY;AACRA,oBAAQ,EAAR;AACH;AACD,YAAI,CAACC,MAAL,EAAa;AACTA,qBAAS,EAAT;AACH;AACD,YAAMO,SAAS;AACXR,mBAAOA,KADI;AAEXC,oBAAQA;AAFG,SAAf;;AAKA,YAAMiB,OAAOzB,MAAM0B,SAAN,CAAgB,oCAAhB,EAAsD;AAC/DC,oBAAQH;AADuD,SAAtD,CAAb;AAGA,eAAOnB,UAAUoB,IAAV,IACFzB,MAAMiB,IAAN,CAAWF,MAAX,EAAmBG,MAAnB,KAA8B,CAA9B,GAAkC,EAAlC,GACI,MAAMlB,MAAMsB,YAAN,CAAmBP,MAAnB,CAFR,CAAP;AAGH;AAtFY,CAAjB","file":"content-repo.js","sourcesContent":["/*\nCopyright 2015, 2016 OpenMarket Ltd\n\nLicensed under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License.\nYou may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License.\n*/\n/**\n * @module content-repo\n */\nconst utils = require(\"./utils\");\n\n/** Content Repo utility functions */\nmodule.exports = {\n /**\n * Get the HTTP URL for an MXC URI.\n * @param {string} baseUrl The base homeserver url which has a content repo.\n * @param {string} mxc The mxc:// URI.\n * @param {Number} width The desired width of the thumbnail.\n * @param {Number} height The desired height of the thumbnail.\n * @param {string} resizeMethod The thumbnail resize method to use, either\n * \"crop\" or \"scale\".\n * @param {Boolean} allowDirectLinks If true, return any non-mxc URLs\n * directly. Fetching such URLs will leak information about the user to\n * anyone they share a room with. If false, will return the emptry string\n * for such URLs.\n * @return {string} The complete URL to the content.\n */\n getHttpUriForMxc: function(baseUrl, mxc, width, height,\n resizeMethod, allowDirectLinks) {\n if (typeof mxc !== \"string\" || !mxc) {\n return '';\n }\n if (mxc.indexOf(\"mxc://\") !== 0) {\n if (allowDirectLinks) {\n return mxc;\n } else {\n return '';\n }\n }\n let serverAndMediaId = mxc.slice(6); // strips mxc://\n let prefix = \"/_matrix/media/v1/download/\";\n const params = {};\n\n if (width) {\n params.width = width;\n }\n if (height) {\n params.height = height;\n }\n if (resizeMethod) {\n params.method = resizeMethod;\n }\n if (utils.keys(params).length > 0) {\n // these are thumbnailing params so they probably want the\n // thumbnailing API...\n prefix = \"/_matrix/media/v1/thumbnail/\";\n }\n\n const fragmentOffset = serverAndMediaId.indexOf(\"#\");\n let fragment = \"\";\n if (fragmentOffset >= 0) {\n fragment = serverAndMediaId.substr(fragmentOffset);\n serverAndMediaId = serverAndMediaId.substr(0, fragmentOffset);\n }\n return baseUrl + prefix + serverAndMediaId +\n (utils.keys(params).length === 0 ? \"\" :\n (\"?\" + utils.encodeParams(params))) + fragment;\n },\n\n /**\n * Get an identicon URL from an arbitrary string.\n * @param {string} baseUrl The base homeserver url which has a content repo.\n * @param {string} identiconString The string to create an identicon for.\n * @param {Number} width The desired width of the image in pixels. Default: 96.\n * @param {Number} height The desired height of the image in pixels. Default: 96.\n * @return {string} The complete URL to the identicon.\n */\n getIdenticonUri: function(baseUrl, identiconString, width, height) {\n if (!identiconString) {\n return null;\n }\n if (!width) {\n width = 96;\n }\n if (!height) {\n height = 96;\n }\n const params = {\n width: width,\n height: height,\n };\n\n const path = utils.encodeUri(\"/_matrix/media/v1/identicon/$ident\", {\n $ident: identiconString,\n });\n return baseUrl + path +\n (utils.keys(params).length === 0 ? \"\" :\n (\"?\" + utils.encodeParams(params)));\n },\n};\n"]}
\No newline at end of file