koishi-plugin-chatluna-storage-service 0.0.11 → 1.0.1

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.
@@ -0,0 +1,74 @@
1
+ /**
2
+ * Storage backend interface and types
3
+ */
4
+ export interface StorageResult {
5
+ /** Unique key/path for the stored file */
6
+ key: string;
7
+ /** Public URL if backend supports it, undefined otherwise */
8
+ publicUrl?: string;
9
+ }
10
+ export interface StorageBackend {
11
+ /** Backend type identifier */
12
+ readonly type: StorageBackendType;
13
+ /** Whether this backend provides public URLs */
14
+ readonly hasPublicUrl: boolean;
15
+ /**
16
+ * Upload a file to storage
17
+ * @param buffer File content
18
+ * @param filename Original filename
19
+ * @returns Storage result with key and optional public URL
20
+ */
21
+ upload(buffer: Buffer, filename: string): Promise<StorageResult>;
22
+ /**
23
+ * Download a file from storage
24
+ * @param key File key/path
25
+ * @returns File content as Buffer
26
+ */
27
+ download(key: string): Promise<Buffer>;
28
+ /**
29
+ * Delete a file from storage
30
+ * @param key File key/path
31
+ */
32
+ delete(key: string): Promise<void>;
33
+ /**
34
+ * Check if a file exists in storage
35
+ * @param key File key/path
36
+ */
37
+ exists(key: string): Promise<boolean>;
38
+ /**
39
+ * Initialize the storage backend
40
+ */
41
+ init(): Promise<void>;
42
+ }
43
+ export type StorageBackendType = 'local' | 's3' | 'webdav' | 'r2';
44
+ export interface LocalStorageConfig {
45
+ type: 'local';
46
+ storagePath: string;
47
+ }
48
+ export interface S3StorageConfig {
49
+ type: 's3';
50
+ endpoint: string;
51
+ bucket: string;
52
+ region: string;
53
+ accessKeyId: string;
54
+ secretAccessKey: string;
55
+ publicUrl?: string;
56
+ pathStyle?: boolean;
57
+ }
58
+ export interface WebDAVStorageConfig {
59
+ type: 'webdav';
60
+ endpoint: string;
61
+ username?: string;
62
+ password?: string;
63
+ basePath?: string;
64
+ publicUrl?: string;
65
+ }
66
+ export interface R2StorageConfig {
67
+ type: 'r2';
68
+ accountId: string;
69
+ bucket: string;
70
+ accessKeyId: string;
71
+ secretAccessKey: string;
72
+ publicUrl?: string;
73
+ }
74
+ export type StorageConfig = LocalStorageConfig | S3StorageConfig | WebDAVStorageConfig | R2StorageConfig;
@@ -0,0 +1,7 @@
1
+ export * from './base';
2
+ export { LocalStorageBackend } from './local';
3
+ export { S3StorageBackend } from './s3';
4
+ export { WebDAVStorageBackend } from './webdav';
5
+ export { R2StorageBackend } from './r2';
6
+ import { StorageBackend, StorageConfig } from './base';
7
+ export declare function createStorageBackend(config: StorageConfig): StorageBackend;
@@ -0,0 +1,13 @@
1
+ import { StorageBackend, StorageResult, LocalStorageConfig } from './base';
2
+ export declare class LocalStorageBackend implements StorageBackend {
3
+ private config;
4
+ readonly type: "local";
5
+ readonly hasPublicUrl = false;
6
+ private basePath;
7
+ constructor(config: LocalStorageConfig);
8
+ init(): Promise<void>;
9
+ upload(buffer: Buffer, filename: string): Promise<StorageResult>;
10
+ download(key: string): Promise<Buffer>;
11
+ delete(key: string): Promise<void>;
12
+ exists(key: string): Promise<boolean>;
13
+ }
@@ -0,0 +1,19 @@
1
+ import { StorageBackend, StorageResult, R2StorageConfig } from './base';
2
+ /**
3
+ * Cloudflare R2 Storage Backend
4
+ * R2 is S3-compatible, but uses a specific endpoint format
5
+ */
6
+ export declare class R2StorageBackend implements StorageBackend {
7
+ private config;
8
+ readonly type: "r2";
9
+ readonly hasPublicUrl: boolean;
10
+ private endpoint;
11
+ constructor(config: R2StorageConfig);
12
+ init(): Promise<void>;
13
+ upload(buffer: Buffer, filename: string): Promise<StorageResult>;
14
+ download(key: string): Promise<Buffer>;
15
+ delete(key: string): Promise<void>;
16
+ exists(key: string): Promise<boolean>;
17
+ private generateAuthorizationHeader;
18
+ private getSigningKey;
19
+ }
@@ -0,0 +1,15 @@
1
+ import { StorageBackend, StorageResult, S3StorageConfig } from './base';
2
+ export declare class S3StorageBackend implements StorageBackend {
3
+ private config;
4
+ readonly type: "s3";
5
+ readonly hasPublicUrl: boolean;
6
+ constructor(config: S3StorageConfig);
7
+ init(): Promise<void>;
8
+ upload(buffer: Buffer, filename: string): Promise<StorageResult>;
9
+ download(key: string): Promise<Buffer>;
10
+ delete(key: string): Promise<void>;
11
+ exists(key: string): Promise<boolean>;
12
+ private buildS3Url;
13
+ private generateAuthorizationHeader;
14
+ private getSigningKey;
15
+ }
@@ -0,0 +1,18 @@
1
+ import { StorageBackend, StorageResult, WebDAVStorageConfig } from './base';
2
+ export declare class WebDAVStorageBackend implements StorageBackend {
3
+ private config;
4
+ readonly type: "webdav";
5
+ readonly hasPublicUrl: boolean;
6
+ private basePath;
7
+ constructor(config: WebDAVStorageConfig);
8
+ init(): Promise<void>;
9
+ upload(buffer: Buffer, filename: string): Promise<StorageResult>;
10
+ download(key: string): Promise<Buffer>;
11
+ delete(key: string): Promise<void>;
12
+ exists(key: string): Promise<boolean>;
13
+ private ensureBasePath;
14
+ private ensureDirectory;
15
+ private b64;
16
+ private trimSlash;
17
+ private encodePath;
18
+ }