npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@theswing/cdn

v1.0.8

Published

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

Downloads

452

Readme

@theswing/cdn

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

Installing

Using npm:

$ npm install @theswing/cdn

Example

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을 반환 (비율 유지)