Skip to content

Commit

Permalink
Bit of cleanup, fixed album creation
Browse files Browse the repository at this point in the history
  • Loading branch information
zarya committed Nov 19, 2024
1 parent 40a734e commit 323d5f9
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 27 deletions.
4 changes: 0 additions & 4 deletions src/files/templates/upload.html
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,6 @@
<span class="sr-only">Loading...</span>
</button>
<script src={% static 'js/upload.js' %}></script>
<img id="preview">
<div class="progress" role="progressbar" aria-label="Progress" aria-valuenow="0" aria-valuemin="0" aria-valuemax="100">
<div class="progress-bar" style="width: 0%"></div>
</div>
<div class="modal fade" id="image-editor-modal" tabindex="-1" aria-labelledby="ImageEditorModalLabel" aria-hidden="true">
<div class="modal-dialog modal-fullscreen">
<div class="modal-content">
Expand Down
2 changes: 1 addition & 1 deletion src/static_src/js/grinder.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ UC.onFinished = (active) => {
}

UC.onDeQueue = (active, jobs, current, total, _element) => {
UC.log(`Active jobs: ${active} left in Queue: ${jobs} Current: ${current} Total: ${total}`)
console.log(`Active jobs: ${active} left in Queue: ${jobs} Current: ${current} Total: ${total}`)
if (jobs > 0) {
const pct = ((current - jobs + 1)/current*100);
document.getElementsByClassName('progress-bar').item(0).setAttribute('aria-valuenow', pct);
Expand Down
22 changes: 6 additions & 16 deletions src/static_src/js/upload.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,12 @@ const UC = new UploadClient(client_id, () => {
console.log("Loaded UC client");
});

UC.onDeQueue = (active, jobs, current, total, _element) => {
UC.log(`Active jobs: ${active} left in Queue: ${jobs} Current: ${current} Total: ${total}`)
if (jobs > 0) {
const pct = ((current - jobs + 1)/current*100);
document.getElementsByClassName('progress-bar').item(0).setAttribute('aria-valuenow', pct);
document.getElementsByClassName('progress-bar').item(0).setAttribute('style','width:'+Number(pct)+'%');
}
}

//Init base variables
var dropzone = undefined;
var ImageEditorModal = undefined;
var ImageEditor = undefined;
var ImageEditorOrgFile = undefined;
var ImageUploadList = [];
tui.usageStatistics = false

jQuery(document).ready(function () {
Expand Down Expand Up @@ -154,10 +146,9 @@ jQuery(document).ready(function () {
dropzone.on("success", file => {
const resp = JSON.parse(file.xhr.response);
const uuid = resp.bma_response.uuid;
const source_url = resp.bma_response.links.downloads.original;

//Queue file for jobs fetching and processing
UC.addUploadedFile(uuid, source_url, file);
//Append images to make album when done
ImageUploadList.push(uuid)

//Make BMA scripts happy
const index = formdatas.indexOf(file.name);
Expand All @@ -166,20 +157,19 @@ jQuery(document).ready(function () {
}
//Trigger BMA script enableUploadButton
enableUploadButton();

UC.startGrinder();
});

//Event triggered after its done uploading a batch
dropzone.on("complete", _file => {
UC.processNextJob();
dropzone.processQueue();
})

//Event triggered after its done uploading
dropzone.on("queuecomplete", _file => {
const now = new Date;
UC.createAlbum(`Uploaded ${now.toISOString()}`,"")
console.log("Adding album for", ImageUploadList)
UC.createAlbum(`Uploaded ${now.toISOString()}`,"", ImageUploadList);
ImageUploadList = [];
})
});

Expand Down
20 changes: 14 additions & 6 deletions src/static_src/js/uploadClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class UploadClient {
this.bma_version = JSON.parse(document.getElementById('bma_version').textContent);
this.client_version = `js-client - BMA ${this.bma_version}`;
this.activeJobs = 0;
this.maxConcurrent = 6;
this.maxConcurrent = 2;
this.skip_jobs = [];
this.source_file_store = {};
this.job_queue = [];
Expand Down Expand Up @@ -293,7 +293,14 @@ class UploadClient {
"Authorization": `Bearer ${this.oauth.token}`,
},
});
return { url: file_url, file: await result.blob() }
const file = await result.blob();
const header = result.headers.get('Content-Disposition');
const parts = header.split(';');
const filename = parts[1].split('=')[1];
if (filename.endsWith(".webp\"")) {
return { url: file_url, file: new Blob([file], {type:"image/webp"})}
}
return { url: file_url, file: file }
} catch (error) {
console.log(error.message);
return [];
Expand Down Expand Up @@ -457,15 +464,16 @@ class UploadClient {
*
* @param {string} name - Name of the album.
* @param {string} description - Description of the album.
* @param {array} files - List of file uuids to create a album with.
* @returns {array} bma_response
*/
async createAlbum(name, description) {
var data = {
async createAlbum(name, description, files = this.finished) {
const data = {
'title': name,
'description': description,
'files': this.finished,
'files': files,
}
if (this.finished.length === 0) return
if (files.length === 0) return
try {
const response = await fetch(`/api/v1/json/albums/create/`, {
headers: {
Expand Down

0 comments on commit 323d5f9

Please sign in to comment.