summaryrefslogtreecommitdiffstats
path: root/web/react/utils
diff options
context:
space:
mode:
Diffstat (limited to 'web/react/utils')
-rw-r--r--web/react/utils/utils.jsx29
1 files changed, 17 insertions, 12 deletions
diff --git a/web/react/utils/utils.jsx b/web/react/utils/utils.jsx
index a808c9be3..33aae7d1e 100644
--- a/web/react/utils/utils.jsx
+++ b/web/react/utils/utils.jsx
@@ -15,9 +15,9 @@ import * as client from './client.jsx';
import Autolinker from 'autolinker';
export function isEmail(email) {
- //var regex = /^([a-zA-Z0-9_.+-])+\@(([a-zA-Z0-9-])+\.)+([a-zA-Z0-9]{2,4})+$/;
- var regex = /^[-a-z0-9~!$%^&*_=+}{\'?]+(\.[-a-z0-9~!$%^&*_=+}{\'?]+)*@([a-z0-9_][-a-z0-9_]*(\.[-a-z0-9_]+)*\.(aero|arpa|biz|com|coop|edu|gov|info|int|mil|museum|name|net|org|pro|travel|mobi|[a-z][a-z])|([0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}))(:[0-9]{1,5})?$/i;
- return regex.test(email);
+ // writing a regex to match all valid email addresses is really, really hard (see http://stackoverflow.com/a/201378)
+ // so we just do a simple check and rely on a verification email to tell if it's a real address
+ return email.indexOf('@') !== -1;
}
export function cleanUpUrlable(input) {
@@ -527,6 +527,19 @@ export function splitFileLocation(fileLocation) {
return {ext: ext, name: filename, path: filePath};
}
+export function getPreviewImagePath(filename) {
+ // Returns the path to a preview image that can be used to represent a file.
+ const fileInfo = splitFileLocation(filename);
+ const fileType = getFileType(fileInfo.ext);
+
+ if (fileType === 'image') {
+ return getFileUrl(fileInfo.path + '_preview.jpg');
+ }
+
+ // only images have proper previews, so just use a placeholder icon for non-images
+ return getPreviewImagePathForFileType(fileType);
+}
+
export function toTitleCase(str) {
function doTitleCase(txt) {
return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase();
@@ -1050,15 +1063,7 @@ export function fileSizeToString(bytes) {
// Converts a filename (like those attached to Post objects) to a url that can be used to retrieve attachments from the server.
export function getFileUrl(filename) {
- var url = filename;
-
- // This is a temporary patch to fix issue with old files using absolute paths
- if (url.indexOf('/api/v1/files/get') !== -1) {
- url = filename.split('/api/v1/files/get')[1];
- }
- url = getWindowLocationOrigin() + '/api/v1/files/get' + url + '?' + getSessionIndex();
-
- return url;
+ return getWindowLocationOrigin() + '/api/v1/files/get' + filename + '?' + getSessionIndex();
}
// Gets the name of a file (including extension) from a given url or file path.