Move user_picture.js to webpack

* Fix relative path generation in webpack
* remove vendored/native-file-system-adapter
* remove vendored/zip.js
This commit is contained in:
2024-10-09 00:19:14 +02:00
committed by Bartuccio Antoine
parent b969513d94
commit ceee393bd8
34 changed files with 5883 additions and 5876 deletions

View File

@ -5,11 +5,7 @@
{%- endblock -%}
{% block additional_js %}
<script defer type="module">
import { showSaveFilePicker } from "{{ static('vendored/native-file-system-adapter/mod.js') }}";
window.showSaveFilePicker = showSaveFilePicker; /* Export function to normal javascript */
</script>
<script defer type="text/javascript" src="{{ static('vendored/zipjs/zip-fs-full.min.js') }}"></script>
<script src="{{ static('webpack/users/pictures-index.js') }}" defer></script>
{% endblock %}
{% block title %}
@ -65,77 +61,8 @@
{{ super() }}
<script>
/**
* @typedef UserProfile
* @property {number} id
* @property {string} first_name
* @property {string} last_name
* @property {string} nick_name
* @property {string} display_name
* @property {string} profile_url
* @property {string} profile_pict
*/
/**
* @typedef Picture
* @property {number} id
* @property {string} name
* @property {number} size
* @property {string} date
* @property {UserProfile} owner
* @property {string} full_size_url
* @property {string} compressed_url
* @property {string} thumb_url
* @property {string} album
* @property {boolean} is_moderated
* @property {boolean} asked_for_removal
*/
document.addEventListener("alpine:init", () => {
Alpine.data("user_pictures", () => ({
isDownloading: false,
loading: true,
pictures: [],
albums: {},
async init() {
this.pictures = await fetchPaginated("{{ url("api:pictures") }}" + "?users_identified={{ object.id }}");
this.albums = this.pictures.reduce((acc, picture) => {
if (!acc[picture.album]){
acc[picture.album] = [];
}
acc[picture.album].push(picture);
return acc;
}, {});
this.loading = false;
},
async downloadZip(){
this.isDownloading = true;
const bar = this.$refs.progress;
bar.value = 0;
bar.max = this.pictures.length;
const fileHandle = await window.showSaveFilePicker({
_preferPolyfill: false,
suggestedName: "{%- trans -%} pictures {%- endtrans -%}.zip",
types: {},
excludeAcceptAllOption: false,
})
const zipWriter = new zip.ZipWriter(await fileHandle.createWritable());
await Promise.all(this.pictures.map(p => {
const imgName = p.album + "/IMG_" + p.date.replaceAll(/[:\-]/g, "_") + p.name.slice(p.name.lastIndexOf("."));
return zipWriter.add(
imgName,
new zip.HttpReader(p.full_size_url),
{level: 9, lastModDate: new Date(p.date), onstart: () => bar.value += 1}
);
}));
await zipWriter.close();
this.isDownloading = false;
}
}))
});
window.addEventListener("DOMContentLoaded", () => {
loadPicturePage("{{ url("api:pictures") }}" + "?users_identified={{ object.id }}");
})
</script>
{% endblock script %}