picgo 2.0.3 → 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/AGENTS.md +4 -1
- package/CLAUDE.md +1 -0
- package/CONTEXT.md +53 -0
- package/README.md +57 -2
- package/dist/core/Lifecycle.d.ts +4 -2
- package/dist/core/PicGo.d.ts +2 -2
- package/dist/i18n/zh-CN.d.ts +62 -0
- package/dist/index.cjs.js +1 -1
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.esm.js +1 -1
- package/dist/index.esm.js.map +1 -1
- package/dist/lib/Cloud/ApiErrorCode.d.ts +11 -0
- package/dist/lib/Cloud/Request.d.ts +29 -1
- package/dist/lib/Cloud/__mocks__/lifecycleScenarios.d.ts +16 -0
- package/dist/lib/Cloud/index.d.ts +17 -4
- package/dist/lib/Cloud/services/AlbumService.d.ts +39 -0
- package/dist/lib/Cloud/services/BillingService.d.ts +9 -0
- package/dist/lib/Cloud/services/FileService.d.ts +20 -0
- package/dist/lib/Cloud/services/UserService.d.ts +3 -4
- package/dist/lib/Cloud/services/multipart/MultipartStorage.d.ts +37 -0
- package/dist/lib/Cloud/services/multipart/MultipartUploadService.d.ts +49 -0
- package/dist/lib/Cloud/utils.d.ts +8 -1
- package/dist/lib/Logger.d.ts +28 -1
- package/dist/lib/Server/index.d.ts +3 -0
- package/dist/lib/Server/routes.d.ts +3 -1
- package/dist/plugins/commander/cloud/actions/configSync.d.ts +7 -0
- package/dist/plugins/commander/cloud/actions/index.d.ts +3 -0
- package/dist/plugins/commander/cloud/actions/login.d.ts +2 -0
- package/dist/plugins/commander/cloud/actions/logout.d.ts +2 -0
- package/dist/plugins/commander/cloud/delete.d.ts +4 -0
- package/dist/plugins/commander/cloud/get.d.ts +4 -0
- package/dist/plugins/commander/cloud/import.d.ts +13 -0
- package/dist/plugins/commander/cloud/index.d.ts +3 -0
- package/dist/plugins/commander/cloud/list.d.ts +18 -0
- package/dist/plugins/commander/cloud/retry.d.ts +4 -0
- package/dist/plugins/commander/cloud/shared.d.ts +16 -0
- package/dist/plugins/commander/cloud/status.d.ts +16 -0
- package/dist/plugins/commander/cloud/update.d.ts +4 -0
- package/dist/plugins/commander/get.d.ts +16 -0
- package/dist/plugins/commander/upload.d.ts +1 -1
- package/dist/plugins/commander/utils/progressRenderer.d.ts +31 -0
- package/dist/plugins/uploader/picgoCloud.d.ts +3 -0
- package/dist/types/index.d.ts +351 -5
- package/dist/types/internal.d.ts +8 -2
- package/dist/utils/enum.d.ts +13 -1
- package/dist/utils/interfaces.d.ts +23 -1
- package/dist/utils/pluginConfig.d.ts +50 -0
- package/dist/utils/progressBar.d.ts +11 -0
- package/dist/utils/static.d.ts +18 -0
- package/dist/utils/uploadWithProgress.d.ts +39 -0
- package/package.json +5 -3
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export declare enum ApiErrorCode {
|
|
2
|
+
AccountFrozen = "ACCOUNT_FROZEN",
|
|
3
|
+
ConfigConflict = "CONFIG_CONFLICT",
|
|
4
|
+
ConfigNotFound = "CONFIG_NOT_FOUND",
|
|
5
|
+
DuplicateId = "DUPLICATE_ID",
|
|
6
|
+
GraceRestricted = "GRACE_RESTRICTED",
|
|
7
|
+
ImportDisabled = "IMPORT_DISABLED",
|
|
8
|
+
PlanIneligible = "PLAN_INELIGIBLE",
|
|
9
|
+
PlanRequired = "PLAN_REQUIRED",
|
|
10
|
+
QuotaExceeded = "QUOTA_EXCEEDED"
|
|
11
|
+
}
|
|
@@ -1,5 +1,30 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { AxiosRequestConfig } from 'axios';
|
|
2
2
|
import type { IPicGo } from '../../types';
|
|
3
|
+
type ICloudErrorData = {
|
|
4
|
+
success?: boolean;
|
|
5
|
+
code?: string;
|
|
6
|
+
message?: string;
|
|
7
|
+
[key: string]: unknown;
|
|
8
|
+
};
|
|
9
|
+
type ICloudRequestErrorResponse = {
|
|
10
|
+
status: number;
|
|
11
|
+
data: unknown;
|
|
12
|
+
};
|
|
13
|
+
type ICloudRequestError = Error & {
|
|
14
|
+
isAxiosError: true;
|
|
15
|
+
code?: string;
|
|
16
|
+
status?: number;
|
|
17
|
+
response?: ICloudRequestErrorResponse;
|
|
18
|
+
};
|
|
19
|
+
type ICloudServiceError = Error & {
|
|
20
|
+
apiCode?: string;
|
|
21
|
+
status?: number;
|
|
22
|
+
};
|
|
23
|
+
declare const getCloudErrorData: (error: unknown) => ICloudErrorData | undefined;
|
|
24
|
+
declare const getCloudErrorStatus: (error: unknown) => number | undefined;
|
|
25
|
+
declare const getCloudErrorCode: (error: unknown) => string | undefined;
|
|
26
|
+
declare const getCloudErrorMessage: (error: unknown, fallback?: string) => string;
|
|
27
|
+
declare const createCloudServiceError: (message: string, cause?: unknown) => ICloudServiceError;
|
|
3
28
|
/**
|
|
4
29
|
* Authenticated Request Client for PicGo Cloud API
|
|
5
30
|
*/
|
|
@@ -7,6 +32,9 @@ declare class AuthRequestClient {
|
|
|
7
32
|
private readonly ctx;
|
|
8
33
|
private readonly baseURL;
|
|
9
34
|
constructor(ctx: IPicGo, baseURL?: string);
|
|
35
|
+
private resolveUrl;
|
|
10
36
|
request<T = any>(config: AxiosRequestConfig, token?: string): Promise<T>;
|
|
11
37
|
}
|
|
12
38
|
export { AuthRequestClient };
|
|
39
|
+
export { createCloudServiceError, getCloudErrorData, getCloudErrorCode, getCloudErrorMessage, getCloudErrorStatus };
|
|
40
|
+
export type { ICloudErrorData, ICloudRequestError, ICloudServiceError };
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { CloudBillingOverview, CloudUsage, ICloudUserInfo } from '../../../types';
|
|
2
|
+
/**
|
|
3
|
+
* 本文件用于本地开发 / QA 验收 lifecycle v2 UI 表现,不参与线上逻辑。
|
|
4
|
+
* 通过环境变量 `PICGO_MOCK_LIFECYCLE=<scenario>` 启用。
|
|
5
|
+
*
|
|
6
|
+
* 使用方式(PicGo desktop 主进程会读到 process.env):
|
|
7
|
+
* PICGO_MOCK_LIFECYCLE=grace pnpm dev
|
|
8
|
+
*
|
|
9
|
+
* 可选值:active-pro | active-pro-yearly | active-grant | grace | frozen | pending-cleanup
|
|
10
|
+
* 取消 mock:unset PICGO_MOCK_LIFECYCLE
|
|
11
|
+
*/
|
|
12
|
+
export type MockLifecycleScenario = 'active-pro' | 'active-pro-yearly' | 'active-pro-cancel' | 'active-grant' | 'active-grant-lifetime' | 'grace' | 'frozen' | 'pending-cleanup';
|
|
13
|
+
export declare function getMockScenario(): MockLifecycleScenario | undefined;
|
|
14
|
+
export declare function buildMockOverview(scenario: MockLifecycleScenario): CloudBillingOverview;
|
|
15
|
+
export declare function buildMockUsage(scenario: MockLifecycleScenario, appType: 'gui' | 'cli'): CloudUsage;
|
|
16
|
+
export declare function buildMockWhoami(scenario: MockLifecycleScenario): ICloudUserInfo;
|
|
@@ -1,15 +1,28 @@
|
|
|
1
|
-
import type { ICloudManager, IPicGo } from '../../types';
|
|
1
|
+
import type { CloudBillingOverview, CloudUsage, ICloudManager, ICloudUserInfo, IPicGo } from '../../types';
|
|
2
2
|
import { UserService } from './services/UserService';
|
|
3
|
+
import { AlbumService } from './services/AlbumService';
|
|
4
|
+
import { MultipartUploadService } from './services/multipart/MultipartUploadService';
|
|
3
5
|
declare class CloudManager implements ICloudManager {
|
|
4
6
|
private readonly ctx;
|
|
5
7
|
private readonly auth;
|
|
8
|
+
private readonly billingService;
|
|
9
|
+
private albumService?;
|
|
10
|
+
private uploaderService?;
|
|
11
|
+
private userInfoCache;
|
|
12
|
+
private userInfoPromise?;
|
|
6
13
|
user: UserService;
|
|
7
14
|
constructor(ctx: IPicGo);
|
|
15
|
+
get album(): AlbumService;
|
|
16
|
+
get uploader(): MultipartUploadService;
|
|
8
17
|
login(token?: string): Promise<void>;
|
|
9
18
|
logout(): void;
|
|
10
19
|
disposeLoginFlow(): void;
|
|
11
|
-
getUserInfo(): Promise<
|
|
12
|
-
|
|
13
|
-
|
|
20
|
+
getUserInfo(): Promise<ICloudUserInfo | null>;
|
|
21
|
+
refreshUserInfo(): Promise<ICloudUserInfo | null>;
|
|
22
|
+
getUsage(): Promise<CloudUsage | null>;
|
|
23
|
+
getBillingOverview(): Promise<CloudBillingOverview | null>;
|
|
24
|
+
setAutoImport(autoImport: boolean): Promise<ICloudUserInfo>;
|
|
25
|
+
private fetchUserInfo;
|
|
26
|
+
private clearUserInfoCache;
|
|
14
27
|
}
|
|
15
28
|
export { CloudManager };
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import type { AlbumFiltersResponse, AlbumListQuery, AlbumListResponse, AlbumStatsResponse, BatchUpdateResult, IImgInfo, ImportResult, IPicGo } from '../../../types';
|
|
2
|
+
import { AuthRequestClient } from '../Request';
|
|
3
|
+
export declare class AlbumService {
|
|
4
|
+
private static readonly DEFAULT_LIMIT;
|
|
5
|
+
private static readonly DEFAULT_OFFSET;
|
|
6
|
+
private static readonly IMPORT_BATCH_SIZE;
|
|
7
|
+
private static readonly MAX_IMPORT_ATTEMPTS;
|
|
8
|
+
private readonly ctx;
|
|
9
|
+
private readonly client;
|
|
10
|
+
private readonly pendingFilePath;
|
|
11
|
+
constructor(ctx: IPicGo, client?: AuthRequestClient);
|
|
12
|
+
list(query?: AlbumListQuery): Promise<AlbumListResponse>;
|
|
13
|
+
get(id: string): Promise<IImgInfo>;
|
|
14
|
+
update(id: string, data: Partial<IImgInfo>): Promise<IImgInfo>;
|
|
15
|
+
batchUpdate(items: {
|
|
16
|
+
id: string;
|
|
17
|
+
data: Partial<IImgInfo>;
|
|
18
|
+
}[]): Promise<BatchUpdateResult>;
|
|
19
|
+
delete(id: string | string[]): Promise<void>;
|
|
20
|
+
getStats(): Promise<AlbumStatsResponse>;
|
|
21
|
+
getFilters(): Promise<AlbumFiltersResponse>;
|
|
22
|
+
import(items: IImgInfo[]): Promise<ImportResult>;
|
|
23
|
+
getPending(): Promise<IImgInfo[]>;
|
|
24
|
+
addToPending(items: IImgInfo[]): Promise<IImgInfo[]>;
|
|
25
|
+
retryPending(): Promise<ImportResult>;
|
|
26
|
+
private normalizeImportItems;
|
|
27
|
+
private importBatchWithRetry;
|
|
28
|
+
private normalizeBatchSummary;
|
|
29
|
+
private resolveContentType;
|
|
30
|
+
private buildExtra;
|
|
31
|
+
private emitImportProgress;
|
|
32
|
+
private shouldRetry;
|
|
33
|
+
private isUnauthorizedError;
|
|
34
|
+
private hasApiErrorCode;
|
|
35
|
+
private writePending;
|
|
36
|
+
private warnInvalidPendingFile;
|
|
37
|
+
private isFileMissing;
|
|
38
|
+
private isImgInfoLike;
|
|
39
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { CloudBillingOverview, CloudUsage, IPicGo } from '../../../types';
|
|
2
|
+
declare class BillingService {
|
|
3
|
+
private readonly client;
|
|
4
|
+
private readonly ctx;
|
|
5
|
+
constructor(ctx: IPicGo);
|
|
6
|
+
getUsage(token?: string): Promise<CloudUsage>;
|
|
7
|
+
getOverview(token?: string): Promise<CloudBillingOverview>;
|
|
8
|
+
}
|
|
9
|
+
export { BillingService };
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { IImgInfo, IPicGo } from '../../../types';
|
|
2
|
+
export type FileUploadResult = {
|
|
3
|
+
imgUrl: string;
|
|
4
|
+
width?: number;
|
|
5
|
+
height?: number;
|
|
6
|
+
size?: number;
|
|
7
|
+
contentType?: string;
|
|
8
|
+
};
|
|
9
|
+
export declare class FileService {
|
|
10
|
+
private readonly ctx;
|
|
11
|
+
private readonly client;
|
|
12
|
+
constructor(ctx: IPicGo);
|
|
13
|
+
upload(img: IImgInfo): Promise<FileUploadResult>;
|
|
14
|
+
private getToken;
|
|
15
|
+
private getFileName;
|
|
16
|
+
private getImageBuffer;
|
|
17
|
+
private getContentType;
|
|
18
|
+
private buildUploadHeaders;
|
|
19
|
+
private callAuthenticatedStep;
|
|
20
|
+
}
|
|
@@ -1,11 +1,10 @@
|
|
|
1
|
-
import type { IConfig, IPicGo } from '../../../types';
|
|
1
|
+
import type { ICloudUserInfo, IConfig, IPicGo } from '../../../types';
|
|
2
2
|
declare class UserService {
|
|
3
3
|
private readonly client;
|
|
4
4
|
private readonly ctx;
|
|
5
5
|
constructor(ctx: IPicGo);
|
|
6
|
-
whoami(token: string): Promise<
|
|
7
|
-
|
|
8
|
-
}>;
|
|
6
|
+
whoami(token: string): Promise<ICloudUserInfo>;
|
|
7
|
+
setAutoImport(autoImport: boolean, token?: string): Promise<ICloudUserInfo>;
|
|
9
8
|
verifyToken(token: string): Promise<boolean>;
|
|
10
9
|
getUserConfig(token: string): Promise<IConfig>;
|
|
11
10
|
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import type { IPicGo, MultipartCompletedPart, MultipartSession } from '../../../../types';
|
|
2
|
+
/**
|
|
3
|
+
* Persistent storage for in-flight multipart upload sessions — used to support resume
|
|
4
|
+
* across process crashes / restarts.
|
|
5
|
+
*
|
|
6
|
+
* Layout: a single JSON file `picgo-cloud-multipart-pending.json` under ctx.baseDir.
|
|
7
|
+
* The top level carries a `v: 1` schema version for future migrations. Sessions are keyed
|
|
8
|
+
* by `${userId}:${fingerprint}` so accounts switched on the same machine cannot collide.
|
|
9
|
+
*
|
|
10
|
+
* Design principle: missing file / corrupt JSON / write failure → silently degrade to
|
|
11
|
+
* "no resume". Persistence is nice-to-have, never a hard requirement; storage failures
|
|
12
|
+
* must never block the actual upload flow.
|
|
13
|
+
*/
|
|
14
|
+
export declare class MultipartStorage {
|
|
15
|
+
private readonly ctx;
|
|
16
|
+
constructor(ctx: IPicGo);
|
|
17
|
+
/** Look up a session by (userId, fingerprint). Returns null if missing / expired / unreadable. */
|
|
18
|
+
get(userId: string, fingerprint: string): MultipartSession | null;
|
|
19
|
+
/** Write or replace a session. Write failures are swallowed (resume is not a hard requirement). */
|
|
20
|
+
set(userId: string, fingerprint: string, session: MultipartSession): void;
|
|
21
|
+
/** Remove a session by (userId, fingerprint). No-op if the entry doesn't exist. */
|
|
22
|
+
remove(userId: string, fingerprint: string): void;
|
|
23
|
+
/** Append a completed part; if the same partNumber already exists it is replaced (retry case). */
|
|
24
|
+
appendCompletedPart(userId: string, fingerprint: string, part: MultipartCompletedPart): void;
|
|
25
|
+
/** Sweep sessions whose createdAt is older than (now - 7d). Boundary: entries at exactly 7d are kept. */
|
|
26
|
+
sweepExpired(now?: number): void;
|
|
27
|
+
/** List every session for the given userId in insertion order. */
|
|
28
|
+
listForUser(userId: string): Array<{
|
|
29
|
+
fingerprint: string;
|
|
30
|
+
session: MultipartSession;
|
|
31
|
+
}>;
|
|
32
|
+
private getFilePath;
|
|
33
|
+
/** Read the file; missing / parse failure / schema mismatch all collapse to an empty store. */
|
|
34
|
+
private read;
|
|
35
|
+
/** Atomic write; failures swallowed (resume is not a hard requirement and must not block uploads). */
|
|
36
|
+
private write;
|
|
37
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import type { FileUploadResult } from '../FileService';
|
|
2
|
+
import type { ICloudUploaderManager, IImgInfo, ILogger, IPicGo, MultipartSession } from '../../../../types';
|
|
3
|
+
import { AuthRequestClient } from '../../Request';
|
|
4
|
+
import { MultipartStorage } from './MultipartStorage';
|
|
5
|
+
/**
|
|
6
|
+
* PicGo Cloud multipart upload service. Two responsibilities:
|
|
7
|
+
*
|
|
8
|
+
* 1. **State machine** (`runMultipartUpload` function, called by FileService's size dispatch):
|
|
9
|
+
* initiate → concurrent part PUTs → complete, with local session persistence so a crashed /
|
|
10
|
+
* interrupted upload can resume on the next attempt for the same file.
|
|
11
|
+
*
|
|
12
|
+
* 2. **Management API** (this class's abort / listPending / removePending): exposed to picgo-gui
|
|
13
|
+
* for a future "clean up pending uploads" UI. Mounted on `ctx.cloud.uploader`.
|
|
14
|
+
*
|
|
15
|
+
* Sessions left over by failure / crash are double-protected: server-side R2 lifecycle cleans
|
|
16
|
+
* orphan multipart uploads after 7 days, local TTL also sweeps after 7 days. We intentionally
|
|
17
|
+
* do NOT abort the remote session on state-machine failure, otherwise resume would be defeated.
|
|
18
|
+
*/
|
|
19
|
+
export declare class MultipartUploadService implements ICloudUploaderManager {
|
|
20
|
+
private readonly ctx;
|
|
21
|
+
private readonly authClient;
|
|
22
|
+
private readonly storage;
|
|
23
|
+
private readonly diagLogger;
|
|
24
|
+
constructor(ctx: IPicGo);
|
|
25
|
+
/**
|
|
26
|
+
* Best-effort abort of a remote multipart upload session.
|
|
27
|
+
* Swallows all errors (R2's 7-day lifecycle is the safety net); callers don't need try/catch.
|
|
28
|
+
*/
|
|
29
|
+
abort(uploadId: string, objectKey: string): Promise<void>;
|
|
30
|
+
/** List all local pending multipart sessions belonging to the currently logged-in user. */
|
|
31
|
+
listPending(): MultipartSession[];
|
|
32
|
+
/** Delete only the local entry; does not notify the remote (call abort for that). */
|
|
33
|
+
removePending(fingerprint: string): void;
|
|
34
|
+
/** @internal */
|
|
35
|
+
getInternals(): {
|
|
36
|
+
ctx: IPicGo;
|
|
37
|
+
authClient: AuthRequestClient;
|
|
38
|
+
storage: MultipartStorage;
|
|
39
|
+
diagLogger: ILogger | undefined;
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Run a full multipart upload: fingerprint → get/create session → concurrent part uploads → complete.
|
|
44
|
+
* Called by FileService.upload when buffer size >= MULTIPART_THRESHOLD_BYTES.
|
|
45
|
+
*
|
|
46
|
+
* Deliberately not exposed on `ctx.cloud.uploader`: GUI / external plugins should go through
|
|
47
|
+
* FileService so the size dispatch (single-PUT vs multipart) stays in one place.
|
|
48
|
+
*/
|
|
49
|
+
export declare function runMultipartUpload(ctx: IPicGo, img: IImgInfo): Promise<FileUploadResult>;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { ICloudUserInfo } from '../../types';
|
|
1
2
|
type ITokenExchangeResponse = {
|
|
2
3
|
success: boolean;
|
|
3
4
|
token?: string;
|
|
@@ -6,10 +7,16 @@ type ITokenExchangeResponse = {
|
|
|
6
7
|
type IErrorResponse = {
|
|
7
8
|
message?: string;
|
|
8
9
|
};
|
|
10
|
+
declare const isRecord: (value: unknown) => value is Record<string, unknown>;
|
|
11
|
+
declare const compactDefinedRecord: <T extends Record<string, unknown>>(value: T) => Partial<T>;
|
|
12
|
+
declare const chunkArray: <T>(items: T[], chunkSize: number) => T[][];
|
|
13
|
+
declare const toNonNegativeInteger: (value: unknown, fallback: number) => number;
|
|
14
|
+
declare const toUnixMilliseconds: (value: number | string | Date | null | undefined) => number | undefined;
|
|
15
|
+
declare const isPaidCloudUser: (userInfo: ICloudUserInfo | null | undefined) => boolean;
|
|
9
16
|
declare const toBase64Url: (bytes: Uint8Array) => string;
|
|
10
17
|
declare const generatePkceVerifier: () => string;
|
|
11
18
|
declare const pkceChallengeFromVerifier: (verifier: string) => Promise<string>;
|
|
12
19
|
declare const isErrorResponse: (data: unknown) => data is IErrorResponse;
|
|
13
20
|
declare const exchangeToken: (code: string, verifier: string) => Promise<ITokenExchangeResponse>;
|
|
14
|
-
export { exchangeToken, generatePkceVerifier, isErrorResponse, pkceChallengeFromVerifier, toBase64Url };
|
|
21
|
+
export { chunkArray, compactDefinedRecord, exchangeToken, generatePkceVerifier, isErrorResponse, isPaidCloudUser, isRecord, pkceChallengeFromVerifier, toNonNegativeInteger, toUnixMilliseconds, toBase64Url };
|
|
15
22
|
export type { IErrorResponse, ITokenExchangeResponse };
|
package/dist/lib/Logger.d.ts
CHANGED
|
@@ -2,9 +2,24 @@ import { ILogArgvType, ILogArgvTypeWithError, ILogger, IPicGo } from '../types';
|
|
|
2
2
|
export declare class Logger implements ILogger {
|
|
3
3
|
private readonly level;
|
|
4
4
|
private readonly ctx;
|
|
5
|
+
private readonly consoleOutput;
|
|
6
|
+
private readonly respectSilent;
|
|
5
7
|
private logLevel;
|
|
6
8
|
private logPath;
|
|
7
|
-
|
|
9
|
+
private logPathOverride?;
|
|
10
|
+
constructor(ctx: IPicGo, options?: {
|
|
11
|
+
/** Whether to output to console. Defaults to true. */
|
|
12
|
+
consoleOutput?: boolean;
|
|
13
|
+
/**
|
|
14
|
+
* Whether to obey the global `silent` config.
|
|
15
|
+
* - true (default): when `silent` is enabled, both console output and file writes are suppressed.
|
|
16
|
+
* - false: file writes always happen regardless of `silent`, useful for audit/diagnostic logs
|
|
17
|
+
* that must not be lost even in silent mode.
|
|
18
|
+
*/
|
|
19
|
+
respectSilent?: boolean;
|
|
20
|
+
/** Override the log file path. Defaults to `settings.logPath` or `ctx.baseDir/picgo.log`. */
|
|
21
|
+
logPath?: string;
|
|
22
|
+
});
|
|
8
23
|
private handleLog;
|
|
9
24
|
private checkLogFileIsLarge;
|
|
10
25
|
private recreateLogFile;
|
|
@@ -15,5 +30,17 @@ export declare class Logger implements ILogger {
|
|
|
15
30
|
error(...msg: ILogArgvTypeWithError[]): void;
|
|
16
31
|
warn(...msg: ILogArgvType[]): void;
|
|
17
32
|
debug(...msg: ILogArgvType[]): void;
|
|
33
|
+
createLogger(options?: {
|
|
34
|
+
/** Override the log file path. */
|
|
35
|
+
logPath?: string;
|
|
36
|
+
/** Whether to output to console. Defaults to true. */
|
|
37
|
+
consoleOutput?: boolean;
|
|
38
|
+
/**
|
|
39
|
+
* Whether to obey the global `silent` config.
|
|
40
|
+
* - true (default): silent mode suppresses both console and file output.
|
|
41
|
+
* - false: file writes always happen, useful for audit/diagnostic logs.
|
|
42
|
+
*/
|
|
43
|
+
respectSilent?: boolean;
|
|
44
|
+
}): Logger;
|
|
18
45
|
}
|
|
19
46
|
export default Logger;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { Handler, MiddlewareHandler } from 'hono';
|
|
2
2
|
import type { IPicGo, IServerManager, PluginRouterSetup } from '../../types';
|
|
3
|
+
import type { IServerUploadAdapter } from '../../types/internal';
|
|
3
4
|
declare class ServerManager implements IServerManager {
|
|
4
5
|
private app;
|
|
5
6
|
private readonly ctx;
|
|
@@ -9,12 +10,14 @@ declare class ServerManager implements IServerManager {
|
|
|
9
10
|
private authSecret?;
|
|
10
11
|
private warnedQuerySecret;
|
|
11
12
|
private staticRoutePrefixes;
|
|
13
|
+
private uploadAdapter?;
|
|
12
14
|
constructor(ctx: IPicGo);
|
|
13
15
|
registerGet<P extends string>(path: P, handler: Handler<any, P>, isInternal?: boolean): void;
|
|
14
16
|
registerPost<P extends string>(path: P, handler: Handler<any, P>, isInternal?: boolean): void;
|
|
15
17
|
registerPut<P extends string>(path: P, handler: Handler<any, P>, isInternal?: boolean): void;
|
|
16
18
|
registerDelete<P extends string>(path: P, handler: Handler<any, P>, isInternal?: boolean): void;
|
|
17
19
|
registerMiddleware<P extends string>(path: P, handler: MiddlewareHandler<any, P>): void;
|
|
20
|
+
setUploadAdapter(adapter?: IServerUploadAdapter): void;
|
|
18
21
|
registerStatic(path: string, root: string): void;
|
|
19
22
|
private handleRegister;
|
|
20
23
|
mount(path: string, setup: PluginRouterSetup): void;
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import type { Hono } from 'hono';
|
|
2
2
|
import type { IPicGo } from '../../types';
|
|
3
|
-
|
|
3
|
+
import type { IServerUploadAdapter } from '../../types/internal';
|
|
4
|
+
type GetUploadAdapter = () => IServerUploadAdapter | undefined;
|
|
5
|
+
declare const registerCoreRoutes: (app: Hono<any, any, any>, ctx: IPicGo, getUploadAdapter?: GetUploadAdapter) => void;
|
|
4
6
|
export { registerCoreRoutes };
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { Command } from 'commander';
|
|
2
|
+
import type { IPicGo } from '../../../../types';
|
|
3
|
+
export declare const applyConfigSyncOptions: (cmd: Command) => Command;
|
|
4
|
+
export declare const createConfigSyncAction: (ctx: IPicGo) => (options: {
|
|
5
|
+
encrypt?: string | boolean;
|
|
6
|
+
skipEncryptionSwitchConfirm?: boolean;
|
|
7
|
+
}) => Promise<void>;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { Command } from 'commander';
|
|
2
|
+
import type { IPicGo } from '../../../types';
|
|
3
|
+
interface ICloudImportOptions {
|
|
4
|
+
jsonFile?: string;
|
|
5
|
+
data?: string;
|
|
6
|
+
verbose?: boolean;
|
|
7
|
+
enableAutoImport?: boolean;
|
|
8
|
+
format?: string;
|
|
9
|
+
}
|
|
10
|
+
declare const applyCloudImportOptions: (cmd: Command) => Command;
|
|
11
|
+
declare const createCloudImportAction: (ctx: IPicGo) => (dbPath: string | undefined, options: ICloudImportOptions) => Promise<void>;
|
|
12
|
+
declare const registerCloudImportCommand: (ctx: IPicGo, parentCommand: Command) => void;
|
|
13
|
+
export { applyCloudImportOptions, createCloudImportAction, registerCloudImportCommand };
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { Command } from 'commander';
|
|
2
|
+
import { type IPicGo } from '../../../types';
|
|
3
|
+
interface CloudListOptions {
|
|
4
|
+
contentType?: string;
|
|
5
|
+
type?: string;
|
|
6
|
+
ext?: string;
|
|
7
|
+
search?: string;
|
|
8
|
+
fileName?: string;
|
|
9
|
+
limit?: string;
|
|
10
|
+
offset?: string;
|
|
11
|
+
sort?: 'newest' | 'oldest' | 'fileName';
|
|
12
|
+
order?: 'asc' | 'desc';
|
|
13
|
+
format?: string;
|
|
14
|
+
}
|
|
15
|
+
declare const applyCloudListOptions: (cmd: Command) => Command;
|
|
16
|
+
declare const createCloudListAction: (ctx: IPicGo) => (options: CloudListOptions) => Promise<void>;
|
|
17
|
+
declare const registerCloudListCommand: (ctx: IPicGo, parentCommand: Command) => void;
|
|
18
|
+
export { applyCloudListOptions, createCloudListAction, registerCloudListCommand };
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { Ora } from 'ora';
|
|
2
|
+
import type { ImportResult, IPicGo } from '../../../types';
|
|
3
|
+
declare const createSpinner: (text: string) => Ora;
|
|
4
|
+
declare const ensureCloudLogin: (ctx: IPicGo) => void;
|
|
5
|
+
declare const runCloudCommand: (ctx: IPicGo, handler: () => Promise<void>) => Promise<void>;
|
|
6
|
+
declare const compactObject: <T extends Record<string, unknown>>(value: T) => Partial<T>;
|
|
7
|
+
declare const parseInteger: (value?: string) => number | undefined;
|
|
8
|
+
interface IImportProgressRenderer {
|
|
9
|
+
spinner: Ora;
|
|
10
|
+
dispose: () => void;
|
|
11
|
+
}
|
|
12
|
+
declare const createImportProgressRenderer: (ctx: IPicGo, verbose: boolean) => IImportProgressRenderer;
|
|
13
|
+
declare const printImportSummary: (ctx: IPicGo, result: ImportResult) => void;
|
|
14
|
+
declare const printJson: (value: unknown) => void;
|
|
15
|
+
declare const printCompactJson: (value: unknown) => void;
|
|
16
|
+
export { compactObject, createImportProgressRenderer, createSpinner, ensureCloudLogin, parseInteger, printCompactJson, printImportSummary, printJson, runCloudCommand };
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { Command } from 'commander';
|
|
2
|
+
import type { IPicGo } from '../../../types';
|
|
3
|
+
interface CloudAuthStatusOptions {
|
|
4
|
+
format?: string;
|
|
5
|
+
}
|
|
6
|
+
type CloudAuthStatus = 'logged_in' | 'logged_out' | 'invalid' | 'error';
|
|
7
|
+
interface CloudAuthStatusResult {
|
|
8
|
+
status: CloudAuthStatus;
|
|
9
|
+
loggedIn: boolean;
|
|
10
|
+
user?: string | null;
|
|
11
|
+
plan?: number;
|
|
12
|
+
message?: string;
|
|
13
|
+
}
|
|
14
|
+
declare const createCloudAuthStatusAction: (ctx: IPicGo) => (options?: CloudAuthStatusOptions) => Promise<CloudAuthStatusResult>;
|
|
15
|
+
declare const registerCloudAuthStatusCommand: (ctx: IPicGo, authCommand: Command) => void;
|
|
16
|
+
export { createCloudAuthStatusAction, registerCloudAuthStatusCommand };
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { IPicGo, IPlugin } from '../../types';
|
|
2
|
+
interface GetOptions {
|
|
3
|
+
format?: string;
|
|
4
|
+
}
|
|
5
|
+
interface PluginEntry {
|
|
6
|
+
name: string;
|
|
7
|
+
enabled: boolean;
|
|
8
|
+
}
|
|
9
|
+
declare const resolveUploader: (ctx: IPicGo) => string;
|
|
10
|
+
declare const resolveTransformer: (ctx: IPicGo) => string;
|
|
11
|
+
declare const resolvePlugins: (ctx: IPicGo) => PluginEntry[];
|
|
12
|
+
declare const createUploaderAction: (ctx: IPicGo) => (options: GetOptions) => string;
|
|
13
|
+
declare const createTransformerAction: (ctx: IPicGo) => (options: GetOptions) => string;
|
|
14
|
+
declare const createPluginsAction: (ctx: IPicGo) => (options: GetOptions) => PluginEntry[];
|
|
15
|
+
declare const get: IPlugin;
|
|
16
|
+
export { get, resolveUploader, resolveTransformer, resolvePlugins, createUploaderAction, createTransformerAction, createPluginsAction };
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { Ora } from 'ora';
|
|
2
|
+
import type { IPicGo, IProgress } from '../../../types';
|
|
3
|
+
import type { IBuildInEvent } from '../../../utils/enum';
|
|
4
|
+
/**
|
|
5
|
+
* Options for a generic CLI progress renderer.
|
|
6
|
+
*
|
|
7
|
+
* The renderer picks one of three modes:
|
|
8
|
+
* - **TTY mode** — stdout is an interactive terminal AND `verbose=false`: ora spinner draws the
|
|
9
|
+
* progress bar in place (single line that updates).
|
|
10
|
+
* - **Verbose mode** — `verbose=true`: each event prints a full line, suitable for log redirection
|
|
11
|
+
* or when the operator wants per-event history.
|
|
12
|
+
* - **Non-TTY mode** — stdout is piped / CI: same as verbose, lines printed one at a time so
|
|
13
|
+
* downstream log capture isn't clobbered by spinner escape codes.
|
|
14
|
+
*
|
|
15
|
+
* The caller only provides two formatters: the inline label that follows the bar in TTY mode,
|
|
16
|
+
* and the full line text used in verbose / non-TTY modes.
|
|
17
|
+
*/
|
|
18
|
+
export interface IProgressRendererOptions<TProgress extends IProgress> {
|
|
19
|
+
ctx: IPicGo;
|
|
20
|
+
event: IBuildInEvent;
|
|
21
|
+
verbose: boolean;
|
|
22
|
+
/** Label appended after the progress bar in TTY mode. */
|
|
23
|
+
formatBarText: (payload: TProgress) => string;
|
|
24
|
+
/** Full line text printed in verbose / non-TTY modes. */
|
|
25
|
+
formatVerboseText: (payload: TProgress) => string;
|
|
26
|
+
}
|
|
27
|
+
export interface IProgressRendererHandle {
|
|
28
|
+
spinner: Ora;
|
|
29
|
+
dispose: () => void;
|
|
30
|
+
}
|
|
31
|
+
export declare const createProgressRenderer: <TProgress extends IProgress>(options: IProgressRendererOptions<TProgress>) => IProgressRendererHandle;
|