Skip to content

Commit

Permalink
refactor(API): switch lcp (renew,return,unlock) to redux-saga logic
Browse files Browse the repository at this point in the history
delete LCP API
(FIxes #1992)
  • Loading branch information
panaC committed Sep 7, 2023
1 parent 93a79a3 commit 2374d85
Show file tree
Hide file tree
Showing 18 changed files with 272 additions and 175 deletions.
2 changes: 0 additions & 2 deletions src/common/api/api.type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,13 @@
// ==LICENSE-END==

import { ICatalogModuleApi } from "./interface/catalog.interface";
import { ILcpModuleApi } from "./interface/lcpApi.interface";
import { IOpdsModuleApi } from "./interface/opdsApi.interface";
import { IApiappModuleApi } from "./interface/apiappApi.interface";
import { IHttpBrowserModuleApi } from "./interface/httpBrowser.interface";
import { IPublicationModuleApi } from "./interface/publicationApi.interface";

export type TApiMethod =
ICatalogModuleApi &
ILcpModuleApi &
IOpdsModuleApi &
IApiappModuleApi &
IHttpBrowserModuleApi &
Expand Down
18 changes: 0 additions & 18 deletions src/common/api/interface/lcpApi.interface.ts

This file was deleted.

4 changes: 1 addition & 3 deletions src/common/api/methodApi.type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

import { IHttpBrowserApi } from "./interface/httpBrowser.interface";
import { ICatalogApi } from "./interface/catalog.interface";
import { ILcpApi } from "./interface/lcpApi.interface";
import { IOpdsApi } from "./interface/opdsApi.interface";
import { IPublicationApi } from "./interface/publicationApi.interface";
import { IApiappApi } from "./interface/apiappApi.interface";
Expand All @@ -17,5 +16,4 @@ export type TMethodApi =
keyof IPublicationApi |
keyof IOpdsApi |
keyof IApiappApi |
keyof IHttpBrowserApi |
keyof ILcpApi
keyof IHttpBrowserApi
4 changes: 1 addition & 3 deletions src/common/api/moduleApi.type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,9 @@ type TPublicationApi = "publication";
type TOpdsApi = "opds";
type TApiappApi = "apiapp";
type THttpBrowserApi = "httpbrowser";
type TLcpApi = "lcp";
export type TModuleApi =
TCatalogApi |
TPublicationApi |
TOpdsApi |
TApiappApi |
THttpBrowserApi |
TLcpApi
THttpBrowserApi
6 changes: 6 additions & 0 deletions src/common/redux/actions/lcp/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,13 @@
// ==LICENSE-END==

import * as userKeyCheckRequest from "./user-key-check-request";
import * as renewPublicationLicense from "./renewPublicationLicense";
import * as returnPublication from "./returnPublication";
import * as unlockPublicationWithPassphrase from "./unlockPublicationWithPassphrase";

export {
userKeyCheckRequest,
renewPublicationLicense,
returnPublication,
unlockPublicationWithPassphrase,
};
29 changes: 29 additions & 0 deletions src/common/redux/actions/lcp/renewPublicationLicense.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// ==LICENSE-BEGIN==
// Copyright 2017 European Digital Reading Lab. All rights reserved.
// Licensed to the Readium Foundation under one or more contributor license agreements.
// Use of this source code is governed by a BSD-style license
// that can be found in the LICENSE file exposed on Github (readium) in the project repository.
// ==LICENSE-END==

import { Action } from "readium-desktop/common/models/redux";

export const ID = "LCP_RENEW_PUBLICATION_LICENSE";

export interface Payload {
publicationIdentifier: string;
}

export function build(
publicationIdentifier: string,
):
Action<typeof ID, Payload> {

return {
type: ID,
payload: {
publicationIdentifier,
},
};
}
build.toString = () => ID; // Redux StringableActionCreator
export type TAction = ReturnType<typeof build>;
29 changes: 29 additions & 0 deletions src/common/redux/actions/lcp/returnPublication.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// ==LICENSE-BEGIN==
// Copyright 2017 European Digital Reading Lab. All rights reserved.
// Licensed to the Readium Foundation under one or more contributor license agreements.
// Use of this source code is governed by a BSD-style license
// that can be found in the LICENSE file exposed on Github (readium) in the project repository.
// ==LICENSE-END==

import { Action } from "readium-desktop/common/models/redux";

export const ID = "LCP_RETURN_PUBLICATION";

export interface Payload {
publicationIdentifier: string;
}

export function build(
publicationIdentifier: string,
):
Action<typeof ID, Payload> {

return {
type: ID,
payload: {
publicationIdentifier,
},
};
}
build.toString = () => ID; // Redux StringableActionCreator
export type TAction = ReturnType<typeof build>;
32 changes: 32 additions & 0 deletions src/common/redux/actions/lcp/unlockPublicationWithPassphrase.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// ==LICENSE-BEGIN==
// Copyright 2017 European Digital Reading Lab. All rights reserved.
// Licensed to the Readium Foundation under one or more contributor license agreements.
// Use of this source code is governed by a BSD-style license
// that can be found in the LICENSE file exposed on Github (readium) in the project repository.
// ==LICENSE-END==

import { Action } from "readium-desktop/common/models/redux";

export const ID = "LCP_UNLOCK_PUBLICATION_WITH_PASS";

export interface Payload {
publicationIdentifier: string;
passphrase: string;
}

export function build(
publicationIdentifier: string,
passphrase: string,
):
Action<typeof ID, Payload> {

return {
type: ID,
payload: {
publicationIdentifier,
passphrase,
},
};
}
build.toString = () => ID; // Redux StringableActionCreator
export type TAction = ReturnType<typeof build>;
112 changes: 0 additions & 112 deletions src/main/api/lcp.ts

This file was deleted.

4 changes: 0 additions & 4 deletions src/main/di.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import * as path from "path";
import { Translator } from "readium-desktop/common/services/translator";
import { ok } from "readium-desktop/common/utils/assert";
import { CatalogApi } from "readium-desktop/main/api/catalog";
import { LcpApi } from "readium-desktop/main/api/lcp";
import { LocatorViewConverter } from "readium-desktop/main/converter/locator";
import { OpdsFeedViewConverter } from "readium-desktop/main/converter/opds";
import { PublicationViewConverter } from "readium-desktop/main/converter/publication";
Expand Down Expand Up @@ -227,8 +226,6 @@ container.bind(diSymbolTable["opds-api"]).toConstantValue(opdsApi);
container.bind(diSymbolTable["apiapp-api"]).toConstantValue(apiappApi);
container.bind(diSymbolTable["httpbrowser-api"]).toConstantValue(httpBrowserApi);

container.bind<LcpApi>(diSymbolTable["lcp-api"]).to(LcpApi).inSingletonScope();

let libraryWin: BrowserWindow;

const saveLibraryWindowInDi =
Expand Down Expand Up @@ -279,7 +276,6 @@ interface IGet {
(s: "opds-api"): typeof opdsApi;
(s: "apiapp-api"): typeof apiappApi;
(s: "httpbrowser-api"): typeof httpBrowserApi;
(s: "lcp-api"): LcpApi;
(s: "saga-middleware"): SagaMiddleware;
// minor overload type used in api.ts/LN32
(s: keyof typeof diSymbolTable): any;
Expand Down
2 changes: 2 additions & 0 deletions src/main/redux/middleware/sync.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ const SYNCHRONIZABLE_ACTIONS: string[] = [
authActions.cancel.ID,

sessionActions.enable.ID,

lcpActions.unlockPublicationWithPassphrase.ID,
];

export const reduxSyncMiddleware: Middleware
Expand Down
4 changes: 4 additions & 0 deletions src/main/redux/sagas/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import * as reader from "./reader";
import * as streamer from "./streamer";
import * as win from "./win";
import * as telemetry from "./telemetry";
import * as lcp from "./lcp";

// Logger
const filename_ = "readium-desktop:main:saga:app";
Expand Down Expand Up @@ -95,6 +96,9 @@ export function* rootSaga() {
// OPDS authentication flow
yield auth.saga();

// LCP saga
yield lcp.saga();

// rehydrate shorcuts in redux
yield put(keyboardActions.setShortcuts.build(keyboardShortcuts.getAll(), false));

Expand Down
Loading

0 comments on commit 2374d85

Please sign in to comment.