mirror of
https://github.com/zulip/zulip-desktop.git
synced 2025-10-24 08:33:36 +00:00
This adds a feature of showing the pdf attachments in a new window so that a user can quickly view the same. Fixes: #547.
46 lines
969 B
JavaScript
46 lines
969 B
JavaScript
'use strict';
|
|
|
|
const wurl = require('wurl');
|
|
|
|
let instance = null;
|
|
|
|
class LinkUtil {
|
|
constructor() {
|
|
if (instance) {
|
|
return instance;
|
|
} else {
|
|
instance = this;
|
|
}
|
|
|
|
return instance;
|
|
}
|
|
|
|
isInternal(currentUrl, newUrl) {
|
|
const currentDomain = wurl('hostname', currentUrl);
|
|
const newDomain = wurl('hostname', newUrl);
|
|
|
|
const sameDomainUrl = (currentDomain === newDomain || newUrl === currentUrl + '/');
|
|
const isUploadsUrl = newUrl.includes(currentUrl + '/user_uploads/');
|
|
const isInternalUrl = newUrl.includes('/#narrow') || isUploadsUrl;
|
|
|
|
return {
|
|
isInternalUrl: sameDomainUrl && isInternalUrl,
|
|
isUploadsUrl
|
|
};
|
|
}
|
|
|
|
isImage(url) {
|
|
// test for images extension as well as urls like .png?s=100
|
|
const isImageUrl = /\.(bmp|gif|jpg|jpeg|png|webp)\?*.*$/i;
|
|
return isImageUrl.test(url);
|
|
}
|
|
|
|
isPDF(url) {
|
|
// test for pdf extension
|
|
const isPDFUrl = /\.(pdf)\?*.*$/i;
|
|
return isPDFUrl.test(url);
|
|
}
|
|
}
|
|
|
|
module.exports = new LinkUtil();
|