@xccjh/resource-opt
TypeScript icon, indicating that this package has built-in type declarations

1.0.0 • Public • Published

前言

工具库,包含oss文件操作,本地文件操作

特性

  1. oss-upload oss上传资源
  2. oss-list oss获取资源列表
  3. oss-delete oss删除资源
  4. oss-download oss下载资源
  5. local-list 本地获取资源列表
  6. local-create 本地创建资源
  7. local-delete 本地删除资源

安装

$ yarn add @xccjh/resource-opt

配置oss & fs操作

const { ResourceOptManager } = require('@xccjh/resource-opt')

const options = {
  uploadDir: true,
  uploadFullPathFile: false,
  listType: 'all',
  region: '',
  endpoint: 'oss-cn-hongkong.aliyuncs.com',
  accessKeyId: 'LTAI5tGCjmVjvPDPooTKeU12',
  accessKeySecret: 'ddI0TfZUZel24E87YXKJVz91sn9ZFZ',
  localSourceFilter: (item) => {
    return item.path.indexOf('.js.map') !== -1
  }
}

new ResourceOptManager(options).init()

option汇总

  /**
  * 配置本地操作目标资源过滤器
  * @param item
  * @returns {boolean}
  */
  localSourceFilter = (item) => { return true }
  /**
  * 配置远程操作目标资源过滤器
  * @param item
  * @returns {boolean}
  */
  remoteSourceFilter = (item) => { return true }
  /**
   * 操作类型
   * @type {'oss-list' | 'oss-upload' | 'oss-delete' | 'oss-download' | 'local-list' | 'local-create' | 'local-delete''}
   */
  opterateType = 'oss-list'
  /**
   * 是否以全路径上传
   * @type {boolean}
   */
  uploadFullPathFile = false
  /**
   * 是否上传目录
   * @type {boolean}
   */
  uploadDir = false
  /**
   * 过滤类型
   * @type {'all' | 'file' | 'dir'}
   */
  listType = 'all'

/**
 * 本地操作地址
 * @type {string}
 */
  remoteResourcePath = ''
/**
 * 远程操作地址
 * @type {string}
 */
  localResourcePath = ''
  /**
   * 批量上传单批文件个数
   * @type {number}
   */
  batchNumber = 200
  ossBucket
  endpoint = ''
  region = 'oss-cn-shanghai'
  accessKeyId = 'LTAI5tCzqLRdAhWtvinM7HF8'
  accessKeySecret = 'Q5WJpvQtNE90O4IdgGcg0udysELuqB'

通用资源cli操作

// $ yarn add @xccjh/resource-opt -g
/**
* 通用资源操作
* @description
* resource-opt <operateType : oss-upload | oss-list | oss-delete | oss-download | local-list | local-create> [Bucket] [remotepath] [localpath] 
* @example ‘’‘md
* 用法示例(分批,深度递归,支持文件,文件夹,./,.等,没有的目录和文件自动处理):
* - 删除远程文件夹bb下所有: resource-opt oss-delete xccjhzjh bb 
* - 删除远程根目录所有下所有: resource-opt oss-delete xccjhzjh .
* - 删除远程根目录所有下所有: resource-opt oss-delete xccjhzjh ./
* - 删除远程根目录所有下所有: resource-opt oss-delete xccjhzjh /
* - 查看远程文件夹bb下所有: resource-opt oss-list xccjhzjh bb 
* - 查看远程文件夹bb下所有: resource-opt oss-list xccjhzjh ./bb 
* - 查看远程文件夹bb下所有: resource-opt oss-list xccjhzjh /bb 
* - 查看远程文件夹bb下所有: resource-opt oss-list xccjhzjh bb/ 
* - 查看远程文件夹bb下所有: resource-opt oss-list xccjhzjh ./bb/ 
* - 查看远程文件夹bb下所有: resource-opt oss-list xccjhzjh /bb/ 
* - 上传本地cc文件夹所有到远程文件夹bb: resource-opt oss-upload xccjhzjh bb cc 
* - 上传本地cc文件夹所有到远程文件夹bb: resource-opt oss-upload xccjhzjh bb ./cc
* - 上传本地bb文件夹所有到远程根目录: resource-opt oss-upload xccjhzjh . bb
* - 上传本地bb文件夹所有到远程根目录: resource-opt oss-upload xccjhzjh ./ bb
* - 下载远程bb文件夹所有到本地文件夹cc: resource-opt oss-download xccjhzjh bb cc 
* - 下载远程aa文件夹所有到本地文件夹根目录: resource-opt oss-download xccjhzjh aa ./
* - 下载远程aa文件夹所有到本地文件夹根目录: resource-opt oss-download xccjhzjh aa .
* - 创建本地aa/aa/bb/c: resource-opt local-create aa/aa/bb/c
* - 查看本地aa/aa/bb/c文件列表: resource-opt local-list aa/aa/bb/c
* - 删除本地aa/aa/bb/c: resource-opt local-delete aa/aa/bb/c
* ’‘’
*/

That's all

Readme

Keywords

Package Sidebar

Install

npm i @xccjh/resource-opt

Weekly Downloads

0

Version

1.0.0

License

ISC

Unpacked Size

230 kB

Total Files

18

Last publish

Collaborators

  • xccjh