From e24cdcb815ca7045d56a22dc9879000ac6775493 Mon Sep 17 00:00:00 2001 From: Thomas Lynch Date: Sun, 19 Sep 2021 18:16:42 +0000 Subject: [PATCH] bugfixes and improvements for #369 - only show imgops on image/* mimetype - fix an issue with meta url, imgops links and notifications improve post notifications, show image/badge/icon, trying thumbs and respecting spoilers --- gulp/res/js/hover.js | 5 ++++- gulp/res/js/live.js | 3 ++- gulp/res/js/yous.js | 22 ++++++++++++++++++++-- gulpfile.js | 1 + views/mixins/post.pug | 4 ++-- 5 files changed, 29 insertions(+), 6 deletions(-) diff --git a/gulp/res/js/hover.js b/gulp/res/js/hover.js index d9c7dd82..c1cd0867 100644 --- a/gulp/res/js/hover.js +++ b/gulp/res/js/hover.js @@ -131,7 +131,10 @@ window.addEventListener('DOMContentLoaded', (event) => { if (!postJson) { return; //post was deleted or missing } - const postHtml = post({ post: postJson }); + const postHtml = post({ + post: postJson, + meta: metaLocal, + }); const wrap = document.createElement('div'); wrap.innerHTML = postHtml; hoveredPost = wrap.firstChild.nextSibling; diff --git a/gulp/res/js/live.js b/gulp/res/js/live.js index 8de0cad2..b24bbb24 100644 --- a/gulp/res/js/live.js +++ b/gulp/res/js/live.js @@ -39,7 +39,8 @@ window.addEventListener('settingsReady', function(event) { //after domcontentloa modview: isModView, manage: (isRecent && !isGlobalRecent), globalmanage: isGlobalRecent, - upLevel: isThread + upLevel: isThread, + meta: metaLocal, }); let insertPoint; if (isRecent) { diff --git a/gulp/res/js/yous.js b/gulp/res/js/yous.js index 9b868d3c..8e3e10d0 100644 --- a/gulp/res/js/yous.js +++ b/gulp/res/js/yous.js @@ -69,9 +69,27 @@ const handleNewYous = (e) => { try { console.log('attempting to send notification', postYou); const postData = e.detail.json; - new Notification(`${quotesYou ? 'New quote in: ' : ''}${document.title}`, { + const notificationOptions = { body: postData.nomarkup ? postData.nomarkup.substring(0,100) : '' - }); + } + if (postData.files.length > 0 && !postData.spoiler) { + //tries to use a thumb instead of full files, will be lighter on bandwidth and able to show for video and some audio too + const notificationFile = postData.files.find(f => (!f.spoiler && (f.hasThumb === true || f.mimetype.startsWith('image/')))); + if (notificationFile) { + let notificationImageURL; + if (notificationFile.hasThumb) { + notificationImageURL = `/file/thumb/${notificationFile.hash}${notificationFile.thumbextension}`; + } else { + notificationImageURL = `/file/${notificationFile.filename}`; + } + if (notificationImageURL) { + notificationOptions.image = notificationImageURL; + notificationOptions.badge = notificationImageURL; + notificationOptions.icon = notificationImageURL; + } + } + } + new Notification(`${quotesYou ? 'New quote in: ' : ''}${document.title}`, notificationOptions); } catch (e) { // notification cant send for some reason -- user revoked perms in browser? console.log('failed to send notification', e); diff --git a/gulpfile.js b/gulpfile.js index 5a4a0c34..94909fa9 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -386,6 +386,7 @@ const captchaGridSize = ${config.get.captchaOptions.grid.size}; const SERVER_TIMEZONE = '${Intl.DateTimeFormat().resolvedOptions().timeZone}'; const ipHashPermLevel = ${config.get.ipHashPermLevel}; const settings = ${JSON.stringify(config.get.frontendScriptDefault)}; +const metaLocal = ${JSON.stringify(config.get.meta)}; `; fs.writeFileSync('gulp/res/js/locals.js', locals); fs.writeFileSync('gulp/res/js/post.js', pug.compileFileClient(`${paths.pug.src}/includes/post.pug`, { compileDebug: false, debug: false, name: 'post' })); diff --git a/views/mixins/post.pug b/views/mixins/post.pug index bfc9e9e7..bc79ad78 100644 --- a/views/mixins/post.pug +++ b/views/mixins/post.pug @@ -76,6 +76,7 @@ mixin post(post, truncate, manage=false, globalmanage=false, ban=false, overboar .post-files(class=(post.files.length > 1 ? 'fn' : '')) each file, fileindex in post.files .post-file + - const type = file.mimetype.split('/')[0] span.post-file-info span: a(href='/file/'+file.filename title='Download '+file.originalFilename download=file.originalFilename) #{post.spoiler || file.spoiler ? 'Spoiler File' : file.originalFilename} | @@ -97,10 +98,9 @@ mixin post(post, truncate, manage=false, globalmanage=false, ban=false, overboar if file.durationString | , #{file.durationString} | ) - if (board && board.settings.reverseImageSearchLinks === true) || overboard || manage || globalmanage + if type === 'image' && ((board && board.settings.reverseImageSearchLinks === true) || overboard || manage || globalmanage) | span: a(href=`https://imgops.com/${meta.url}/file/${file.filename}` title='ImgOps' target='_blank') ImgOps - - const type = file.mimetype.split('/')[0] .post-file-src(data-type=type data-attachment=(file.attachment ? "true" : "false")) a(target='_blank' href=`/file/${file.filename}`) if post.spoiler || file.spoiler