@mw-components/ali-oss
v5.0.4
Published
阿里云 OSS 命令行工具 ossutil 封装 midway.js 组件,提供 TypeScript 类型定义
Downloads
114
Maintainers
Readme
@mw-components/ali-oss
Ali Oss ossutil client component for midway.js
Prepare
sudo wget https://gosspublic.alicdn.com/ossutil/1.7.11/ossutil64 -O /usr/bin/ossutil
sudo chmod a+x /usr/bin/ossutil
Installation
npm i @mw-components/ali-oss
Configuration
Enable Plugin
Edit ${app_root}/src/configuration.ts
:
import { join } from 'path'
import { ILifeCycle } from '@midwayjs/core'
import { Configuration } from '@midwayjs/decorator'
import * as aliOss from '@mw-components/ali-oss'
@Configuration({
imports: [
aliOss,
],
importConfigs: [join(__dirname, 'config')],
})
export class ContainerConfiguration implements ILifeCycle { }
Add Configurations
Update project src/config/config.prod.ts
import { Config } from '@mw-components/ali-oss'
export enum ClientKey {
ossmain = 'ossmain',
}
const clientConfig = {
accessKeyId: process.env.ALI_OSS_AID || '',
accessKeySecret: process.env.ALI_OSS_ASECRET || '',
endpoint: process.env.ALI_OSS_ENDPOINT || 'https://oss-cn-hangzhou.aliyuncs.com',
bucket: process.env.ALI_OSS_BUCKET || '',
cmd: 'ossutil',
debug: false,
}
export const aliOssConfig: Readonly<Config<ClientKey>> = {
ossmain: clientConfig,
}
Usage
Inject and mkdir()
import assert from 'node:assert/strict'
import { AliOssComponent } from '@mw-components/ali-oss'
import { App, Config, Inject } from '@midwayjs/decorator'
export class RootClass {
@Inject() readonly ossClient: AliOssComponent
async mkdir(path: string): Promise<void> {
const mkdirRet = await ossClient.mkdir('ossmain', path)
assert(! mkdirRet.exitCode, 'mkdir failed')
assert(mkdirRet.data, 'mkdir failed')
}
}
Methods
cp()
在远程拷贝createSymlink()
创建软连接mkdir()
创建目录mv()
在远程移动对象pathExists()
检测远程文件是否存在rm()
删除远程对象rmrf()
删除远程对象及其下级所有对象stat()
获取远程对象属性syncLocal()
(强制)同步远程对象到本地syncRemote()
(强制)同步本地目录到远程upload()
上传本地文件到远程