picgo 1.8.1 → 2.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/.env.example +2 -0
- package/AGENTS.md +4 -0
- package/README.md +25 -2
- package/dist/core/PicGo.d.ts +5 -1
- package/dist/i18n/index.d.ts +2 -2
- package/dist/i18n/zh-CN.d.ts +35 -0
- package/dist/index.cjs.js +1 -1
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.d.ts +6 -0
- package/dist/index.esm.js +1 -1
- package/dist/index.esm.js.map +1 -1
- package/dist/lib/Cloud/Auth.d.ts +15 -0
- package/dist/lib/Cloud/Request.d.ts +12 -0
- package/dist/lib/Cloud/index.d.ts +15 -0
- package/dist/lib/Cloud/services/ConfigService.d.ts +15 -0
- package/dist/lib/Cloud/services/UserService.d.ts +12 -0
- package/dist/lib/Cloud/utils.d.ts +15 -0
- package/dist/lib/ConfigSyncManager/E2ECryptoService.d.ts +24 -0
- package/dist/lib/ConfigSyncManager/Merger.d.ts +4 -0
- package/dist/lib/ConfigSyncManager/errors.d.ts +29 -0
- package/dist/lib/ConfigSyncManager/index.d.ts +39 -0
- package/dist/lib/ConfigSyncManager/types.d.ts +87 -0
- package/dist/lib/ConfigSyncManager/utils.d.ts +41 -0
- package/dist/lib/Routes/routePath.d.ts +6 -0
- package/dist/lib/Server/index.d.ts +39 -0
- package/dist/lib/Server/routes.d.ts +4 -0
- package/dist/lib/Server/utils.d.ts +10 -0
- package/dist/lib/utils.d.ts +2 -0
- package/dist/plugins/commander/config.d.ts +2 -2
- package/dist/plugins/commander/configPath.d.ts +3 -0
- package/dist/plugins/commander/index.d.ts +2 -2
- package/dist/plugins/commander/login.d.ts +3 -0
- package/dist/plugins/commander/logout.d.ts +3 -0
- package/dist/plugins/commander/server.d.ts +3 -0
- package/dist/plugins/commander/setting.d.ts +2 -2
- package/dist/plugins/commander/utils.d.ts +10 -0
- package/dist/types/index.d.ts +78 -2
- package/dist/types/internal.d.ts +8 -0
- package/package.json +13 -4
- package/vitest.config.ts +9 -0
- package/dist/__tests__/unit/uploaderConfigManager.spec.d.ts +0 -1
- package/dist/__tests__/unit/urlRewrite.spec.d.ts +0 -1
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { type AxiosRequestConfig } from 'axios';
|
|
2
|
+
import type { IPicGo } from '../../types';
|
|
3
|
+
/**
|
|
4
|
+
* Authenticated Request Client for PicGo Cloud API
|
|
5
|
+
*/
|
|
6
|
+
declare class AuthRequestClient {
|
|
7
|
+
private readonly ctx;
|
|
8
|
+
private readonly baseURL;
|
|
9
|
+
constructor(ctx: IPicGo, baseURL?: string);
|
|
10
|
+
request<T = any>(config: AxiosRequestConfig, token?: string): Promise<T>;
|
|
11
|
+
}
|
|
12
|
+
export { AuthRequestClient };
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { ICloudManager, IPicGo } from '../../types';
|
|
2
|
+
import { UserService } from './services/UserService';
|
|
3
|
+
declare class CloudManager implements ICloudManager {
|
|
4
|
+
private readonly ctx;
|
|
5
|
+
private readonly auth;
|
|
6
|
+
user: UserService;
|
|
7
|
+
constructor(ctx: IPicGo);
|
|
8
|
+
login(token?: string): Promise<void>;
|
|
9
|
+
logout(): void;
|
|
10
|
+
disposeLoginFlow(): void;
|
|
11
|
+
getUserInfo(): Promise<{
|
|
12
|
+
user: string;
|
|
13
|
+
} | null>;
|
|
14
|
+
}
|
|
15
|
+
export { CloudManager };
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { IPicGo } from '../../../types';
|
|
2
|
+
import type { IE2ERequestFields, ISyncConfigResponse } from '../../ConfigSyncManager/types';
|
|
3
|
+
export interface IUpdateConfigResult {
|
|
4
|
+
success: boolean;
|
|
5
|
+
version: number;
|
|
6
|
+
conflict?: boolean;
|
|
7
|
+
}
|
|
8
|
+
export declare class ConfigService {
|
|
9
|
+
private readonly client;
|
|
10
|
+
private readonly ctx;
|
|
11
|
+
private appType;
|
|
12
|
+
constructor(ctx: IPicGo);
|
|
13
|
+
fetchConfig(): Promise<ISyncConfigResponse | null>;
|
|
14
|
+
updateConfig(configStr: string, baseVersion: number, e2eFields?: IE2ERequestFields): Promise<IUpdateConfigResult>;
|
|
15
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { IConfig, IPicGo } from '../../../types';
|
|
2
|
+
declare class UserService {
|
|
3
|
+
private readonly client;
|
|
4
|
+
private readonly ctx;
|
|
5
|
+
constructor(ctx: IPicGo);
|
|
6
|
+
whoami(token: string): Promise<{
|
|
7
|
+
user: string;
|
|
8
|
+
}>;
|
|
9
|
+
verifyToken(token: string): Promise<boolean>;
|
|
10
|
+
getUserConfig(token: string): Promise<IConfig>;
|
|
11
|
+
}
|
|
12
|
+
export { UserService };
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
type ITokenExchangeResponse = {
|
|
2
|
+
success: boolean;
|
|
3
|
+
token?: string;
|
|
4
|
+
message?: string;
|
|
5
|
+
};
|
|
6
|
+
type IErrorResponse = {
|
|
7
|
+
message?: string;
|
|
8
|
+
};
|
|
9
|
+
declare const toBase64Url: (bytes: Uint8Array) => string;
|
|
10
|
+
declare const generatePkceVerifier: () => string;
|
|
11
|
+
declare const pkceChallengeFromVerifier: (verifier: string) => Promise<string>;
|
|
12
|
+
declare const isErrorResponse: (data: unknown) => data is IErrorResponse;
|
|
13
|
+
declare const exchangeToken: (code: string, verifier: string) => Promise<ITokenExchangeResponse>;
|
|
14
|
+
export { exchangeToken, generatePkceVerifier, isErrorResponse, pkceChallengeFromVerifier, toBase64Url };
|
|
15
|
+
export type { IErrorResponse, ITokenExchangeResponse };
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { type IE2EPayload, type ISyncConfigResponse } from './types';
|
|
2
|
+
declare class E2ECryptoService {
|
|
3
|
+
generateE2EPayload(config: string, pin: string): {
|
|
4
|
+
payload: IE2EPayload;
|
|
5
|
+
dek: Buffer;
|
|
6
|
+
};
|
|
7
|
+
encryptConfig(config: string, dek: Buffer): string;
|
|
8
|
+
decryptConfig(encryptedConfig: string, dek: Buffer): string;
|
|
9
|
+
wrapDEK(dek: Buffer, pin: string, salt: Buffer): string;
|
|
10
|
+
unwrapDEK(encryptedDEK: string, pin: string, salt: Buffer): Buffer;
|
|
11
|
+
decodeSalt(saltBase64: string): Buffer;
|
|
12
|
+
private deriveKEK;
|
|
13
|
+
private encryptWithKey;
|
|
14
|
+
private decryptWithKey;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Ensure encrypted payload includes a client KEK salt for E2E decryption.
|
|
18
|
+
*/
|
|
19
|
+
declare const requireClientKekSalt: (res: ISyncConfigResponse) => string;
|
|
20
|
+
/**
|
|
21
|
+
* Ensure encrypted payload includes an encrypted DEK for E2E decryption.
|
|
22
|
+
*/
|
|
23
|
+
declare const requireClientDekEncrypted: (res: ISyncConfigResponse) => string;
|
|
24
|
+
export { E2ECryptoService, requireClientDekEncrypted, requireClientKekSalt };
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
declare class BaseE2EError extends Error {
|
|
2
|
+
constructor(message: string);
|
|
3
|
+
}
|
|
4
|
+
export declare class CorruptedDataError extends BaseE2EError {
|
|
5
|
+
constructor(message?: string);
|
|
6
|
+
}
|
|
7
|
+
export declare class UnsupportedVersionError extends BaseE2EError {
|
|
8
|
+
constructor(message?: string);
|
|
9
|
+
}
|
|
10
|
+
export declare class MissingHandlerError extends BaseE2EError {
|
|
11
|
+
constructor(message?: string);
|
|
12
|
+
}
|
|
13
|
+
export declare class MissingEncryptionSwitchHandlerError extends BaseE2EError {
|
|
14
|
+
constructor(message?: string);
|
|
15
|
+
}
|
|
16
|
+
export declare class InvalidPinError extends BaseE2EError {
|
|
17
|
+
constructor(message?: string);
|
|
18
|
+
}
|
|
19
|
+
export declare class MaxRetryExceededError extends BaseE2EError {
|
|
20
|
+
constructor(message?: string);
|
|
21
|
+
}
|
|
22
|
+
export declare class DecryptionFailedError extends BaseE2EError {
|
|
23
|
+
constructor(message?: string);
|
|
24
|
+
}
|
|
25
|
+
export declare class InvalidEncryptionMethodError extends BaseE2EError {
|
|
26
|
+
readonly value: unknown;
|
|
27
|
+
constructor(value: unknown);
|
|
28
|
+
}
|
|
29
|
+
export {};
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import type { IPicGo, IConfig } from '../../types';
|
|
2
|
+
import type { IApplyResolvedOptions, IEncryptionSwitchContext, ISyncOptions, ISyncResult } from './types';
|
|
3
|
+
import { E2EAskPinReason } from './types';
|
|
4
|
+
interface IConfigSyncManagerOptions {
|
|
5
|
+
onAskPin?: (reason: E2EAskPinReason, retryCount: number) => Promise<string | null>;
|
|
6
|
+
onAskEncryptionSwitch?: (context: IEncryptionSwitchContext) => Promise<boolean>;
|
|
7
|
+
}
|
|
8
|
+
export declare class ConfigSyncManager {
|
|
9
|
+
private readonly ctx;
|
|
10
|
+
private readonly snapshotPath;
|
|
11
|
+
private readonly configService;
|
|
12
|
+
private readonly onAskPin?;
|
|
13
|
+
private readonly onAskEncryptionSwitch?;
|
|
14
|
+
private readonly e2eService;
|
|
15
|
+
private currentRemoteVersion;
|
|
16
|
+
private originalRemote;
|
|
17
|
+
private remoteE2EVersion;
|
|
18
|
+
private remoteClientKekSalt?;
|
|
19
|
+
private remoteClientDekEncrypted?;
|
|
20
|
+
private cachedDEK?;
|
|
21
|
+
private cachedClientDekEncrypted?;
|
|
22
|
+
constructor(ctx: IPicGo, options?: IConfigSyncManagerOptions);
|
|
23
|
+
sync(options?: ISyncOptions, retryCount?: number): Promise<ISyncResult>;
|
|
24
|
+
applyResolvedConfig(resolvedConfig: IConfig, options?: IApplyResolvedOptions): Promise<ISyncResult>;
|
|
25
|
+
private fetchRemoteConfig;
|
|
26
|
+
private pushRemoteConfig;
|
|
27
|
+
private applyE2EStateAfterPush;
|
|
28
|
+
private setRemoteE2EState;
|
|
29
|
+
private confirmEncryptionSwitch;
|
|
30
|
+
private buildPushPayload;
|
|
31
|
+
private shouldUseE2E;
|
|
32
|
+
private isEncryptionModeSwitch;
|
|
33
|
+
private decryptRemoteConfig;
|
|
34
|
+
private ensureDEK;
|
|
35
|
+
private askPin;
|
|
36
|
+
}
|
|
37
|
+
export type { IDiffNode, IE2EPayload, IEncryptionSwitchContext, ISyncConfigResponse, ISyncOptions, IApplyResolvedOptions } from './types';
|
|
38
|
+
export { SyncStatus, ConflictType, E2EVersion, EncryptionMethod, E2EAskPinReason } from './types';
|
|
39
|
+
export { CorruptedDataError, UnsupportedVersionError, MissingHandlerError, MissingEncryptionSwitchHandlerError, InvalidPinError, MaxRetryExceededError, DecryptionFailedError } from './errors';
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import type { IConfig } from '../../types';
|
|
2
|
+
export declare enum SyncStatus {
|
|
3
|
+
SUCCESS = "success",
|
|
4
|
+
CONFLICT = "conflict",
|
|
5
|
+
FAILED = "failed"
|
|
6
|
+
}
|
|
7
|
+
export declare enum ConflictType {
|
|
8
|
+
CLEAN = "clean",
|
|
9
|
+
CONFLICT = "conflict",
|
|
10
|
+
ADDED = "added",
|
|
11
|
+
DELETED = "deleted",
|
|
12
|
+
MODIFIED = "modified"
|
|
13
|
+
}
|
|
14
|
+
export declare enum E2EVersion {
|
|
15
|
+
NONE = 0,
|
|
16
|
+
V1 = 1
|
|
17
|
+
}
|
|
18
|
+
export declare enum EncryptionMethod {
|
|
19
|
+
AUTO = "auto",
|
|
20
|
+
SSE = "sse",
|
|
21
|
+
E2EE = "e2ee"
|
|
22
|
+
}
|
|
23
|
+
export declare enum E2EAskPinReason {
|
|
24
|
+
SETUP = "setup",
|
|
25
|
+
DECRYPT = "decrypt",
|
|
26
|
+
RETRY = "retry"
|
|
27
|
+
}
|
|
28
|
+
export declare enum APPType {
|
|
29
|
+
GUI = "gui",
|
|
30
|
+
CLI = "cli"
|
|
31
|
+
}
|
|
32
|
+
export type ConfigValue = string | number | boolean | null | undefined | any[] | Record<string, any>;
|
|
33
|
+
export interface IE2EPayload {
|
|
34
|
+
e2eVersion: E2EVersion.V1;
|
|
35
|
+
clientKekSalt: string;
|
|
36
|
+
clientDekEncrypted: string;
|
|
37
|
+
config: string;
|
|
38
|
+
}
|
|
39
|
+
export interface IE2ERequestFields {
|
|
40
|
+
e2eVersion?: E2EVersion;
|
|
41
|
+
clientKekSalt?: string;
|
|
42
|
+
clientDekEncrypted?: string;
|
|
43
|
+
}
|
|
44
|
+
export interface IEncryptionSwitchContext {
|
|
45
|
+
from: EncryptionMethod;
|
|
46
|
+
to: EncryptionMethod;
|
|
47
|
+
}
|
|
48
|
+
export interface ISyncConfigResponse {
|
|
49
|
+
version: number;
|
|
50
|
+
config: string;
|
|
51
|
+
encryption?: {
|
|
52
|
+
e2eVersion?: number;
|
|
53
|
+
clientKekSalt?: string;
|
|
54
|
+
clientDekEncrypted?: string;
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
export interface ISyncOptions {
|
|
58
|
+
encryptionMethod?: EncryptionMethod;
|
|
59
|
+
skipEncryptionSwitchConfirm?: boolean;
|
|
60
|
+
}
|
|
61
|
+
export interface IApplyResolvedOptions {
|
|
62
|
+
useE2E?: boolean;
|
|
63
|
+
}
|
|
64
|
+
export interface ISnapshot {
|
|
65
|
+
version: number;
|
|
66
|
+
updatedAt: string;
|
|
67
|
+
data: ConfigValue;
|
|
68
|
+
}
|
|
69
|
+
export interface IDiffNode {
|
|
70
|
+
key: string;
|
|
71
|
+
status: ConflictType;
|
|
72
|
+
snapshotValue?: ConfigValue;
|
|
73
|
+
localValue?: ConfigValue;
|
|
74
|
+
remoteValue?: ConfigValue;
|
|
75
|
+
children?: IDiffNode[];
|
|
76
|
+
}
|
|
77
|
+
export interface IMergeResult {
|
|
78
|
+
value: ConfigValue;
|
|
79
|
+
conflict: boolean;
|
|
80
|
+
diffNode?: IDiffNode;
|
|
81
|
+
}
|
|
82
|
+
export interface ISyncResult {
|
|
83
|
+
status: SyncStatus;
|
|
84
|
+
message?: string;
|
|
85
|
+
diffTree?: IDiffNode;
|
|
86
|
+
mergedConfig?: IConfig;
|
|
87
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import type { IConfig } from '../../types';
|
|
2
|
+
import type { ConfigValue, ISnapshot } from './types';
|
|
3
|
+
import { E2EVersion, EncryptionMethod } from './types';
|
|
4
|
+
declare const ENCRYPTION_METHOD_PATH = "settings.picgoCloud.encryptionMethod";
|
|
5
|
+
declare const IGNORED_PATHS: string[];
|
|
6
|
+
interface IMaskIgnoredOptions {
|
|
7
|
+
cleanupEmptyParents?: boolean;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Mask ignored config paths so local-only values don't conflict or overwrite remote values.
|
|
11
|
+
*/
|
|
12
|
+
declare const maskIgnoredFields: (target: IConfig, source: IConfig, options?: IMaskIgnoredOptions) => IConfig;
|
|
13
|
+
/**
|
|
14
|
+
* Read the local encryption method preference from config.
|
|
15
|
+
*/
|
|
16
|
+
declare const getLocalEncryptionMethod: (config: IConfig) => EncryptionMethod | undefined;
|
|
17
|
+
/**
|
|
18
|
+
* Resolve encryption method based on explicit method or local preference.
|
|
19
|
+
*/
|
|
20
|
+
declare const resolveEncryptionMethod: (method: EncryptionMethod | undefined, localConfig: IConfig) => EncryptionMethod;
|
|
21
|
+
/**
|
|
22
|
+
* Normalize remote E2E version and reject unsupported versions.
|
|
23
|
+
*/
|
|
24
|
+
declare const resolveE2EVersion: (version?: number) => E2EVersion;
|
|
25
|
+
/**
|
|
26
|
+
* Read a JSON config file using comment-json to preserve comments and metadata.
|
|
27
|
+
*/
|
|
28
|
+
declare const readConfigWithComments: (filePath: string) => Promise<ConfigValue>;
|
|
29
|
+
/**
|
|
30
|
+
* Write a JSON config file using comment-json to preserve comments and metadata.
|
|
31
|
+
*/
|
|
32
|
+
declare const writeConfigWithComments: (filePath: string, config: ConfigValue) => Promise<void>;
|
|
33
|
+
/**
|
|
34
|
+
* Load snapshot data from disk, handling legacy plain-object snapshots.
|
|
35
|
+
*/
|
|
36
|
+
declare const loadSnapshot: (snapshotPath: string) => Promise<ISnapshot>;
|
|
37
|
+
/**
|
|
38
|
+
* Persist snapshot data to disk with version and timestamp metadata.
|
|
39
|
+
*/
|
|
40
|
+
declare const saveSnapshot: (snapshotPath: string, config: ConfigValue, version: number) => Promise<void>;
|
|
41
|
+
export { IGNORED_PATHS, ENCRYPTION_METHOD_PATH, getLocalEncryptionMethod, loadSnapshot, maskIgnoredFields, readConfigWithComments, resolveE2EVersion, resolveEncryptionMethod, saveSnapshot, writeConfigWithComments };
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import type { Handler, MiddlewareHandler } from 'hono';
|
|
2
|
+
import type { IPicGo, IServerManager, PluginRouterSetup } from '../../types';
|
|
3
|
+
declare class ServerManager implements IServerManager {
|
|
4
|
+
private app;
|
|
5
|
+
private readonly ctx;
|
|
6
|
+
private server?;
|
|
7
|
+
private listeningPort?;
|
|
8
|
+
private listeningHost?;
|
|
9
|
+
private authSecret?;
|
|
10
|
+
private warnedQuerySecret;
|
|
11
|
+
private staticRoutePrefixes;
|
|
12
|
+
constructor(ctx: IPicGo);
|
|
13
|
+
registerGet<P extends string>(path: P, handler: Handler<any, P>, isInternal?: boolean): void;
|
|
14
|
+
registerPost<P extends string>(path: P, handler: Handler<any, P>, isInternal?: boolean): void;
|
|
15
|
+
registerPut<P extends string>(path: P, handler: Handler<any, P>, isInternal?: boolean): void;
|
|
16
|
+
registerDelete<P extends string>(path: P, handler: Handler<any, P>, isInternal?: boolean): void;
|
|
17
|
+
registerMiddleware<P extends string>(path: P, handler: MiddlewareHandler<any, P>): void;
|
|
18
|
+
registerStatic(path: string, root: string): void;
|
|
19
|
+
private handleRegister;
|
|
20
|
+
mount(path: string, setup: PluginRouterSetup): void;
|
|
21
|
+
getServerInfo(): string;
|
|
22
|
+
isListening(): boolean;
|
|
23
|
+
private initMiddleware;
|
|
24
|
+
private initCoreRoutes;
|
|
25
|
+
private t;
|
|
26
|
+
private getRequestPath;
|
|
27
|
+
private isStaticPath;
|
|
28
|
+
private shouldSkipAuth;
|
|
29
|
+
private extractAuthToken;
|
|
30
|
+
private warnQuerySecretOnce;
|
|
31
|
+
private getClientIp;
|
|
32
|
+
private logUnauthorized;
|
|
33
|
+
private handleAuth;
|
|
34
|
+
private startServer;
|
|
35
|
+
private isExistingPicGoServer;
|
|
36
|
+
listen(port?: number, host?: string, ignoreExistingExternalServer?: boolean, secret?: string): Promise<number | void>;
|
|
37
|
+
shutdown(): void;
|
|
38
|
+
}
|
|
39
|
+
export { ServerManager };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Hono } from 'hono';
|
|
2
|
+
import { IPicGo } from '../../types';
|
|
3
|
+
/**
|
|
4
|
+
* Route overriding helper.
|
|
5
|
+
*
|
|
6
|
+
* Logic:
|
|
7
|
+
* 1. Business routes (GET/POST/...): last registration wins (override).
|
|
8
|
+
* 2. Middlewares (ALL): preserve all in order (append).
|
|
9
|
+
*/
|
|
10
|
+
export declare const rebuildApp: <T extends Hono<any, any, any>>(draftApp: T, ctx: IPicGo) => T;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { IPlugin } from '../../types';
|
|
1
|
+
import type { IPlugin } from '../../types';
|
|
2
2
|
declare const config: IPlugin;
|
|
3
|
-
export
|
|
3
|
+
export { config };
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { IPicGo } from '../../types';
|
|
2
|
-
declare const
|
|
3
|
-
export
|
|
2
|
+
declare const commanders: (ctx: IPicGo) => void;
|
|
3
|
+
export { commanders };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { type IDiffNode } from '../../lib/ConfigSyncManager';
|
|
2
|
+
/**
|
|
3
|
+
* Format a config value for CLI output, falling back to util.inspect when JSON fails.
|
|
4
|
+
*/
|
|
5
|
+
declare const formatConfigValue: (value: unknown) => string;
|
|
6
|
+
/**
|
|
7
|
+
* Print a diff tree with colorized status labels for conflict resolution output.
|
|
8
|
+
*/
|
|
9
|
+
declare const printDiffTree: (node: IDiffNode, indent?: number) => void;
|
|
10
|
+
export { formatConfigValue, printDiffTree };
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,6 +1,56 @@
|
|
|
1
1
|
import { Command } from 'commander';
|
|
2
2
|
import { Inquirer } from 'inquirer';
|
|
3
3
|
import { IRequestPromiseOptions } from './oldRequest';
|
|
4
|
+
import type { Env, Handler, Hono, MiddlewareHandler } from 'hono';
|
|
5
|
+
/**
|
|
6
|
+
* Type definition for the plugin router setup callback.
|
|
7
|
+
* The plugin receives a Hono instance created by the Host.
|
|
8
|
+
*/
|
|
9
|
+
export type PluginRouterSetup = (router: Hono<any, any, any>) => void;
|
|
10
|
+
export interface IServerManager<E extends Env = any> {
|
|
11
|
+
/**
|
|
12
|
+
*
|
|
13
|
+
* @param port
|
|
14
|
+
* @param host
|
|
15
|
+
* @param ignoreExistingExternalServer PicGo GUI may start a server instance already, if you want to start a new one, set this to true
|
|
16
|
+
* @param secret shared secret for server authentication
|
|
17
|
+
* @returns
|
|
18
|
+
*/
|
|
19
|
+
listen: (port?: number, host?: string, ignoreExistingExternalServer?: boolean, secret?: string) => Promise<number | void>;
|
|
20
|
+
shutdown: () => void;
|
|
21
|
+
isListening: () => boolean;
|
|
22
|
+
/**
|
|
23
|
+
* Get current server listening address if running.
|
|
24
|
+
* e.g. "http://127.0.0.1:36677/"
|
|
25
|
+
*/
|
|
26
|
+
getServerInfo: () => string;
|
|
27
|
+
registerGet<P extends string>(path: P, handler: Handler<E, P>): void;
|
|
28
|
+
registerPost<P extends string>(path: P, handler: Handler<E, P>): void;
|
|
29
|
+
registerPut<P extends string>(path: P, handler: Handler<E, P>): void;
|
|
30
|
+
registerDelete<P extends string>(path: P, handler: Handler<E, P>): void;
|
|
31
|
+
registerMiddleware<P extends string>(path: P, handler: MiddlewareHandler<E, P>): void;
|
|
32
|
+
/**
|
|
33
|
+
* Register a static file server route.
|
|
34
|
+
* @param path - The URL prefix (e.g. '/static')
|
|
35
|
+
* @param root - The local file system path
|
|
36
|
+
*/
|
|
37
|
+
registerStatic: (path: string, root: string) => void;
|
|
38
|
+
/**
|
|
39
|
+
* Mount a sub-router for plugins.
|
|
40
|
+
*
|
|
41
|
+
* PicGo creates a new Hono instance (to ensure version consistency)
|
|
42
|
+
* and passes it to the setup callback for the plugin to configure.
|
|
43
|
+
*/
|
|
44
|
+
mount: (path: string, setup: PluginRouterSetup) => void;
|
|
45
|
+
}
|
|
46
|
+
export interface ICloudManager {
|
|
47
|
+
login: (token?: string) => Promise<void>;
|
|
48
|
+
logout: () => void;
|
|
49
|
+
disposeLoginFlow: () => void;
|
|
50
|
+
getUserInfo: () => Promise<{
|
|
51
|
+
user: string;
|
|
52
|
+
} | null>;
|
|
53
|
+
}
|
|
4
54
|
export interface IPicGo extends NodeJS.EventEmitter {
|
|
5
55
|
/**
|
|
6
56
|
* picgo configPath
|
|
@@ -20,6 +70,14 @@ export interface IPicGo extends NodeJS.EventEmitter {
|
|
|
20
70
|
* picgo commander, for cli
|
|
21
71
|
*/
|
|
22
72
|
cmd: ICommander;
|
|
73
|
+
/**
|
|
74
|
+
* picgo server manager
|
|
75
|
+
*/
|
|
76
|
+
server: IServerManager;
|
|
77
|
+
/**
|
|
78
|
+
* picgo cloud manager
|
|
79
|
+
*/
|
|
80
|
+
cloud: ICloudManager;
|
|
23
81
|
/**
|
|
24
82
|
* after transformer, the input will be output
|
|
25
83
|
*/
|
|
@@ -68,11 +126,18 @@ export interface IPicGo extends NodeJS.EventEmitter {
|
|
|
68
126
|
* http request tool
|
|
69
127
|
*/
|
|
70
128
|
request: IRequest['request'];
|
|
129
|
+
/**
|
|
130
|
+
* Opens a URL in the default browser.
|
|
131
|
+
*
|
|
132
|
+
* Default implementation uses the `open` package in Node.js.
|
|
133
|
+
* Consumers (Electron/VSCode extensions) can overwrite this method.
|
|
134
|
+
*/
|
|
135
|
+
openUrl: (url: string) => Promise<void>;
|
|
71
136
|
i18n: II18nManager;
|
|
72
137
|
/**
|
|
73
138
|
* get picgo config
|
|
74
139
|
*/
|
|
75
|
-
getConfig: <T>(name?: string) => T;
|
|
140
|
+
getConfig: <T = unknown>(name?: string) => T;
|
|
76
141
|
/**
|
|
77
142
|
* save picgo config to configPath
|
|
78
143
|
*/
|
|
@@ -396,6 +461,17 @@ export interface IConfig {
|
|
|
396
461
|
npmRegistry?: string;
|
|
397
462
|
/** for npm */
|
|
398
463
|
npmProxy?: string;
|
|
464
|
+
picgoCloud?: {
|
|
465
|
+
token?: string;
|
|
466
|
+
[others: string]: any;
|
|
467
|
+
};
|
|
468
|
+
server?: {
|
|
469
|
+
port?: number;
|
|
470
|
+
host?: string;
|
|
471
|
+
enable?: boolean;
|
|
472
|
+
secret?: string;
|
|
473
|
+
[others: string]: any;
|
|
474
|
+
};
|
|
399
475
|
[others: string]: any;
|
|
400
476
|
};
|
|
401
477
|
[configOptions: string]: any;
|
|
@@ -515,7 +591,7 @@ export interface IProcessEnv {
|
|
|
515
591
|
[propName: string]: Undefinable<string>;
|
|
516
592
|
}
|
|
517
593
|
export type ILogArgvType = string | number;
|
|
518
|
-
export type ILogArgvTypeWithError = ILogArgvType | Error;
|
|
594
|
+
export type ILogArgvTypeWithError = ILogArgvType | Error | unknown;
|
|
519
595
|
export type Nullable<T> = T | null;
|
|
520
596
|
export type Undefinable<T> = T | undefined;
|
|
521
597
|
export interface ILogger {
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { Env, Handler } from "hono";
|
|
2
|
+
import { IServerManager } from ".";
|
|
3
|
+
export interface IInternalServerManager<E extends Env = any> extends IServerManager<E> {
|
|
4
|
+
registerGet<P extends string>(path: P, handler: Handler<E, P>, isInternal?: boolean): void;
|
|
5
|
+
registerPost<P extends string>(path: P, handler: Handler<E, P>, isInternal?: boolean): void;
|
|
6
|
+
registerPut<P extends string>(path: P, handler: Handler<E, P>, isInternal?: boolean): void;
|
|
7
|
+
registerDelete<P extends string>(path: P, handler: Handler<E, P>, isInternal?: boolean): void;
|
|
8
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "picgo",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0",
|
|
4
4
|
"description": "A tool for picture uploading",
|
|
5
5
|
"main": "dist/index.cjs.js",
|
|
6
6
|
"module": "dist/index.esm.js",
|
|
@@ -60,6 +60,7 @@
|
|
|
60
60
|
"copyfiles": "^2.1.0",
|
|
61
61
|
"cross-env": "^7.0.3",
|
|
62
62
|
"cz-customizable": "^7.5.1",
|
|
63
|
+
"dpdm": "^3.14.0",
|
|
63
64
|
"eslint": "^9.39.1",
|
|
64
65
|
"eslint-config-prettier": "^10.1.8",
|
|
65
66
|
"eslint-plugin-import": "^2.32.0",
|
|
@@ -75,6 +76,7 @@
|
|
|
75
76
|
"vitest": "^4.0.16"
|
|
76
77
|
},
|
|
77
78
|
"dependencies": {
|
|
79
|
+
"@hono/node-server": "^1.19.7",
|
|
78
80
|
"@picgo/i18n": "^1.0.0",
|
|
79
81
|
"@picgo/store": "^2.0.2",
|
|
80
82
|
"axios": "^1.13.2",
|
|
@@ -83,8 +85,13 @@
|
|
|
83
85
|
"comment-json": "^4.5.1",
|
|
84
86
|
"cross-spawn": "^6.0.5",
|
|
85
87
|
"dayjs": "^1.7.4",
|
|
88
|
+
"dotenv": "^17.2.3",
|
|
89
|
+
"ejs": "^3.1.10",
|
|
86
90
|
"form-data": "^4.0.5",
|
|
87
91
|
"fs-extra": "^6.0.1",
|
|
92
|
+
"giget": "^2.0.0",
|
|
93
|
+
"globby": "^11.0.4",
|
|
94
|
+
"hono": "^4.11.3",
|
|
88
95
|
"image-size": "^0.8.3",
|
|
89
96
|
"inquirer": "^6.0.0",
|
|
90
97
|
"is-wsl": "^2.2.0",
|
|
@@ -93,6 +100,7 @@
|
|
|
93
100
|
"md5": "^2.2.1",
|
|
94
101
|
"mime-types": "3.0.2",
|
|
95
102
|
"minimist": "^1.2.5",
|
|
103
|
+
"open": "^11.0.0",
|
|
96
104
|
"resolve": "^1.8.1",
|
|
97
105
|
"tunnel": "^0.0.6"
|
|
98
106
|
},
|
|
@@ -105,11 +113,11 @@
|
|
|
105
113
|
},
|
|
106
114
|
"plugins": {},
|
|
107
115
|
"engines": {
|
|
108
|
-
"node": ">=
|
|
116
|
+
"node": ">= 20.19.0"
|
|
109
117
|
},
|
|
110
118
|
"scripts": {
|
|
111
119
|
"start": "node ./bin/picgo",
|
|
112
|
-
"lint": "tsc --noEmit && eslint src --ext .ts",
|
|
120
|
+
"lint": "pnpm lint:dpdm && tsc --noEmit && eslint src --ext .ts",
|
|
113
121
|
"test": "vitest run",
|
|
114
122
|
"build": "cross-env NODE_ENV=production rimraf ./dist && rollup -c rollup.config.js",
|
|
115
123
|
"dev": "cross-env NODE_ENV=development rollup -c rollup.config.js -w",
|
|
@@ -118,6 +126,7 @@
|
|
|
118
126
|
"major": "npm version major && git push origin master && git push origin --tags",
|
|
119
127
|
"cz": "git-cz",
|
|
120
128
|
"release": "bump-version",
|
|
121
|
-
"commitlint": "commitlint --edit"
|
|
129
|
+
"commitlint": "commitlint --edit",
|
|
130
|
+
"lint:dpdm": "dpdm -T --tsconfig ./tsconfig.json --no-tree --no-warning --exit-code circular:1 src/index.ts"
|
|
122
131
|
}
|
|
123
132
|
}
|
package/vitest.config.ts
ADDED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|