Skip to content

Commit

Permalink
Merge branch 'release/0.15.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
nwtgck committed Nov 6, 2019
2 parents 8dd753e + a6d1da6 commit ce1eb56
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 41 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
- name: Use Node.js 10.x
uses: actions/setup-node@v1
with:
version: 10.x
node-version: 10.x
- name: npm ci, build, and test
run: |
npm ci
Expand Down
7 changes: 6 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)

## [Unreleased]

## [0.15.1] - 2019-11-06
### Changed
* Update dependencies

## [0.15.0] - 2019-10-22
### Changed
* Update dependencies
Expand Down Expand Up @@ -235,7 +239,8 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
* Docker automated build on Docker Hub
* Support HTTPS

[Unreleased]: https://github.com/nwtgck/piping-server/compare/v0.15.0...HEAD
[Unreleased]: https://github.com/nwtgck/piping-server/compare/v0.15.1...HEAD
[0.15.1]: https://github.com/nwtgck/piping-server/compare/v0.15.0...v0.15.1
[0.15.0]: https://github.com/nwtgck/piping-server/compare/v0.14.0...v0.15.0
[0.14.0]: https://github.com/nwtgck/piping-server/compare/v0.13.2...v0.14.0
[0.13.2]: https://github.com/nwtgck/piping-server/compare/v0.13.1...v0.13.2
Expand Down
46 changes: 27 additions & 19 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "piping-server",
"version": "0.15.0",
"version": "0.15.1",
"description": "Streaming Data Transfer Server over HTTP/HTTPS",
"bin": {
"piping-server": "dist/src/index.js"
Expand Down Expand Up @@ -30,7 +30,7 @@
"license": "MIT",
"devDependencies": {
"@types/mocha": "^5.0.0",
"@types/node": "^10.12.21",
"@types/node": "^12.11.7",
"@types/power-assert": "^1.5.0",
"@types/request": "^2.48.1",
"@types/yargs": "^13.0.0",
Expand Down
24 changes: 15 additions & 9 deletions src/piping.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {ParsedUrlQuery} from "querystring";
import * as stream from "stream";
import * as url from "url";

import {opt, optMap} from "./utils";
import {OptionalProperty, optMap} from "./utils";
import {VERSION} from "./version";

type HttpReq = http.IncomingMessage | http2.Http2ServerRequest;
Expand Down Expand Up @@ -78,7 +78,8 @@ const NAME_TO_RESERVED_PATH = {
};

const indexPage: string =
`<html>
`<!DOCTYPE html>
<html lang="en">
<head>
<title>Piping</title>
<meta name="viewport" content="width=device-width,initial-scale=1">
Expand All @@ -97,7 +98,7 @@ Streaming Data Transfer Server over HTTP/HTTPS
<input type="checkbox" id="text_mode" onchange="toggleInputMode()">: <b>Text mode</b><br><br>
<input type="file" id="file_input">
<textarea type="text" id="text_input" placeholder="Input text" cols="30" rows="10"></textarea>
<textarea id="text_input" placeholder="Input text" cols="30" rows="10"></textarea>
<br>
<h3>Step 2: Write your secret path</h3>
Expand Down Expand Up @@ -234,9 +235,14 @@ export class Server {
*/
private static getNReceivers(reqUrl: string | undefined): number {
// Get query parameter
const query = opt(optMap(url.parse, reqUrl, true).query);
const query: ParsedUrlQuery | undefined =
// tslint:disable-next-line:max-line-length
// NOTE: Return type casting is safe because function parse(urlStr: string, parseQueryString: true, slashesDenoteHost?: boolean): UrlWithParsedQuery;
(optMap(url.parse, reqUrl, true) as OptionalProperty<url.UrlWithParsedQuery>)
.query;
// The number receivers
const nReceivers: number = nanOrElse(parseInt((query as ParsedUrlQuery).n as string, 10), 1);
// NOTE: parseInt(undefined, 10) is NaN
const nReceivers: number = nanOrElse(parseInt((query?.n as string || "1"), 10), 1);
return nReceivers;
}
private readonly pathToEstablished: {[path: string]: boolean} = {};
Expand All @@ -254,10 +260,10 @@ export class Server {
// Get path name
const reqPath: string =
url.resolve(
"/",
opt(optMap(url.parse, opt(req.url)).pathname)
"/",
optMap(url.parse, req.url).pathname?.
// Remove last "/"
.replace(/\/$/, "")
replace(/\/$/, "") || ""
);
this.logger.info(`${req.method} ${req.url}`);

Expand Down Expand Up @@ -380,7 +386,7 @@ export class Server {
}) :
undefined;

const senderData: NodeJS.ReadableStream =
const senderData: stream.Readable =
part === undefined ? sender.req : part;

let closeCount: number = 0;
Expand Down
11 changes: 2 additions & 9 deletions src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,10 @@
/**
* Type which has optional property
*/
type OptionalProperty<T> = {
export type OptionalProperty<T> = {
[K in keyof T]: T[K] | undefined;
};

/**
* Optional property
* @param obj
*/
export function opt<T>(obj: T | null | undefined): OptionalProperty<T> {
return obj || ({} as OptionalProperty<T>);
}

/**
* Mapping for optional
* @param f
Expand All @@ -23,6 +15,7 @@ export function optMap<T, S>(
f: (p: T, ...args: any[]) => S, obj: T | null | undefined, ...args: any[]
): OptionalProperty<S> {
if (obj === null || obj === undefined) {
// FIXME: This is not safe when S is not an object.
return {} as OptionalProperty<S>;
} else {
return f(obj, ...args);
Expand Down

0 comments on commit ce1eb56

Please sign in to comment.