diff --git a/controllers/albumsController.js b/controllers/albumsController.js index 1c5bc7b..a74a323 100644 --- a/controllers/albumsController.js +++ b/controllers/albumsController.js @@ -191,10 +191,10 @@ albumsController.get = async (req, res, next) => { } albumsController.generateZip = async (req, res, next) => { + const versionString = parseInt(req.query.v) const download = (filePath, fileName) => { const headers = { 'Access-Control-Allow-Origin': '*' } - // Album page will append editedAt timestamp to the download link by default - if (parseInt(req.query.v) > 0) { + if (versionString > 0) { // Cache-Control header is useful when using CDN (max-age: 30 days) headers['Cache-Control'] = 'public, max-age=2592000, must-revalidate, proxy-revalidate, immutable, stale-while-revalidate=86400, stale-if-error=604800' } @@ -227,6 +227,10 @@ albumsController.generateZip = async (req, res, next) => { }) } + if ((!versionString || versionString <= 0) && album.editedAt) { + return res.redirect(`${album.identifier}?v=${album.editedAt}`) + } + if (album.zipGeneratedAt > album.editedAt) { const filePath = path.join(config.uploads.folder, 'zips', `${identifier}.zip`) const fileName = `${album.name}.zip` diff --git a/views/album.njk b/views/album.njk index 00ba3ca..4b79a58 100644 --- a/views/album.njk +++ b/views/album.njk @@ -41,7 +41,7 @@ - {% if enableDownload -%} + {% if enableDownload and files.length -%}

Download Album @@ -49,7 +49,7 @@

{%- endif %} - {% if enableDownload -%} + {% if enableDownload and files.length -%}
Album archives may be cached by CDN, if the one you downloaded seems outdated, you should try refreshing the page to get the latest version of the download link. @@ -72,7 +72,7 @@ {%- else -%}
- There is nothing here yet! + There are no files in the album.
{%- endif %}