@simplysm/storage 14.0.50 → 14.0.52
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/package.json +3 -4
- package/README.md +0 -84
- package/docs/clients/ftp-storage-client.md +0 -47
- package/docs/clients/sftp-storage-client.md +0 -58
- package/docs/factory/storage-factory.md +0 -82
- package/docs/types/file-info.md +0 -32
- package/docs/types/storage-client.md +0 -50
- package/docs/types/storage-conn-config.md +0 -34
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@simplysm/storage",
|
|
3
|
-
"version": "14.0.
|
|
3
|
+
"version": "14.0.52",
|
|
4
4
|
"description": "심플리즘 패키지 - 저장소 (node)",
|
|
5
5
|
"author": "심플리즘",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -14,14 +14,13 @@
|
|
|
14
14
|
"types": "./dist/index.d.ts",
|
|
15
15
|
"files": [
|
|
16
16
|
"dist",
|
|
17
|
-
"src"
|
|
18
|
-
"docs"
|
|
17
|
+
"src"
|
|
19
18
|
],
|
|
20
19
|
"sideEffects": false,
|
|
21
20
|
"dependencies": {
|
|
22
21
|
"basic-ftp": "^5.3.0",
|
|
23
22
|
"ssh2-sftp-client": "^12.1.1",
|
|
24
|
-
"@simplysm/core-common": "14.0.
|
|
23
|
+
"@simplysm/core-common": "14.0.52"
|
|
25
24
|
},
|
|
26
25
|
"devDependencies": {
|
|
27
26
|
"@types/ssh2-sftp-client": "^9.0.6"
|
package/README.md
DELETED
|
@@ -1,84 +0,0 @@
|
|
|
1
|
-
# @simplysm/storage
|
|
2
|
-
|
|
3
|
-
FTP/FTPS/SFTP 파일 저장소 클라이언트 라이브러리 (Node.js 전용). `StorageClient` 인터페이스로 프로토콜을 통일하고, `StorageFactory`로 연결 생명주기를 관리한다.
|
|
4
|
-
|
|
5
|
-
## Installation
|
|
6
|
-
|
|
7
|
-
```bash
|
|
8
|
-
npm install @simplysm/storage
|
|
9
|
-
```
|
|
10
|
-
|
|
11
|
-
## API Overview
|
|
12
|
-
|
|
13
|
-
### Types
|
|
14
|
-
|
|
15
|
-
| Entry | Kind | Description |
|
|
16
|
-
|-------|------|-------------|
|
|
17
|
-
| [`StorageConnConfig`](./docs/types/storage-conn-config.md) | interface | 스토리지 서버 연결 설정 |
|
|
18
|
-
| [`FileInfo`](./docs/types/file-info.md) | interface | 파일/디렉토리 정보 |
|
|
19
|
-
| [`StorageClient`](./docs/types/storage-client.md) | interface | 스토리지 클라이언트 공통 인터페이스 (포함: `StorageProtocol`) |
|
|
20
|
-
|
|
21
|
-
### Clients
|
|
22
|
-
|
|
23
|
-
| Entry | Kind | Description |
|
|
24
|
-
|-------|------|-------------|
|
|
25
|
-
| [`FtpStorageClient`](./docs/clients/ftp-storage-client.md) | class | FTP/FTPS 프로토콜 스토리지 클라이언트 (`basic-ftp` 기반) |
|
|
26
|
-
| [`SftpStorageClient`](./docs/clients/sftp-storage-client.md) | class | SFTP 프로토콜 스토리지 클라이언트 (`ssh2-sftp-client` 기반) |
|
|
27
|
-
|
|
28
|
-
### Factory
|
|
29
|
-
|
|
30
|
-
| Entry | Kind | Description |
|
|
31
|
-
|-------|------|-------------|
|
|
32
|
-
| [`StorageFactory`](./docs/factory/storage-factory.md) | class | 프로토콜별 클라이언트 생성 및 연결 생명주기 자동 관리 (포함: `StorageProtocol`) |
|
|
33
|
-
|
|
34
|
-
## Usage Examples
|
|
35
|
-
|
|
36
|
-
### SFTP로 파일 업로드 (StorageFactory 사용 권장)
|
|
37
|
-
|
|
38
|
-
```typescript
|
|
39
|
-
import { StorageFactory } from "@simplysm/storage";
|
|
40
|
-
|
|
41
|
-
await StorageFactory.connect(
|
|
42
|
-
"sftp",
|
|
43
|
-
{ host: "sftp.example.com", user: "user", password: "pass" },
|
|
44
|
-
async (storage) => {
|
|
45
|
-
await storage.mkdir("/remote/dir");
|
|
46
|
-
await storage.put("/local/file.txt", "/remote/dir/file.txt");
|
|
47
|
-
},
|
|
48
|
-
);
|
|
49
|
-
```
|
|
50
|
-
|
|
51
|
-
콜백이 완료되거나 예외가 발생하면 자동으로 연결이 종료된다.
|
|
52
|
-
|
|
53
|
-
### FTP로 파일 목록 조회 및 다운로드
|
|
54
|
-
|
|
55
|
-
```typescript
|
|
56
|
-
import { StorageFactory } from "@simplysm/storage";
|
|
57
|
-
|
|
58
|
-
const files = await StorageFactory.connect(
|
|
59
|
-
"ftp",
|
|
60
|
-
{ host: "ftp.example.com", port: 21, user: "user", password: "pass" },
|
|
61
|
-
async (storage) => {
|
|
62
|
-
const list = await storage.list("/data");
|
|
63
|
-
for (const file of list.filter((f) => f.isFile)) {
|
|
64
|
-
const content = await storage.readFile(`/data/${file.name}`);
|
|
65
|
-
// content는 Bytes (Uint8Array)
|
|
66
|
-
}
|
|
67
|
-
return list;
|
|
68
|
-
},
|
|
69
|
-
);
|
|
70
|
-
```
|
|
71
|
-
|
|
72
|
-
### SSH 키 인증으로 SFTP 연결 (비밀번호 생략)
|
|
73
|
-
|
|
74
|
-
```typescript
|
|
75
|
-
import { StorageFactory } from "@simplysm/storage";
|
|
76
|
-
|
|
77
|
-
await StorageFactory.connect(
|
|
78
|
-
"sftp",
|
|
79
|
-
{ host: "sftp.example.com", user: "user" }, // password 생략 → SSH agent/키 파일 인증
|
|
80
|
-
async (storage) => {
|
|
81
|
-
const list = await storage.list("/home/user");
|
|
82
|
-
},
|
|
83
|
-
);
|
|
84
|
-
```
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
# FtpStorageClient
|
|
2
|
-
|
|
3
|
-
FTP/FTPS 프로토콜을 사용하는 스토리지 클라이언트. `basic-ftp` 라이브러리 기반. [`StorageClient`](../types/storage-client.md) 인터페이스를 구현한다.
|
|
4
|
-
|
|
5
|
-
직접 사용하기보다 [`StorageFactory.connect()`](../factory/storage-factory.md)를 통해 콜백 패턴으로 사용하는 것을 권장한다.
|
|
6
|
-
|
|
7
|
-
```typescript
|
|
8
|
-
class FtpStorageClient implements StorageClient {
|
|
9
|
-
constructor(private readonly _secure: boolean = false);
|
|
10
|
-
}
|
|
11
|
-
```
|
|
12
|
-
|
|
13
|
-
## Constructor
|
|
14
|
-
|
|
15
|
-
| Parameter | Type | Default | Description |
|
|
16
|
-
|-----------|------|---------|-------------|
|
|
17
|
-
| `_secure` | `boolean` | `false` | `true`이면 FTPS (TLS/SSL 암호화), `false`이면 FTP |
|
|
18
|
-
|
|
19
|
-
## Members
|
|
20
|
-
|
|
21
|
-
[`StorageClient`](../types/storage-client.md) 인터페이스의 모든 메서드를 구현한다. 구현 특이사항:
|
|
22
|
-
|
|
23
|
-
| Member | Kind | Description |
|
|
24
|
-
|--------|------|-------------|
|
|
25
|
-
| `connect` | method | 이미 연결된 상태에서 호출하면 `SdError` 발생. 연결 실패 시 내부 `ftp.Client`를 즉시 닫고 예외를 전파 |
|
|
26
|
-
| `mkdir` | method | `basic-ftp`의 `ensureDir()`을 사용하여 부모 디렉토리 포함 재귀 생성 |
|
|
27
|
-
| `exists` | method | 먼저 `size()` 명령으로 파일을 O(1) 성능으로 확인. 실패 시 부모 디렉토리 `list()`로 디렉토리 존재 여부 확인. 슬래시 없는 경로(예: `file.txt`)는 루트(`/`)에서 검색. 모든 예외는 `false` 반환 |
|
|
28
|
-
| `put` | method | `string`이면 파일 경로로, `Bytes`이면 `Readable` 스트림으로 변환하여 `uploadFrom()` 호출 |
|
|
29
|
-
| `close` | method | 동기적으로 내부 클라이언트를 정리하고 `Promise.resolve()` 반환. 이미 종료된 상태에서 호출해도 안전 |
|
|
30
|
-
|
|
31
|
-
## Usage
|
|
32
|
-
|
|
33
|
-
```typescript
|
|
34
|
-
import { FtpStorageClient } from "@simplysm/storage";
|
|
35
|
-
|
|
36
|
-
// FTPS 사용
|
|
37
|
-
const client = new FtpStorageClient(true);
|
|
38
|
-
try {
|
|
39
|
-
await client.connect({ host: "ftps.example.com", user: "user", password: "pass" });
|
|
40
|
-
const exists = await client.exists("/remote/file.txt");
|
|
41
|
-
if (exists) {
|
|
42
|
-
await client.rename("/remote/file.txt", "/remote/backup.txt");
|
|
43
|
-
}
|
|
44
|
-
} finally {
|
|
45
|
-
await client.close();
|
|
46
|
-
}
|
|
47
|
-
```
|
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
# SftpStorageClient
|
|
2
|
-
|
|
3
|
-
SFTP 프로토콜을 사용하는 스토리지 클라이언트. `ssh2-sftp-client` 라이브러리 기반. [`StorageClient`](../types/storage-client.md) 인터페이스를 구현한다.
|
|
4
|
-
|
|
5
|
-
직접 사용하기보다 [`StorageFactory.connect()`](../factory/storage-factory.md)를 통해 콜백 패턴으로 사용하는 것을 권장한다.
|
|
6
|
-
|
|
7
|
-
```typescript
|
|
8
|
-
class SftpStorageClient implements StorageClient {
|
|
9
|
-
constructor();
|
|
10
|
-
}
|
|
11
|
-
```
|
|
12
|
-
|
|
13
|
-
## Members
|
|
14
|
-
|
|
15
|
-
[`StorageClient`](../types/storage-client.md) 인터페이스의 모든 메서드를 구현한다. 구현 특이사항:
|
|
16
|
-
|
|
17
|
-
| Member | Kind | Description |
|
|
18
|
-
|--------|------|-------------|
|
|
19
|
-
| `connect` | method | 이미 연결된 상태에서 호출하면 `SdError` 발생. `password` 유무에 따라 인증 방식이 달라짐 (아래 인증 메커니즘 참조). 연결 실패 시 `client.end()`를 호출하고 예외를 전파 |
|
|
20
|
-
| `mkdir` | method | `ssh2-sftp-client`의 `mkdir(path, true)`를 호출하여 부모 디렉토리 포함 재귀 생성 |
|
|
21
|
-
| `list` | method | `item.type === "-"`이면 파일(`isFile: true`), 아니면 디렉토리(`isFile: false`)로 변환 |
|
|
22
|
-
| `exists` | method | `ssh2-sftp-client`의 `exists()` 반환값(`false \| 'd' \| '-' \| 'l'`)을 검사. 문자열이면 존재. 모든 예외는 `false` 반환 |
|
|
23
|
-
| `readFile` | method | `ssh2-sftp-client`의 `get()` 반환값(`Buffer` 또는 `string`)을 `Bytes`(`Uint8Array`)로 변환 |
|
|
24
|
-
| `put` | method | `string`이면 `fastPut()`으로, `Bytes`이면 `Buffer.from()` 변환 후 `put()`으로 업로드 (`ssh2-sftp-client` 라이브러리 요구사항) |
|
|
25
|
-
| `close` | method | `client.end()`를 호출하여 연결 종료. 이미 종료된 상태에서 호출해도 안전 |
|
|
26
|
-
|
|
27
|
-
## Authentication
|
|
28
|
-
|
|
29
|
-
`connect()` 호출 시 [`StorageConnConfig`](../types/storage-conn-config.md)의 `password` 유무에 따라 인증 방식이 결정된다:
|
|
30
|
-
|
|
31
|
-
**`password`가 있는 경우**: 패스워드 인증
|
|
32
|
-
|
|
33
|
-
**`password`가 없는 경우**: 다음 순서로 시도
|
|
34
|
-
1. SSH agent (`SSH_AUTH_SOCK` 환경변수가 설정된 경우 `agent` 옵션 추가)
|
|
35
|
-
2. `~/.ssh/id_ed25519` 개인키 파일 읽어 `privateKey` 옵션으로 인증 시도
|
|
36
|
-
3. `privateKey` 파싱 실패 시 (암호화된 키 등) SSH agent만으로 재시도
|
|
37
|
-
|
|
38
|
-
## Usage
|
|
39
|
-
|
|
40
|
-
```typescript
|
|
41
|
-
import { SftpStorageClient } from "@simplysm/storage";
|
|
42
|
-
|
|
43
|
-
// 패스워드 인증
|
|
44
|
-
const client = new SftpStorageClient();
|
|
45
|
-
try {
|
|
46
|
-
await client.connect({ host: "sftp.example.com", user: "user", password: "pass" });
|
|
47
|
-
await client.mkdir("/remote/dir");
|
|
48
|
-
await client.put("/local/file.txt", "/remote/dir/file.txt");
|
|
49
|
-
} finally {
|
|
50
|
-
await client.close();
|
|
51
|
-
}
|
|
52
|
-
```
|
|
53
|
-
|
|
54
|
-
SSH 키 인증 사용 시 `password` 필드를 생략한다:
|
|
55
|
-
|
|
56
|
-
```typescript
|
|
57
|
-
await client.connect({ host: "sftp.example.com", user: "user" }); // password 생략
|
|
58
|
-
```
|
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
# StorageFactory
|
|
2
|
-
|
|
3
|
-
스토리지 클라이언트 팩토리. 콜백 패턴으로 연결/종료를 자동 관리한다.
|
|
4
|
-
|
|
5
|
-
```typescript
|
|
6
|
-
class StorageFactory {
|
|
7
|
-
static async connect<R>(
|
|
8
|
-
type: StorageProtocol,
|
|
9
|
-
config: StorageConnConfig,
|
|
10
|
-
fn: (storage: StorageClient) => R | Promise<R>,
|
|
11
|
-
): Promise<R>;
|
|
12
|
-
}
|
|
13
|
-
```
|
|
14
|
-
|
|
15
|
-
## Members
|
|
16
|
-
|
|
17
|
-
| Member | Kind | Type | Description |
|
|
18
|
-
|--------|------|------|-------------|
|
|
19
|
-
| `connect` | static | `<R>(type: StorageProtocol, config: StorageConnConfig, fn: (storage: StorageClient) => R \| Promise<R>) => Promise<R>` | 프로토콜에 맞는 클라이언트를 생성하고, 연결 후 콜백을 실행하며, 완료/예외 시 자동으로 연결을 종료 |
|
|
20
|
-
|
|
21
|
-
### `connect<R>()` 파라미터
|
|
22
|
-
|
|
23
|
-
| Parameter | Type | Description |
|
|
24
|
-
|-----------|------|-------------|
|
|
25
|
-
| `type` | `StorageProtocol` | 프로토콜 타입 |
|
|
26
|
-
| `config` | [`StorageConnConfig`](../types/storage-conn-config.md) | 연결 설정 |
|
|
27
|
-
| `fn` | `(storage: StorageClient) => R \| Promise<R>` | 연결된 클라이언트로 작업을 수행하는 콜백 |
|
|
28
|
-
|
|
29
|
-
**반환**: `Promise<R>` — 콜백의 반환값
|
|
30
|
-
|
|
31
|
-
**동작**:
|
|
32
|
-
- `type`에 따라 [`FtpStorageClient`](../clients/ftp-storage-client.md) 또는 [`SftpStorageClient`](../clients/sftp-storage-client.md)를 생성
|
|
33
|
-
- `client.connect(config)` 후 `fn(client)` 실행
|
|
34
|
-
- `fn` 완료 또는 예외 발생 여부와 무관하게 `finally`에서 `client.close()` 호출
|
|
35
|
-
- `fn`에서 발생한 예외는 그대로 전파
|
|
36
|
-
|
|
37
|
-
## Related Types
|
|
38
|
-
|
|
39
|
-
### `StorageProtocol`
|
|
40
|
-
|
|
41
|
-
`StorageFactory.connect()`의 `type` 파라미터 타입.
|
|
42
|
-
|
|
43
|
-
```typescript
|
|
44
|
-
type StorageProtocol = "ftp" | "ftps" | "sftp";
|
|
45
|
-
```
|
|
46
|
-
|
|
47
|
-
| Variant | Description |
|
|
48
|
-
|---------|-------------|
|
|
49
|
-
| `"ftp"` | 일반 FTP. `FtpStorageClient(false)` 생성 |
|
|
50
|
-
| `"ftps"` | TLS/SSL 암호화 FTP. `FtpStorageClient(true)` 생성 |
|
|
51
|
-
| `"sftp"` | SSH 기반 SFTP. `SftpStorageClient()` 생성 |
|
|
52
|
-
|
|
53
|
-
## Usage
|
|
54
|
-
|
|
55
|
-
```typescript
|
|
56
|
-
import { StorageFactory } from "@simplysm/storage";
|
|
57
|
-
|
|
58
|
-
// 파일 업로드
|
|
59
|
-
await StorageFactory.connect(
|
|
60
|
-
"sftp",
|
|
61
|
-
{ host: "sftp.example.com", user: "user", password: "pass" },
|
|
62
|
-
async (storage) => {
|
|
63
|
-
await storage.mkdir("/remote/dir");
|
|
64
|
-
await storage.put("/local/file.txt", "/remote/dir/file.txt");
|
|
65
|
-
},
|
|
66
|
-
);
|
|
67
|
-
|
|
68
|
-
// 파일 목록 조회 후 반환
|
|
69
|
-
const list = await StorageFactory.connect(
|
|
70
|
-
"ftp",
|
|
71
|
-
{ host: "ftp.example.com", port: 21, user: "user", password: "pass" },
|
|
72
|
-
(storage) => storage.list("/data"),
|
|
73
|
-
);
|
|
74
|
-
|
|
75
|
-
// 바이트 데이터로 업로드
|
|
76
|
-
const data = new Uint8Array([0x48, 0x65, 0x6c, 0x6c, 0x6f]);
|
|
77
|
-
await StorageFactory.connect(
|
|
78
|
-
"ftps",
|
|
79
|
-
{ host: "ftps.example.com", user: "user", password: "pass" },
|
|
80
|
-
(storage) => storage.put(data, "/remote/file.bin"),
|
|
81
|
-
);
|
|
82
|
-
```
|
package/docs/types/file-info.md
DELETED
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
# FileInfo
|
|
2
|
-
|
|
3
|
-
파일 또는 디렉토리 정보를 담는 인터페이스. [`StorageClient.list()`](./storage-client.md)의 반환 타입이다.
|
|
4
|
-
|
|
5
|
-
```typescript
|
|
6
|
-
interface FileInfo {
|
|
7
|
-
name: string;
|
|
8
|
-
isFile: boolean;
|
|
9
|
-
}
|
|
10
|
-
```
|
|
11
|
-
|
|
12
|
-
## Fields
|
|
13
|
-
|
|
14
|
-
| Field | Type | Description |
|
|
15
|
-
|-------|------|-------------|
|
|
16
|
-
| `name` | `string` | 파일 또는 디렉토리의 이름 (경로 아님, 이름만) |
|
|
17
|
-
| `isFile` | `boolean` | `true`이면 파일, `false`이면 디렉토리 |
|
|
18
|
-
|
|
19
|
-
## Usage
|
|
20
|
-
|
|
21
|
-
```typescript
|
|
22
|
-
import { StorageFactory } from "@simplysm/storage";
|
|
23
|
-
|
|
24
|
-
const items = await StorageFactory.connect(
|
|
25
|
-
"sftp",
|
|
26
|
-
{ host: "sftp.example.com", user: "user", password: "pass" },
|
|
27
|
-
async (storage) => storage.list("/remote/dir"),
|
|
28
|
-
);
|
|
29
|
-
|
|
30
|
-
const files = items.filter((item) => item.isFile);
|
|
31
|
-
const dirs = items.filter((item) => !item.isFile);
|
|
32
|
-
```
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
# StorageClient
|
|
2
|
-
|
|
3
|
-
스토리지 클라이언트 공통 인터페이스. [`FtpStorageClient`](../clients/ftp-storage-client.md)와 [`SftpStorageClient`](../clients/sftp-storage-client.md)가 구현한다.
|
|
4
|
-
|
|
5
|
-
직접 사용하기보다 [`StorageFactory.connect()`](../factory/storage-factory.md)를 통해 콜백 패턴으로 사용하는 것을 권장한다.
|
|
6
|
-
|
|
7
|
-
```typescript
|
|
8
|
-
interface StorageClient {
|
|
9
|
-
connect(config: StorageConnConfig): Promise<void>;
|
|
10
|
-
mkdir(dirPath: string): Promise<void>;
|
|
11
|
-
rename(fromPath: string, toPath: string): Promise<void>;
|
|
12
|
-
list(dirPath: string): Promise<FileInfo[]>;
|
|
13
|
-
readFile(filePath: string): Promise<Bytes>;
|
|
14
|
-
exists(filePath: string): Promise<boolean>;
|
|
15
|
-
put(localPathOrBuffer: string | Bytes, storageFilePath: string): Promise<void>;
|
|
16
|
-
uploadDir(fromPath: string, toPath: string): Promise<void>;
|
|
17
|
-
remove(filePath: string): Promise<void>;
|
|
18
|
-
close(): Promise<void>;
|
|
19
|
-
}
|
|
20
|
-
```
|
|
21
|
-
|
|
22
|
-
## Members
|
|
23
|
-
|
|
24
|
-
| Member | Kind | Type | Description |
|
|
25
|
-
|--------|------|------|-------------|
|
|
26
|
-
| `connect` | method | `(config: StorageConnConfig) => Promise<void>` | 스토리지 서버에 연결. 이미 연결된 상태에서 호출하면 `SdError` 발생 |
|
|
27
|
-
| `mkdir` | method | `(dirPath: string) => Promise<void>` | 디렉토리 생성. 부모 디렉토리가 없으면 함께 생성 |
|
|
28
|
-
| `rename` | method | `(fromPath: string, toPath: string) => Promise<void>` | 파일/디렉토리 이름 변경 또는 이동 |
|
|
29
|
-
| `list` | method | `(dirPath: string) => Promise<FileInfo[]>` | 디렉토리 내 파일/디렉토리 목록 조회 |
|
|
30
|
-
| `readFile` | method | `(filePath: string) => Promise<Bytes>` | 파일 내용을 `Bytes`(`Uint8Array`)로 읽기 |
|
|
31
|
-
| `exists` | method | `(filePath: string) => Promise<boolean>` | 파일/디렉토리 존재 여부 확인. 모든 예외는 `false` 반환 |
|
|
32
|
-
| `put` | method | `(localPathOrBuffer: string \| Bytes, storageFilePath: string) => Promise<void>` | 로컬 파일 경로 또는 바이트 데이터를 원격 경로에 업로드 |
|
|
33
|
-
| `uploadDir` | method | `(fromPath: string, toPath: string) => Promise<void>` | 로컬 디렉토리 전체를 원격 경로에 업로드 |
|
|
34
|
-
| `remove` | method | `(filePath: string) => Promise<void>` | 파일 삭제 |
|
|
35
|
-
| `close` | method | `() => Promise<void>` | 연결 종료. 이미 종료된 상태에서 호출해도 안전 |
|
|
36
|
-
|
|
37
|
-
## Usage
|
|
38
|
-
|
|
39
|
-
```typescript
|
|
40
|
-
import type { StorageClient } from "@simplysm/storage";
|
|
41
|
-
import { StorageFactory } from "@simplysm/storage";
|
|
42
|
-
|
|
43
|
-
// StorageClient 타입을 직접 사용하는 경우 (예: 함수 파라미터 타입)
|
|
44
|
-
async function doWork(storage: StorageClient): Promise<void> {
|
|
45
|
-
await storage.mkdir("/remote/dir");
|
|
46
|
-
await storage.put("/local/file.txt", "/remote/dir/file.txt");
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
await StorageFactory.connect("sftp", { host: "sftp.example.com", user: "user", password: "pass" }, doWork);
|
|
50
|
-
```
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
# StorageConnConfig
|
|
2
|
-
|
|
3
|
-
스토리지 서버 연결 설정 인터페이스.
|
|
4
|
-
|
|
5
|
-
```typescript
|
|
6
|
-
interface StorageConnConfig {
|
|
7
|
-
host: string;
|
|
8
|
-
port?: number;
|
|
9
|
-
user?: string;
|
|
10
|
-
password?: string;
|
|
11
|
-
}
|
|
12
|
-
```
|
|
13
|
-
|
|
14
|
-
## Fields
|
|
15
|
-
|
|
16
|
-
| Field | Type | Description |
|
|
17
|
-
|-------|------|-------------|
|
|
18
|
-
| `host` | `string` | 서버 호스트 주소 |
|
|
19
|
-
| `port` | `number \| undefined` | 포트 번호. 생략 시 프로토콜 기본값 사용 (FTP/FTPS: 21, SFTP: 22) |
|
|
20
|
-
| `user` | `string \| undefined` | 사용자 이름 |
|
|
21
|
-
| `password` | `string \| undefined` | 비밀번호. SFTP에서 생략하면 SSH agent + `~/.ssh/id_ed25519` 키 파일 인증을 순서대로 시도 |
|
|
22
|
-
|
|
23
|
-
## Usage
|
|
24
|
-
|
|
25
|
-
```typescript
|
|
26
|
-
import type { StorageConnConfig } from "@simplysm/storage";
|
|
27
|
-
|
|
28
|
-
const config: StorageConnConfig = {
|
|
29
|
-
host: "sftp.example.com",
|
|
30
|
-
port: 22,
|
|
31
|
-
user: "user",
|
|
32
|
-
password: "pass",
|
|
33
|
-
};
|
|
34
|
-
```
|