Skip to content

Commit

Permalink
Auto parse lens ID from filename
Browse files Browse the repository at this point in the history
  • Loading branch information
ptrumpis committed Mar 5, 2024
1 parent 7929a4a commit cb21ea8
Showing 1 changed file with 26 additions and 2 deletions.
28 changes: 26 additions & 2 deletions script.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,17 +61,41 @@ function importFiles(apiPath, formData) {
xhr.send(formData);
}

function parseLensId(path) {
const regex = /(?:^|\/)(\d{11,16})(?:_|\.|$)/;
const match = path.match(regex);
if (match) {
const numericValue = parseInt(match[1], 10);
if (!isNaN(numericValue)) {
return numericValue;
}
}
return null;
}

function addNewLensUploadGroup() {
const clone = document.importNode(lensUploadGroup.content, true);
lensUploadGroups.appendChild(clone);

const fileInput = lensUploadGroups.lastElementChild.querySelector('input[type=file]');
const lensIdInput = fileInput.closest('.upload-group').querySelector('input[name="id[]"]');

uppie(fileInput, (event, formData, files) => {
files.forEach(path => {
const id = parseLensId(path);
if (!lensIdInput.value && id) {
lensIdInput.value = id;
}
});
});
}

uppie(cacheImportDropZone, (event, fd, files) => {
uppie(cacheImportDropZone, (event, formData, files) => {
files.forEach(path => {
cacheImportFileList.innerHTML += path + '\r\n';
});

for (const value of fd.values()) {
for (const value of formData.values()) {
cacheImportForm.append('file[]', value, value.name);
}
});
Expand Down

0 comments on commit cb21ea8

Please sign in to comment.