# @theswing/cdn

> The Swing 공용 CDN에 파일 업로드 하는 모듈

Latest version **1.0.9** (published 2026-06-12) · ISC license · 0 weekly downloads

## Install

```sh
npm install @theswing/cdn
pnpm add @theswing/cdn
yarn add @theswing/cdn
bun add @theswing/cdn
```

## Health

**Score 50/100 (C)** — status: active.

Positive: no vulnerabilities; recently updated.

Warnings: low downloads; no types; no esm support.

## Facts

| | |
|---|---|
| Version | 1.0.9 |
| Published | 2026-06-12 |
| First published | 2022-04-30 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 13.1 KB |
| Known vulnerabilities | 0 (+23 in 1 direct dependencies) |
| Install scripts | no |
| Author | msw |
| Maintainers | mswswing, jwswing |

## Links

- npm: https://www.npmjs.com/package/@theswing/cdn
- Repository: https://github.com/the-swing/openapi-bff-cdn-api
- Homepage: https://github.com/the-swing/openapi-bff-cdn-api/tree/module#readme
- Issues: https://github.com/the-swing/openapi-bff-cdn-api/issues
- npm.io page: https://npm.io/package/@theswing/cdn

## Dependencies (2)

- [axios](https://npm.io/package/axios.md) ^0.27.2
- [jwt-decode](https://npm.io/package/jwt-decode.md) ^3.1.2

## Recent versions

- 1.0.9 (latest) — 2026-06-12
- 1.0.8 — 2023-03-11
- 1.0.7 — 2022-11-17
- 1.0.6 — 2022-11-17
- 1.0.5 — 2022-07-25
- 1.0.4 — 2022-05-26
- 1.0.3 — 2022-05-26
- 1.0.2 — 2022-05-23
- 1.0.1 — 2022-05-23
- 1.0.0 — 2022-04-30

## README

# @theswing/cdn

The Swing 공용 CDN에 파일 업로드 하는 모듈

## Installing

Using npm:

```bash
$ npm install @theswing/cdn
```

## Example

```js
const { CDNUploader, FileTypes, Utils } = require("@theswing/cdn");
// or
import { CDNUploader, FileTypes, Utils } from "@theswing/cdn";


// ...

const cdnUploader = new CDNUploader("API_KEY");
console.log(cdnUploader.domain);
const r = await cdnUploader.performUploadUI(FileTypes.IMAGE);
console.log(r);
window.location.href = Utils.resizedHeight(r.url, 100);


```


## API
##### new CDNUploader(apiKey)
- 객체 생성자
- `apiKey`: (필수) CDN Domain API로 객체 생성

##### get domain: String
- 프로퍼티
- `apiKey` 토큰의 도메인을 출력

##### async function upload(data, config): UploadResult
- CDN에 파일 업로드 작업
- `data`: (필수) 업로드 할 파일, 데이터, BLOB, Buffer 등
- `config`: 설정
  - `filename`: (필수) 파일명
  - `mime`: (필수) 파일 종류
  - `metadata`: (선택) Object 별로로 저장할 데이터 JSON으로 저장됨
  - `secure`: (선택) Boolean 보안 영역 저장 여부 (선택시 url 반환 안함)
  - `onUploadProgress`: (선택) 업로드 진행률 콜백 함수 (UI 표시시 사용)

##### async function exists(fileKey): Boolean
- CDN에 올라간 파일인지 확인하는 함수
- `fileKey`: (필수) 파일 식별자
  
##### async performUploadUI(allowedFileTypes[, config]): UploadResult
- CDN에 파일 업로드 작업 (UI 지원)
- `allowedFileTypes`: 파일 선택 창에서 허용할 파일 종류 (`FileTypes` 참고)
- `config`: (선택) 설정
  - `secure`: (선택) Boolean 보안 영역 저장 여부 (선택시 url 반환 안함)
  - `onUploadProgress`: (선택) 업로드 진행률 콜백 함수 (UI 표시시 사용)
  - `metadata`: (선택) Object 별로로 저장할 데이터 JSON으로 저장됨

##### async getMetadata(fileKey) 
- CDN에 업로드된 메타데이터 다운로드
- `fileKey`: (필수) 파일키


##### async getFile(fileKey) 
- CDN에 업로드된 파일 직접 다운로드 후 Blob로 반환 (CDN 캐시 타지 않고 S3에서 직접)
- `fileKey`: (필수) 파일키

##### async getFileURL(fileKey) 
- CDN에 업로드된 파일 직접 다운로드한 Data URL을 반환 (CDN 캐시 타지 않고 S3에서 직접)
- `fileKey`: (필수) 파일키

> 일반적으로 공개 파일은 CDN URL로 대응하고 getFile API는 비공개 파일 가져올때 활용


## Definition
#### UploadResult
- `url`: CDN URL (secure == true인 경우 제외)
- `fileKey`: 파일 식별자

#### FileTypes
- MIME 스펙이면 직접 입력 가능
- https://developer.mozilla.org/ko/docs/Web/HTTP/Basics_of_HTTP/MIME_types


## Utils
##### isCDNURL(url): Boolean
- URL이 CDN URL인지 판정

##### resizedWidth(url, width): String
- CDN 이미지 URL을 넓이 기준으로 리사이즈된 URL을 반환 (비율 유지)

##### resizedHeight(url, height): String
- CDN 이미지 URL을 높이 기준으로 리사이즈된 URL을 반환 (비율 유지)

---
_Source: https://npm.io/package/@theswing/cdn · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
