Skip to content

Commit

Permalink
FIX: published abort case (#21)
Browse files Browse the repository at this point in the history
* FIX: published abort case

* new version
  • Loading branch information
augustovicente authored Jul 4, 2024
1 parent 40adf5d commit 4a95a38
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@issuu/issuu-api-sdk",
"version": "0.0.19",
"version": "0.0.20",
"type": "module",
"license": "MIT",
"scripts": {
Expand Down
11 changes: 8 additions & 3 deletions src/controllers/draft.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -269,19 +269,19 @@ export const draft = {
abortController?: AbortController,
): Promise<CreateAndPublishDraftResponse | void>
{
let savedDraft: CreateNewDraftResponse | UpdateDraftBySlugResponse, result: PublishDraftBySlugResponse, isAborted = false;
let savedDraft: CreateNewDraftResponse | UpdateDraftBySlugResponse, result: PublishDraftBySlugResponse, isAborted = false, isPublished = false;
progressCallback?.(0);

// setup abort controller
if(abortController) {
abortController.signal.addEventListener('abort', async () => {
if(!savedDraft) return;
else if(savedDraft && !result) {
else if(savedDraft && !isPublished) {
if (!!options?.shouldDeleteOnAbort && !!savedDraft.slug) {
await this.deleteDraftBySlug(savedDraft.slug, abortController);
}
isAborted = true;
} else if(savedDraft && result) {
} else if(savedDraft && isPublished) {
if (!!options?.shouldDeleteOnAbort && !!result.slug) {
await publication.deletePublicationBySlug(result.slug, abortController);
}
Expand All @@ -298,6 +298,10 @@ export const draft = {
}
progressCallback?.(20);

if (savedDraft.state === 'PUBLISHED') {
isPublished = true;
}

// Until 70%
if(isAborted) return progressCallback?.(100);
await this.uploadDocumentToDraftBySlug(
Expand Down Expand Up @@ -329,6 +333,7 @@ export const draft = {
options,
abortController
);
isPublished = true;
// Until 100%
progressCallback?.(100);

Expand Down
2 changes: 1 addition & 1 deletion types/draft.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ interface UpdateDraftBySlugRequest {
fileUrl?: string;
info?: DocumentInformation;
}
interface UpdateDraftBySlugResponse extends CreateNewDraftResponse {};
interface UpdateDraftBySlugResponse extends Document {};

interface UploadDocumentToDraftBySlugRequest {
file: Blob;
Expand Down

0 comments on commit 4a95a38

Please sign in to comment.