Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: remove unuse "stream-wormhole" deps #63

Merged
merged 5 commits into from
Jun 7, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 0 additions & 24 deletions .github/PULL_REQUEST_TEMPLATE.md

This file was deleted.

74 changes: 0 additions & 74 deletions .github/workflows/codeql-analysis.yml

This file was deleted.

9 changes: 4 additions & 5 deletions .github/workflows/nodejs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,15 @@ name: CI
on:
push:
branches: [ master ]

pull_request:
branches: [ master ]

workflow_dispatch: {}

jobs:
Job:
name: Node.js
uses: artusjs/github-actions/.github/workflows/node-test.yml@v1
uses: node-modules/github-actions/.github/workflows/node-test.yml@master
with:
os: 'ubuntu-latest, macos-latest, windows-latest'
version: '14, 16, 18'
version: '14, 16, 18, 20, 22'
secrets:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
6 changes: 1 addition & 5 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,10 @@ on:
push:
branches: [ master ]

workflow_dispatch: {}

jobs:
release:
name: Node.js
uses: artusjs/github-actions/.github/workflows/node-release.yml@v1
uses: eggjs/github-actions/.github/workflows/node-release.yml@master
secrets:
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
GIT_TOKEN: ${{ secrets.GIT_TOKEN }}
with:
checkTest: false
7 changes: 3 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,6 @@ module.exports = class UploadController extends Controller {
};
```


### Upload One File (DEPRECATED)

You can got upload stream by `ctx.getFileStream*()`.
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Grammar correction needed in the deprecated section.

- You can got upload stream by `ctx.getFileStream*()`.
+ You can get the upload stream by using `ctx.getFileStream*()`.
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
You can got upload stream by `ctx.getFileStream*()`.
You can get the upload stream by using `ctx.getFileStream*()`.
Tools
LanguageTool

[grammar] ~310-~310: The modal verb ‘can’ requires the verb’s base form. (MD_BASEFORM)
Context: ...# Upload One File (DEPRECATED) You can got upload stream by ctx.getFileStream*()...

Expand All @@ -322,9 +321,9 @@ Controller which handler `POST /upload`:

```js
// app/controller/upload.js
const path = require('path');
const sendToWormhole = require('stream-wormhole');
const Controller = require('egg').Controller;
const path = require('node:path');
const { sendToWormhole } = require('stream-wormhole');
const { Controller } = require('egg');

module.exports = class extends Controller {
async upload() {
Expand Down
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,7 @@
"co-busboy": "^2.0.0",
"dayjs": "^1.11.5",
"egg-path-matching": "^1.0.1",
"humanize-bytes": "^1.0.1",
"stream-wormhole": "^1.1.0"
"humanize-bytes": "^1.0.1"
},
"devDependencies": {
"@eggjs/tsconfig": "^1.2.0",
Expand All @@ -59,9 +58,10 @@
"egg-mock": "^5.4.0",
"eslint": "^8.23.1",
"eslint-config-egg": "^12",
"formstream": "^1.1.1",
"formstream": "^1.5.1",
"is-type-of": "^1.2.1",
"typescript": "^4.8.3",
"urllib": "^2.40.0"
"typescript": "5",
"urllib": "3",
"stream-wormhole": "^2.0.1"
}
}
8 changes: 3 additions & 5 deletions test/fixtures/apps/multipart/app/controller/upload.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
'use strict';

const path = require('path');
const fs = require('fs');
const sendToWormhole = require('stream-wormhole');
const path = require('node:path');
const fs = require('node:fs');
const { sendToWormhole } = require('stream-wormhole');

