1
0
Fork 0
mirror of https://github.com/binwiederhier/ntfy.git synced 2024-11-26 13:19:15 +01:00

Check for image mimetype first

URL heuristic is the second check if there is no mime
This commit is contained in:
nimbleghost 2023-06-17 21:53:45 +02:00
parent 3cd61d8278
commit b7bb4459f9

View file

@ -34,13 +34,24 @@ export const formatMessage = (m) => {
return m.message; return m.message;
}; };
const isImage = (filenameOrUrl) => filenameOrUrl?.match(/\.(png|jpe?g|gif|webp)$/i) ?? false; const imageRegex = /\.(png|jpe?g|gif|webp)$/i;
const isImage = (attachment) => {
if (!attachment) return false;
// if there's a type, only take that into account
if (attachment.type) {
return attachment.type.startsWith("image/");
}
// otherwise, check the extension
return attachment.name?.match(imageRegex) || attachment.url?.match(imageRegex);
};
export const icon = "/static/images/ntfy.png"; export const icon = "/static/images/ntfy.png";
export const badge = "/static/images/mask-icon.svg"; export const badge = "/static/images/mask-icon.svg";
export const toNotificationParams = ({ subscriptionId, message, defaultTitle, topicRoute }) => { export const toNotificationParams = ({ subscriptionId, message, defaultTitle, topicRoute }) => {
const image = isImage(message.attachment?.name) ? message.attachment.url : undefined; const image = isImage(message.attachment) ? message.attachment.url : undefined;
// https://developer.mozilla.org/en-US/docs/Web/API/Notifications_API // https://developer.mozilla.org/en-US/docs/Web/API/Notifications_API
return [ return [