implementing download for bulk_download events

This commit is contained in:
Stefan Tobler 2024-02-19 14:03:26 -05:00 committed by psychedelicious
parent 9db7e073a3
commit 8d9c566656
5 changed files with 84 additions and 3 deletions

View File

@ -426,6 +426,8 @@
"downloadSelection": "Download Selection",
"preparingDownload": "Preparing Download",
"preparingDownloadFailed": "Problem Preparing Download",
"bulkDownloadStarting": "Beginning Download",
"bulkDownloadFailed": "Problem Preparing Download",
"problemDeletingImages": "Problem Deleting Images",
"problemDeletingImagesDesc": "One or more images could not be deleted"
},

View File

@ -48,6 +48,8 @@ import { addInitialImageSelectedListener } from './listeners/initialImageSelecte
import { addModelSelectedListener } from './listeners/modelSelected';
import { addModelsLoadedListener } from './listeners/modelsLoaded';
import { addDynamicPromptsListener } from './listeners/promptChanged';
import { addBulkDownloadCompleteEventListener } from './listeners/socketio/socketBulkDownloadComplete';
import { addBulkDownloadFailedEventListener } from './listeners/socketio/socketBulkDownloadFailed';
import { addSocketConnectedEventListener as addSocketConnectedListener } from './listeners/socketio/socketConnected';
import { addSocketDisconnectedEventListener as addSocketDisconnectedListener } from './listeners/socketio/socketDisconnected';
import { addGeneratorProgressEventListener as addGeneratorProgressListener } from './listeners/socketio/socketGeneratorProgress';
@ -137,6 +139,8 @@ addModelLoadEventListener();
addSessionRetrievalErrorEventListener();
addInvocationRetrievalErrorEventListener();
addSocketQueueItemStatusChangedEventListener();
addBulkDownloadCompleteEventListener();
addBulkDownloadFailedEventListener();
// ControlNet
addControlNetImageProcessedListener();

View File

@ -0,0 +1,41 @@
import { logger } from 'app/logging/logger';
import { addToast } from 'features/system/store/systemSlice';
import { t } from 'i18next';
import { socketBulkDownloadCompleted } from 'services/events/actions';
import { startAppListening } from '../..';
const log = logger('socketio');
export const addBulkDownloadCompleteEventListener = () => {
startAppListening({
actionCreator: socketBulkDownloadCompleted,
effect: async (action, { dispatch }) => {
log.debug(action.payload, 'Bulk download complete');
const bulk_download_item_name = action.payload.data.bulk_download_item_name;
const url = `/api/v1/images/download/${bulk_download_item_name}`;
const a = document.createElement('a');
a.style.display = 'none';
a.href = url;
a.download = bulk_download_item_name;
document.body.appendChild(a);
a.click();
dispatch(
addToast({
title: t('gallery.bulkDownloadStarting'),
status: 'success',
...(action.payload
? {
description: bulk_download_item_name,
duration: null,
isClosable: true,
}
: {}),
})
);
},
});
};

View File

@ -0,0 +1,32 @@
import { logger } from 'app/logging/logger';
import { addToast } from 'features/system/store/systemSlice';
import { t } from 'i18next';
import { socketBulkDownloadFailed } from 'services/events/actions';
import { startAppListening } from '../..';
const log = logger('socketio');
export const addBulkDownloadFailedEventListener = () => {
startAppListening({
actionCreator: socketBulkDownloadFailed,
effect: async (action, { dispatch }) => {
log.debug(action.payload, 'Bulk download error');
dispatch(
addToast({
title: t('gallery.bulkDownloadFailed'),
status: 'error',
...(action.payload
? {
description: action.payload.data.error,
duration: null,
isClosable: true,
}
: {}),
})
);
},
});
};

View File

@ -156,7 +156,7 @@ export type InvocationRetrievalErrorEvent = {
*
* @example socket.on('queue_item_status_changed', (data: QueueItemStatusChangedEvent) => { ... }
*/
export type QueueItemStatusChangedEvent = {
export type QueueItemStatusChangedEvent = {
queue_id: string;
queue_item: {
queue_id: string;
@ -191,7 +191,7 @@ export type QueueItemStatusChangedEvent = {
failed: number;
canceled: number;
total: number;
};
};
};
export type ClientEmitSubscribeQueue = {
@ -205,6 +205,7 @@ export type ClientEmitUnsubscribeQueue = {
export type BulkDownloadStartedEvent = {
bulk_download_id: string;
bulk_download_item_id: string;
bulk_download_item_name: string;
};
export type BulkDownloadCompletedEvent = {
@ -216,8 +217,9 @@ export type BulkDownloadCompletedEvent = {
export type BulkDownloadFailedEvent = {
bulk_download_id: string;
bulk_download_item_id: string;
bulk_download_item_name: string;
error: string;
}
};
export type ClientEmitSubscribeBulkDownload = {
bulk_download_id: string;