mirror of
https://github.com/BobbyWibowo/lolisafe.git
synced 2024-12-14 00:16:21 +00:00
Updated some things involving album zipping
* When version string is not specified in the URL query of /api/zip/:identifier (the API route to generate and download ZIP archive of the album), it will redirect the request with the album's editedAt timestamp as the value in the version string (only if editedAt timestamp exists). This will ensure that any bare calls to the API (without version string) will always be redirected to its latest state. This is mainly useful when being used with CDN that respects query string. * Download button and CDN notice will no longer be visible in empty album pages. * Matched empty album phrase as the one being used with the zipping API.
This commit is contained in:
parent
e01b007ea1
commit
535d3df73f
@ -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`
|
||||
|
@ -41,7 +41,7 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{% if enableDownload -%}
|
||||
{% if enableDownload and files.length -%}
|
||||
<div class="level-right">
|
||||
<p class="level-item">
|
||||
<a class="button is-primary is-outlined" title="Download album" href="../api/album/zip/{{ identifier }}?v={{ editedAt }}">Download Album</a>
|
||||
@ -49,7 +49,7 @@
|
||||
</div>
|
||||
{%- endif %}
|
||||
</nav>
|
||||
{% if enableDownload -%}
|
||||
{% if enableDownload and files.length -%}
|
||||
<article class="message">
|
||||
<div class="message-body">
|
||||
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 -%}
|
||||
<article class="message">
|
||||
<div class="message-body">
|
||||
There is nothing here yet!
|
||||
There are no files in the album.
|
||||
</div>
|
||||
</article>
|
||||
{%- endif %}
|
||||
|
Loading…
Reference in New Issue
Block a user