Skip to content

Commit

Permalink
[Update] API doc
Browse files Browse the repository at this point in the history
  • Loading branch information
GeoffreyChen777 committed Mar 24, 2024
1 parent 3a18b75 commit 40249e1
Show file tree
Hide file tree
Showing 6 changed files with 99 additions and 17 deletions.
1 change: 1 addition & 0 deletions app/main/services/contextmenu-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ export class ContextMenuService extends Eventable<IContextMenuServiceState> {
/**
* Shows the context menu for paper data.
* @param {boolean} allowEdit - Whether editing is allowed.
* @param {CategorizerMenuItem[]} categorizeList - The list of categorizers.
*/
@errorcatching(
"Failed to show the contextmenu for papers.",
Expand Down
2 changes: 2 additions & 0 deletions app/renderer/services/file-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,8 @@ export class FileService extends Eventable<IFileServiceState> {
/**
* Move files of a paper entity to the library folder
* @param paperEntity - Paper entity to move
* @param moveMain - Move the main file
* @param moveSups - Move the supplementary files
* @returns
*/
async move(
Expand Down
24 changes: 24 additions & 0 deletions app/renderer/services/paper-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -443,6 +443,19 @@ export class PaperService extends Eventable<IPaperServiceState> {
await this.update(paperEntityDrafts, false, true);
}

/**
* Update the main file of a paper entity.
* @param paperEntity - The paper entity.
* @param url - The URL of the main file.
* @returns The updated paper entity.
*/
@processing(ProcessingKey.General)
@errorcatching(
"Failed to update paper entitiy's main file.",
true,
"PaperService",
[]
)
async updateMainURL(paperEntity: PaperEntity, url: string) {
if (this._databaseCore.getState("dbInitializing")) {
return;
Expand All @@ -460,6 +473,17 @@ export class PaperService extends Eventable<IPaperServiceState> {
return updatedPaperEntities[0];
}

/**
* Update the supplementary files of a paper entity.
* @param paperEntity - The paper entity.
* @param urls - The URLs of the supplementary files.
*/
@processing(ProcessingKey.General)
@errorcatching(
"Failed to update paper entity's supplementary files.",
true,
"PaperService"
)
async updateSupURLs(paperEntity: PaperEntity, urls: string[]) {
if (this._databaseCore.getState("dbInitializing")) {
return;
Expand Down
11 changes: 9 additions & 2 deletions app/repositories/file-repository/local-backend.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,10 @@ export class LocalFileBackend implements IFileBackend {
}
}

/**
* Check base folder, if not exist, create it.
* @param folderPath - Folder path
*/
async checkBaseFolder(folderPath: string): Promise<void> {
const _folderPath = eraseProtocol(folderPath);
if (!existsSync(_folderPath)) {
Expand All @@ -107,8 +111,6 @@ export class LocalFileBackend implements IFileBackend {
* Move file from sourceURL to targetURL
* @param sourceURL - Source URL, also can be a file name in the app library folder
* @param targetURL - Target URL, also can be a file name in the app library folder
* @param forceDelete - Force delete source file
* @param forceNotLink - Force not to use link
* @returns Target file name in the app library folder
*/
async moveFile(sourceURL: string, targetURL: string): Promise<string> {
Expand Down Expand Up @@ -139,6 +141,11 @@ export class LocalFileBackend implements IFileBackend {
}
}

/**
* Remove file from sourceURL
* @param sourceURL - Source URL, also can be a file name in the app library folder
* @returns void
*/
async removeFile(sourceURL: string): Promise<void> {
sourceURL = constructFileURL(sourceURL, true, false, this._appLibFolder);
if (existsSync(sourceURL)) {
Expand Down
72 changes: 60 additions & 12 deletions paperlib-api/dist/api.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { OpenDialogReturnValue } from 'electron';
import { default as Realm_2 } from 'realm';
import { Results } from 'realm';
import { Store } from 'pinia';
import Watcher from 'watcher';
import { XMLParser } from 'fast-xml-parser';

declare enum APPTheme {
Expand Down Expand Up @@ -132,6 +133,12 @@ declare class Categorizer {
initialize(object: ICategorizerDraft): this;
}

declare type CategorizerMenuItem = {
type: CategorizerType;
name: string;
id: OID;
};

declare class CategorizerRepository extends Eventable<ICategorizerRepositoryState> {
constructor();
/**
Expand Down Expand Up @@ -326,8 +333,9 @@ declare class ContextMenuService extends Eventable<IContextMenuServiceState> {
/**
* Shows the context menu for paper data.
* @param {boolean} allowEdit - Whether editing is allowed.
* @param {CategorizerMenuItem[]} categorizeList - The list of categorizers.
*/
showPaperDataMenu(allowEdit: boolean): void;
showPaperDataMenu(allowEdit: boolean, categorizeList: CategorizerMenuItem[]): void;
/**
* Shows the context menu for feed data.
*/
Expand Down Expand Up @@ -964,6 +972,7 @@ declare class FileService extends Eventable<IFileServiceState> {
*/
initialize(): Promise<void>;
private _initBackend;
backend(): Promise<IFileBackend>;
/**
* Start watching file changes. (Only for WebDAV file backend)
*/
Expand All @@ -976,23 +985,26 @@ declare class FileService extends Eventable<IFileServiceState> {
* Check if the file backend is available.
*/
check(): Promise<boolean | undefined>;
/**
* Infer the relative path of a paper entity.
* @param paperEntity - Paper entity to infer the relative path
*/
inferRelativeFileName(paperEntity: PaperEntity): Promise<string>;
/**
* Move files of a paper entity to the library folder
* @param paperEntity - Paper entity to move
* @param fourceDelete - Force to delete the source file
* @param forceNotLink - Force to do not use link
* @param moveMain - Move the main file
* @param moveSups - Move the supplementary files
* @returns
*/
move(paperEntity: PaperEntity, fourceDelete?: boolean, forceNotLink?: boolean): Promise<PaperEntity>;
move(paperEntity: PaperEntity, moveMain?: boolean, moveSups?: boolean): Promise<PaperEntity>;
/**
* Move a file
* @param sourceURL - Source file URL
* @param targetURL - Target file URL
* @param fourceDelete - Force to delete the source file
* @param forceNotLink - Force to do not use link
* @returns
*/
moveFile(sourceURL: string, targetURL: string, fourceDelete?: boolean, forceNotLink?: boolean): Promise<string>;
moveFile(sourceURL: string, targetURL: string): Promise<string>;
/**
* Remove files of a paper entity
* @param paperEntity - Paper entity to remove
Expand Down Expand Up @@ -1175,6 +1187,10 @@ declare interface ICommand {
}

declare interface IContextMenuServiceState {
dataContextMenuRemoveFromClicked: {
type: CategorizerType;
id: OID;
};
dataContextMenuScrapeFromClicked: string;
dataContextMenuOpenClicked: number;
dataContextMenuShowInFinderClicked: number;
Expand Down Expand Up @@ -1345,9 +1361,21 @@ declare interface IFeedServiceState {
entitiesUpdated: number;
}

declare interface IFileBackend {
watcher?: Watcher;
check(): Promise<boolean>;
access(url: string, download: boolean): Promise<string>;
startWatch(): Promise<void>;
stopWatch(): Promise<void>;
moveFile(sourceURL: string, targetURL: string): Promise<string>;
removeFile(sourceURL: string): Promise<void>;
}

declare interface IFileServiceState {
backend: string;
available: boolean;
backendInitializing: boolean;
backendInitialized: boolean;
}

declare interface ILogEventState {
Expand Down Expand Up @@ -1391,6 +1419,7 @@ declare interface IMenuServiceState {
"View-preview": number;
"View-next": number;
"View-previous": number;
"File-delete": number;
}

declare type IPaperEntityCollection = Results<IPaperEntityObject> | List<IPaperEntityObject> | Array<IPaperEntityObject>;
Expand Down Expand Up @@ -1500,6 +1529,7 @@ declare interface IPreferenceStore {
shortcutEdit: string;
shortcutFlag: string;
shortcutCopyKey: string;
shortcutDelete: string;
sidebarWidth: number;
detailPanelWidth: number;
mainviewSortBy: string;
Expand Down Expand Up @@ -1663,11 +1693,18 @@ declare class MenuService extends Eventable<IMenuServiceState> {
* @param key
*/
click(key: keyof IMenuServiceState): void;
/**
* Enable all global shortcuts.
*/
enableGlobalShortcuts(): void;
}

declare class NetworkTool {
private _agent;
private _donwloadProgress;
private _caCert;
private _caClientKey;
private _caClinetCert;
constructor();
/**
* Set proxy agent
Expand Down Expand Up @@ -1862,13 +1899,11 @@ declare class PaperEntityRepository extends Eventable<IPaperEntityRepositoryStat
* Update paper entity.
* @param realm - Realm instance.
* @param paperEntity - Paper entity.
* @param paperTag - Paper tags.
* @param paperFolder - Paper folders.
* @param existingPaperEntity - Existing paper entity.
* @param partition - Partition.
* @param allowUpdate - Allow update flag.
* @returns - Updated boolean flag.
*/
update(realm: Realm_2, paperEntity: IPaperEntityObject, partition: string): boolean;
update(realm: Realm_2, paperEntity: IPaperEntityObject, partition: string, allowUpdate?: boolean): boolean;
/**
* Delete paper entity.
* @param realm - Realm instance.
Expand Down Expand Up @@ -1926,7 +1961,7 @@ declare class PaperService extends Eventable<IPaperServiceState> {
* Update paper entities.
* @param paperEntityDrafts - paper entity drafts
* @param updateCache - Update cache, default is true
* @param isUpdate - Is update, default is false, if true, it is insert. This is for PDF file operation.
* @param isUpdate - Is update, default is false, if false, it is insert. This is for preventing insert duplicated papers.
* @returns Updated paper entities
*/
update(paperEntityDrafts: IPaperEntityCollection, updateCache?: boolean, isUpdate?: boolean): Promise<IPaperEntityCollection>;
Expand All @@ -1937,6 +1972,19 @@ declare class PaperService extends Eventable<IPaperServiceState> {
* @param type - The type of the categorizer.
*/
updateWithCategorizer(ids: OID[], categorizer: Categorizer, type: CategorizerType): Promise<void>;
/**
* Update the main file of a paper entity.
* @param paperEntity - The paper entity.
* @param url - The URL of the main file.
* @returns The updated paper entity.
*/
updateMainURL(paperEntity: PaperEntity, url: string): Promise<PaperEntity | undefined>;
/**
* Update the supplementary files of a paper entity.
* @param paperEntity - The paper entity.
* @param urls - The URLs of the supplementary files.
*/
updateSupURLs(paperEntity: PaperEntity, urls: string[]): Promise<void>;
/**
* Delete paper entities.
* @param ids - Paper entity ids
Expand Down
6 changes: 3 additions & 3 deletions paperlib-api/dist/utils.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -153,12 +153,12 @@ function constructFileURL(url, joined, withProtocol = true, root = "", protocol
}
if (withProtocol) {
if (outURL.startsWith(protocol)) {
return outURL;
return outURL.replace(/\\/g, "/");
} else {
return protocol + outURL;
return (protocol + outURL).replace(/\\/g, "/");
}
} else {
return outURL.replace(protocol, "");
return outURL.replace(protocol, "").replace(/\\/g, "/");
}
}
function listAllFiles(folderURL, arrayOfFiles = null) {
Expand Down

0 comments on commit 40249e1

Please sign in to comment.