Giter Site home page Giter Site logo

nomi-oss-upload's Introduction

nomi-oss-upload

基于 ali-oss 上传的脚手架工具。

安装

npm i -g nomi-oss-upload

使用

# 上传
nomi-oss-upload [options]

# 帮助文档
nomi-oss-upload --help

options 参数说明

config

CLI 上传配置文件

默认值:nomi.upload.config.js

使用方式:-c, --config

nomi-oss-upload -c upload.config.js

配置文件参数:

参数 描述 类型 默认值
ossApiConfig 通过接口动态获取配置 参考下面的 ossApiConfig 配置 -
ossConfig 固定配置 需要符合ali-oss 配置 -
saveDir 上传文件时保存的oss目录 string -
random 是否生成随机文件名称 boolean -
debug 是否开启调试模式 boolean -

ossApiConfig 配置:

参数 描述 类型 默认值
url 通过接口动态获取配置 单元格 -
transferResponse 固定配置 单元格 -

配置文件示例:

module.exports = {
    // 从接口动态获取配置
    ossApiConfig: {
      // 动态获取oss配置的接口地址
      url: "https://xxx.xx.xxx",
      // 转化接口响应数据,需要符合 ali-oss 初始化实例的参数字段 https://www.npmjs.com/package/ali-oss#ossoptions
      transferResponse: (data) => {
        const { securityToken: stsToken, accessKeyId, accessKeySecret, region, bucketName: bucket, endpoint, expiration } = data.data
        const res = {
          accessKeyId,
          region,
          bucket,
          accessKeySecret,
          endpoint,
          stsToken,
        }
        if (expiration && typeof expiration === 'string') {
          res.expiration = new Date(expiration).getTime()
        }
        return res
      }
    },
    // 本地固定配置
    ossConfig: {
      region: "",
      bucket: "",
      endpoint: "",
      accessKeyId: "",
      accessKeySecret: "",
      stsToken: ""
    },
    // 上传文件时保存的oss目录
    saveDir: 'nomi',
    // 随机生成文件名称
    random: true,
    // 开启调试模式
    debug: false,
}

⚠️注意:

  • CLI会优先取配置文件定义的字段,如果配置文件没有的情况下,才会取命令行参数字段
  • 优先取 ossApiConfig 配置, 如果没有配置才会取 ossConfig 配置
  • 无论是动态获取的配置还是固定的配置都需要符合 ali-oss 初始化参数

api

用于获取oss上传文件配置接口url,例如:https://example.com/api/oss/aliyun/get-oss-config

使用方式:-a, --api

nomi-oss-upload --api https://example.com/api/oss/aliyun/get-oss-config

url响应结构:

interface Res {
    accessKeyId: string
    bucket: string
    accessKeySecret: string
    endpoint: string
    stsToken: string
    region?: string
    expiration?: number
}

file

待上传本地文件路径或目录路径(相对路径)

使用方式:-f, --file

nomi-oss-upload --file path/to/example.json

saveDir

上传文件时保存的oss目录

使用方式:-s, --saveDir

nomi-oss-upload --saveDir testDir

⚠️注意:目录后不需要/,如果是多层级目录可以写成parent/child格式。

urlFile

本地配置文件路径(相对路径),文件中包含要上传的远端url列表,文件格式为 json

json文件内容格式如下:

[
    "https://example.com/test.png",
    "https://example.com/test.jpg",
    "https://example.com/test.docx",
    "https://example.com/test.ppt",
    "https://example.com/test.json"
    // ...
]

使用方式:-uf, --urlFile

nomi-oss-upload --urlFile path/to/example.config.json

url

待上传的远端url(完整的有效路径)

使用方式:-u, --url

nomi-oss-upload --url https://example.com/example.jpg

random

是否随机生成文件名称

使用方式:-r, --random

nomi-oss-upload --random

debug

是否开启调试模式

使用方式:-d, --debug

nomi-oss-upload --debug

nomi-oss-upload's People

Contributors

zhicaizhu123 avatar

Stargazers

 avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.