diff --git a/.github/workflows/nodejs.yml b/.github/workflows/nodejs.yml deleted file mode 100644 index 6dffc1d..0000000 --- a/.github/workflows/nodejs.yml +++ /dev/null @@ -1,46 +0,0 @@ -# This workflow will do a clean install of node dependencies, build the source code and run tests across different versions of node -# For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions - -name: Node.js CI - -on: - push: - branches: - - main - - master - pull_request: - branches: - - main - - master - schedule: - - cron: '0 2 * * *' - -jobs: - build: - runs-on: ${{ matrix.os }} - - strategy: - fail-fast: false - matrix: - node-version: [8, 9] - os: [ubuntu-latest, windows-latest, macos-latest] - - steps: - - name: Checkout Git Source - uses: actions/checkout@v2 - - - name: Use Node.js ${{ matrix.node-version }} - uses: actions/setup-node@v1 - with: - node-version: ${{ matrix.node-version }} - - - name: Install Dependencies - run: npm i -g npminstall@5 && npminstall - - - name: Continuous Integration - run: npm run ci - - - name: Code Coverage - uses: codecov/codecov-action@v1 - with: - token: ${{ secrets.CODECOV_TOKEN }} diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..bb3b395 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,32 @@ +name: Publish Package + +on: + push: + branches: [ cur-publish] + +jobs: + publish: + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Set up Node.js + uses: actions/setup-node@v4 + with: + node-version: '20' + + - name: Publish to npmjs + run: npm publish --//registry.npmjs.org/:_authToken=${{ secrets.NPM_TOKEN }} + + - name: Set up Node.js + uses: actions/setup-node@v4 + with: + node-version: '20' + registry-url: https://npm.pkg.github.com + + - name: Publish to GitHub Packages + run: npm publish + env: + NODE_AUTH_TOKEN: ${{secrets.GIT_TOKEN}} \ No newline at end of file diff --git a/README.md b/README.md index 73ade39..64330be 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,7 @@ [![npm download][download-image]][download-url] [npm-image]: https://img.shields.io/npm/v/@onewalker/egg-cos.svg?style=flat-square -[npm-url]: https://npmjs.org/package/@onewalker/egg-cos +[npm-url]: https://www.npmjs.com/package/@onewalker/egg-cos [codecov-image]: https://img.shields.io/codecov/c/github/onewalker/egg-cos.svg?style=flat-square [codecov-url]: https://codecov.io/github/onewalker/egg-cos?branch=master [david-image]: https://img.shields.io/david/onewalker/egg-cos.svg?style=flat-square @@ -15,7 +15,7 @@ [snyk-image]: https://snyk.io/test/npm/@onewalker/egg-cos/badge.svg?style=flat-square [snyk-url]: https://snyk.io/test/npm/@onewalker/egg-cos [download-image]: https://img.shields.io/npm/dm/@onewalker/egg-cos.svg?style=flat-square -[download-url]: https://npmjs.org/package/@onewalker/egg-cos +[download-url]: https://www.npmjs.com/package/@onewalker/egg-cos 腾讯云存储在eggjs框架中的使用。 @@ -26,7 +26,7 @@ Primarily, I tired to merge my addtion of stream ways to the other project, whil ```bash - npm install @onwalker/egg-cos + npm install @onewalker/egg-cos ``` @@ -44,10 +44,10 @@ exports.cos = { // {app_root}/config/config.default.js exports.cos = { client: { - SecretId: '', - SecretKey: '', - Bucket: '', - Region: '' + SecretId: '', + SecretKey: '', + Bucket: '', + Region: '' } }; ``` @@ -73,26 +73,26 @@ const Controller = require('egg').Controller; module.exports = class extends Controller { async upload() { - const ctx = this.ctx; - // please enable `file` mode of `egg-multipart`. - const file = ctx.request.files[0]; - const name = 'egg-cos/' + path.basename(file.filename); - let result; - try { - result = await ctx.cos.put(name, file.filepath); - } finally { - // need to remove the tmp files - await ctx.cleanupRequestFiles(); - } - - if (result) { - ctx.logger.info('cos response:\n', result); - ctx.body = { - url: `https://${result.Location}` - }; - } else { - ctx.body = 'please select a file to upload!'; - } + const ctx = this.ctx; + // please enable `file` mode of `egg-multipart`. + const file = ctx.request.files[0]; + const name = 'egg-cos/' + path.basename(file.filename); + let result; + try { + result = await ctx.cos.put(name, file.filepath); + } finally { + // need to remove the tmp files + await ctx.cleanupRequestFiles(); + } + + if (result) { + ctx.logger.info('cos response:\n', result); + ctx.body = { + url: `https://${result.Location}` + }; + } else { + ctx.body = 'please select a file to upload!'; + } } }; ``` @@ -106,36 +106,36 @@ async upload() { const parts = ctx.multipart(); let part,results=[]; while ((part = await parts()) != null) { - if (part.length) { - // This is content of part stream - console.log('field: ' + part[0]); - console.log('value: ' + part[1]); - console.log('valueTruncated: ' + part[2]); - console.log('fieldnameTruncated: ' + part[3]); - } else { - if (!part.filename) { - return; - } - console.log('field: ' + part.fieldname); - console.log('filename: ' + part.filename); - console.log('encoding: ' + part.encoding); - console.log('mime: ' + part.mime); - console.log("part",part.stream,typeof part); - // file processing, uploading the file to Tencent Cloud Server - let result; - let path=await ctx.helper.MD5encode(String(Date.now())); - let typeArray=part.mime.split('/'); - let type=typeArray[typeArray.length-1]; - let name='ysxbdms/projects/'+path+`.${type}`;//the upload links - try { - result = await ctx.cos.putStream(name,part); - } catch (err) { - await sendToWormhole(part); - throw err; - } - console.log(result); - results.push(result); - } + if (part.length) { + // This is content of part stream + console.log('field: ' + part[0]); + console.log('value: ' + part[1]); + console.log('valueTruncated: ' + part[2]); + console.log('fieldnameTruncated: ' + part[3]); + } else { + if (!part.filename) { + return; + } + console.log('field: ' + part.fieldname); + console.log('filename: ' + part.filename); + console.log('encoding: ' + part.encoding); + console.log('mime: ' + part.mime); + console.log("part",part.stream,typeof part); + // file processing, uploading the file to Tencent Cloud Server + let result; + let path=await ctx.helper.MD5encode(String(Date.now())); + let typeArray=part.mime.split('/'); + let type=typeArray[typeArray.length-1]; + let name='ysxbdms/projects/'+path+`.${type}`;//the upload links + try { + result = await ctx.cos.putStream(name,part); + } catch (err) { + await sendToWormhole(part); + throw err; + } + console.log(result); + results.push(result); + } } console.log('and we are done parsing the form!'); ctx.body=results; @@ -151,3 +151,4 @@ Please open an issue [here](https://github.com/onewalker/egg-cos/issues). ## License [MIT](LICENSE) + diff --git a/package.json b/package.json index fa7c32a..1e055cb 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@onewalker/egg-cos", - "version": "0.1.2", + "version": "1.0.0", "description": "tencent cloud cos plugin for egg", "eggPlugin": { "name": "cos"