Skip to content

Commit

Permalink
docs: add publish info
Browse files Browse the repository at this point in the history
  • Loading branch information
oneWalker committed Nov 7, 2024
1 parent 4a3427a commit 725d7cc
Show file tree
Hide file tree
Showing 4 changed files with 91 additions and 104 deletions.
46 changes: 0 additions & 46 deletions .github/workflows/nodejs.yml

This file was deleted.

32 changes: 32 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -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}}
115 changes: 58 additions & 57 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@
[![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
[david-url]: https://david-dm.org/onewalker/egg-cos
[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框架中的使用。

Expand All @@ -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

```

Expand All @@ -44,10 +44,10 @@ exports.cos = {
// {app_root}/config/config.default.js
exports.cos = {
client: {
SecretId: '',
SecretKey: '',
Bucket: '',
Region: ''
SecretId: '',
SecretKey: '',
Bucket: '',
Region: ''
}
};
```
Expand All @@ -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!';
}
}
};
```
Expand All @@ -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;
Expand All @@ -151,3 +151,4 @@ Please open an issue [here](https://github.com/onewalker/egg-cos/issues).
## License

[MIT](LICENSE)

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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"
Expand Down

0 comments on commit 725d7cc

Please sign in to comment.