mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-06-05 21:59:27 +02:00
Fix cross-tab file drag and drop
This commit is contained in:
@@ -6663,6 +6663,28 @@ function importCharacter(file) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function importFromURL(items, files) {
|
||||||
|
for (const item of items) {
|
||||||
|
if (item.type === 'text/uri-list') {
|
||||||
|
const uriList = await new Promise((resolve) => {
|
||||||
|
item.getAsString((uriList) => { resolve(uriList); });
|
||||||
|
});
|
||||||
|
const uris = uriList.split('\n').filter(uri => uri.trim() !== '');
|
||||||
|
try {
|
||||||
|
for (const uri of uris) {
|
||||||
|
const request = await fetch(uri);
|
||||||
|
const data = await request.blob();
|
||||||
|
const fileName = request.headers.get('Content-Disposition')?.split('filename=')[1]?.replace(/"/g, '') || uri.split('/').pop() || 'file.png';
|
||||||
|
const file = new File([data], fileName, { type: data.type });
|
||||||
|
files.push(file);
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Failed to import from URL', error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const isPwaMode = window.navigator.standalone;
|
const isPwaMode = window.navigator.standalone;
|
||||||
if (isPwaMode) { $("body").addClass('PWA') }
|
if (isPwaMode) { $("body").addClass('PWA') }
|
||||||
|
|
||||||
@@ -8409,12 +8431,13 @@ $(document).ready(function () {
|
|||||||
$dropzone.removeClass('dragover');
|
$dropzone.removeClass('dragover');
|
||||||
});
|
});
|
||||||
|
|
||||||
$dropzone.on('drop', (event) => {
|
$dropzone.on('drop', async (event) => {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
event.stopPropagation();
|
event.stopPropagation();
|
||||||
$dropzone.removeClass('dragover');
|
$dropzone.removeClass('dragover');
|
||||||
|
|
||||||
const files = event.originalEvent.dataTransfer.files;
|
const files = Array.from(event.originalEvent.dataTransfer.files);
|
||||||
|
await importFromURL(event.originalEvent.dataTransfer.items, files);
|
||||||
processDroppedFiles(files);
|
processDroppedFiles(files);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user