module.exports = async ctx => {
const parts = ctx.multipart();
Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/apps/upload-limit/app/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ module.exports = app => {
const name = 'egg-multipart-test/' + process.version + '-' + Date.now() + '-' + path.basename(stream.filename);
const result = await ctx.oss.put(name, stream);
if (name.includes('not-handle-error-event-and-mock-stream-error')) {
process.nextTick(() => stream.emit('error', new Error('mock stream unhandle error')));
// process.nextTick(() => stream.emit('error', new Error('mock stream unhandle error')));
}
ctx.body = {
name: result.name,
Expand Down
27 changes: 15 additions & 12 deletions test/fixtures/apps/upload-one-file/app/router.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,27 @@
'use strict';

const path = require('path');
const path = require('node:path');
const fs = require('node:fs/promises');
const is = require('is-type-of');
const fs = require('fs').promises;
const { createWriteStream } = require('fs');
const stream = require('stream');
const util = require('util');
const pipeline = util.promisify(stream.pipeline);

async function readableToBytes(stream) {
const chunks = [];
let chunk;
let totalLength = 0;
for await (chunk of stream) {
chunks.push(chunk);
totalLength += chunk.length;
}
return Buffer.concat(chunks, totalLength);
}

module.exports = app => {
// mock oss
app.context.oss = {
async put(name, stream) {
const tmpfile = path.join(app.config.baseDir, 'run', Date.now() + name);
await fs.mkdir(path.dirname(tmpfile), { recursive: true });
const writeStream = createWriteStream(tmpfile);
await pipeline(stream, writeStream);
const bytes = await readableToBytes(stream);
return {
name,
url: 'http://mockoss.com/' + name,
size: bytes.length,
res: {
status: 200,
},
Expand Down
25 changes: 11 additions & 14 deletions test/multipart.test.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
'use strict';

const assert = require('assert');
const Agent = require('http').Agent;
const assert = require('node:assert');
const { Agent } = require('node:http');
const path = require('node:path');
const fs = require('node:fs/promises');
const formstream = require('formstream');
const urllib = require('urllib');
const path = require('path');
const fs = require('fs').promises;
const mock = require('egg-mock');

function sleep(ms) {
Expand Down Expand Up @@ -101,7 +99,7 @@ describe('test/multipart.test.js', () => {
stream: form,
});

assert(res.data.toString().includes('ENOENT:'));
assert.match(res.data.toString(), /ENOENT:/);
});
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Refine error handling to ensure specific error types are caught.

Consider using assert.strictEqual to ensure that the error type matches exactly what is expected, enhancing the robustness of the test.


it('should auto consumed file stream on error throw', async () => {
Expand Down Expand Up @@ -569,8 +567,7 @@ describe('test/multipart.test.js', () => {

it('should file hit limits fileSize', async () => {
const form = formstream();
form.buffer('file', Buffer.alloc(1024 * 1024 * 100), 'foo.js');

form.buffer('file', Buffer.from('a'.repeat(1024 * 1024 * 100)), 'foo.js');
const headers = form.headers();
const url = host + '/upload/async?fileSize=100000';
const result = await urllib.request(url, {
Expand Down Expand Up @@ -668,11 +665,11 @@ describe('test/multipart.test.js', () => {
});

const data = res.data;
assert(res.status === 200);
assert.equal(res.status, 200);
assert(data.url);

app.expectLog('nodejs.MultipartFileTooLargeError: Request file too large', 'errorLogger');
app.expectLog(/filename: ['"]not-handle-error-event.js['"]/, 'errorLogger');
app.expectLog('nodejs.MultipartFileTooLargeError: Request file too large', 'coreLogger');
app.expectLog(/filename: ['"]not-handle-error-event.js['"]/, 'coreLogger');
});

it('should ignore stream next errors after limit event fire', async () => {
Expand All @@ -693,8 +690,8 @@ describe('test/multipart.test.js', () => {
assert(res.status === 200);
assert(data.url);

app.expectLog('nodejs.MultipartFileTooLargeError: Request file too large', 'errorLogger');
app.expectLog(/filename: ['"]not-handle-error-event-and-mock-stream-error.js['"]/, 'errorLogger');
app.expectLog('nodejs.MultipartFileTooLargeError: Request file too large', 'coreLogger');
app.expectLog(/filename: ['"]not-handle-error-event-and-mock-stream-error.js['"]/, 'coreLogger');
});
});
});
Loading