Skip to content
This repository has been archived by the owner on Aug 31, 2021. It is now read-only.

Commit

Permalink
APIs and popups
Browse files Browse the repository at this point in the history
  • Loading branch information
mkloubert committed Mar 18, 2018
1 parent 0b70157 commit b50d67f
Show file tree
Hide file tree
Showing 12 changed files with 209 additions and 226 deletions.
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,18 @@

[![Share via Facebook](https://raw.githubusercontent.com/mkloubert/vscode-deploy-reloaded/master/img/share/Facebook.png)](https://www.facebook.com/sharer/sharer.php?u=https%3A%2F%2Fmarketplace.visualstudio.com%2Fitems%3FitemName%3Dmkloubert.vscode-deploy-reloaded&quote=vscode-deploy-reloaded) [![Share via Twitter](https://raw.githubusercontent.com/mkloubert/vscode-deploy-reloaded/master/img/share/Twitter.png)](https://twitter.com/intent/tweet?source=https%3A%2F%2Fmarketplace.visualstudio.com%2Fitems%3FitemName%3Dmkloubert.vscode-deploy-reloaded&text=vscode-deploy-reloaded:%20https%3A%2F%2Fmarketplace.visualstudio.com%2Fitems%3FitemName%3Dmkloubert.vscode-deploy-reloaded&via=mjkloubert) [![Share via Google+](https://raw.githubusercontent.com/mkloubert/vscode-deploy-reloaded/master/img/share/Google+.png)](https://plus.google.com/share?url=https%3A%2F%2Fmarketplace.visualstudio.com%2Fitems%3FitemName%3Dmkloubert.vscode-deploy-reloaded) [![Share via Pinterest](https://raw.githubusercontent.com/mkloubert/vscode-deploy-reloaded/master/img/share/Pinterest.png)](https://pinterest.com/pin/create/button/?url=https%3A%2F%2Fmarketplace.visualstudio.com%2Fitems%3FitemName%3Dmkloubert.vscode-deploy-reloaded&media=https://raw.githubusercontent.com/mkloubert/vscode-deploy-reloaded/master/img/demo1.gif&description=Recoded%20version%20of%20Visual%20Studio%20Code%20extension%20%27vs-deploy%27%2C%20which%20provides%20commands%20to%20deploy%20files%20to%20one%20or%20more%20destinations.) [![Share via Reddit](https://raw.githubusercontent.com/mkloubert/vscode-deploy-reloaded/master/img/share/Reddit.png)](https://www.reddit.com/submit?url=https%3A%2F%2Fmarketplace.visualstudio.com%2Fitems%3FitemName%3Dmkloubert.vscode-deploy-reloaded&title=vscode-deploy-reloaded) [![Share via LinkedIn](https://raw.githubusercontent.com/mkloubert/vscode-deploy-reloaded/master/img/share/LinkedIn.png)](https://www.linkedin.com/shareArticle?mini=true&url=https%3A%2F%2Fmarketplace.visualstudio.com%2Fitems%3FitemName%3Dmkloubert.vscode-deploy-reloaded&title=vscode-deploy-reloaded&summary=Recoded%20version%20of%20Visual%20Studio%20Code%20extension%20%27vs-deploy%27%2C%20which%20provides%20commands%20to%20deploy%20files%20to%20one%20or%20more%20destinations.&source=https%3A%2F%2Fmarketplace.visualstudio.com%2Fitems%3FitemName%3Dmkloubert.vscode-deploy-reloaded) [![Share via Wordpress](https://raw.githubusercontent.com/mkloubert/vscode-deploy-reloaded/master/img/share/Wordpress.png)](https://wordpress.com/press-this.php?u=https%3A%2F%2Fmarketplace.visualstudio.com%2Fitems%3FitemName%3Dmkloubert.vscode-deploy-reloaded&quote=vscode-deploy-reloaded&s=Recoded%20version%20of%20Visual%20Studio%20Code%20extension%20%27vs-deploy%27%2C%20which%20provides%20commands%20to%20deploy%20files%20to%20one%20or%20more%20destinations.&i=https://raw.githubusercontent.com/mkloubert/vscode-deploy-reloaded/master/img/demo1.gif) [![Share via Email](https://raw.githubusercontent.com/mkloubert/vscode-deploy-reloaded/master/img/share/Email.png)](mailto:?subject=vscode-deploy-reloaded&body=Recoded%20version%20of%20Visual%20Studio%20Code%20extension%20'vs-deploy'%2C%20which%20provides%20commands%20to%20deploy%20files%20to%20one%20or%20more%20destinations.:%20https%3A%2F%2Fmarketplace.visualstudio.com%2Fitems%3FitemName%3Dmkloubert.vscode-deploy-reloaded)

## 0.63.0 (March 18th, 2018; APIs and popups)

* added [api endpoints](https://github.com/mkloubert/vscode-deploy-reloaded/wiki/apis)
* [POST /markdown](https://github.com/mkloubert/vscode-deploy-reloaded/wiki/apis#post-apimarkdown)
* added `alwaysShowWorkspaceNameInPopups` and `showWorkspaceNameInPopups` [settings](https://github.com/mkloubert/vscode-deploy-reloaded/wiki#settings--) ... s. [issue #47](https://github.com/mkloubert/vscode-deploy-reloaded/issues/47#issuecomment-373940021)
* passwords in input boxes of [SFTP](https://github.com/mkloubert/vscode-deploy-reloaded/wiki/target_sftp) and [FTP](https://github.com/mkloubert/vscode-deploy-reloaded/wiki/target_ftp) targets are masked now ... s. [issue #48](https://github.com/mkloubert/vscode-deploy-reloaded/issues/48#issuecomment-374041368)
* "outsourced" `asBuffer()`, `doesMatch()`, `makeNonDisposable()`, `readAll()` functions to [vscode-helpers](https://www.npmjs.com/package/vscode-helpers) npm module
* removed obsolete [npm packages](https://www.npmjs.com/):
* [isbinaryfile](https://www.npmjs.com/package/isbinaryfile)
* bugfixes
* code cleanups and improvements

## 0.62.3 (March 17th, 2018; password prompts and bugfixes)

* fixed bugs in [SFTP](https://github.com/mkloubert/vscode-deploy-reloaded/wiki/target_sftp) and [FTP](https://github.com/mkloubert/vscode-deploy-reloaded/wiki/target_ftp) target, when deploying to root directory ... s. [issue #45](https://github.com/mkloubert/vscode-deploy-reloaded/issues/45) and [issue #46](https://github.com/mkloubert/vscode-deploy-reloaded/issues/46)
Expand Down
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ The extension supports the following destinations:
5. [Support and contribute](#support-and-contribute-)
* [Contributors](#contributors-)
6. [Related projects](#related-projects-)
* [node-enumerable](#node-enumerable-)
* [node-simple-socket](#node-simple-socket-)
* [vscode-helpers](#vscode-helpers-)

## Demos [[↑](#table-of-contents)]
Expand Down Expand Up @@ -360,6 +362,14 @@ The API documentation can be found [here](https://mkloubert.github.io/vscode-dep

## Related projects [[↑](#table-of-contents)]

### node-enumerable [[↑](#related-projects-)]

[node-enumerable](https://github.com/mkloubert/node-enumerable) is a [LINQ](https://en.wikipedia.org/wiki/Language_Integrated_Query) implementation for JavaScript, which runs in [Node.js](https://nodejs.org/) and browsers.

### node-simple-socket [[↑](#related-projects-)]

[node-simple-socket](https://github.com/mkloubert/node-simple-socket) is a simple socket class, which supports automatic [RSA](https://en.wikipedia.org/wiki/RSA_(cryptosystem)) encryption and compression for two connected endpoints and runs in [Node.js](https://nodejs.org/).

### vscode-helpers [[↑](#related-projects-)]

[vscode-helpers](https://github.com/mkloubert/vscode-helpers) is a NPM module, which you can use in your own [VSCode extension](https://code.visualstudio.com/docs/extensions/overview) and contains a lot of helpful classes and functions.
9 changes: 9 additions & 0 deletions _res/rest/post.api.markdown.http
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
POST http://localhost/api/markdown HTTP/1.1

{
"title": "A title",
"content": "# Header 1\n\n## Header 2\n\n```javascript\nvar s = 'JavaScript syntax highlighting';\nalert(s);\n```",
"options": {
"css": "body { background-color: white; color: black; }"
}
}
10 changes: 6 additions & 4 deletions package-lock.json

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

15 changes: 12 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "vscode-deploy-reloaded",
"displayName": "Deploy (Reloaded)",
"description": "Deploys files of a workspace to a destination.",
"version": "0.62.3",
"version": "0.63.0",
"publisher": "mkloubert",
"engines": {
"vscode": "^1.21.0"
Expand Down Expand Up @@ -164,6 +164,11 @@
"type": "object",
"scope": "resource",
"properties": {
"alwaysShowWorkspaceNameInPopups": {
"description": "Show workspace name in popups, even if there is only one workspace open.",
"type": "boolean",
"default": false
},
"alwaysShowWorkspaceSelector": {
"description": "Always show workspace button, even if there is only one workspace open or not.",
"type": "boolean",
Expand Down Expand Up @@ -1267,6 +1272,11 @@
}
]
},
"showWorkspaceNameInPopups": {
"description": "Show workspace name as prefix in popup messages or not.",
"type": "boolean",
"default": true
},
"startupCommands": {
"type": "array",
"items": {
Expand Down Expand Up @@ -71081,7 +71091,6 @@
"i18next": "^10.5.0",
"ip": "^1.1.5",
"is-stream": "^1.1.0",
"isbinaryfile": "^3.0.2",
"jsftp": "^2.1.3",
"less": "^2.7.3",
"lodash": "^4.17.5",
Expand All @@ -71107,6 +71116,6 @@
"tmp": "0.0.33",
"uglify-js": "^3.3.13",
"uuid": "^3.2.1",
"vscode-helpers": "^0.16.0"
"vscode-helpers": "^0.19.0"
}
}
113 changes: 111 additions & 2 deletions src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import * as _ from 'lodash';
import * as deploy_contracts from './contracts';
import * as deploy_helpers from './helpers';
import * as deploy_html from './html';
import * as deploy_values from './values';
import * as deploy_workspaces from './workspaces';
import * as Enumerable from 'node-enumerable';
Expand All @@ -26,6 +27,7 @@ import * as HTTP from 'http';
import * as HTTPs from 'https';
import * as i18 from './i18';
import * as ip from 'ip';
const MergeDeep = require('merge-deep');
import * as OS from 'os';
import * as Path from 'path';
import * as vscode from 'vscode';
Expand Down Expand Up @@ -150,6 +152,12 @@ interface HostInfo {
os: string;
}

interface MarkdownDocument {
content: string;
options?: deploy_html.MarkdownDocumentOptions;
title?: string;
}

interface MeInfo {
address: string;
port: number;
Expand Down Expand Up @@ -791,6 +799,106 @@ export class ApiHost extends deploy_helpers.DisposableBase {
.send();
});

// [POST] /api/markdown
app.post('/api/markdown', async (req, resp) => {
const CONTENT_TYPE = deploy_helpers.normalizeString(
req.header('content-type')
);

const BODY = await deploy_helpers.readAll( req );

let doc: MarkdownDocument;
const FROM_JSON = () => {
if (BODY.length > 0) {
doc = JSON.parse(
BODY.toString('utf8')
);
}
};
const FROM_TEXT = () => {
if (BODY.length > 0) {
doc = {
content: BODY.toString('utf8')
};
}
};

try {
switch (CONTENT_TYPE) {
case 'application/json':
FROM_JSON();
break;

case 'text/markdown':
case 'text/plain':
FROM_TEXT();
break;

case '':
try {
FROM_JSON();
}
catch {
FROM_TEXT();
}
break;

default:
return resp.status(406)
.send();
}
}
catch (e) {
return resp.status(400).send(
new Buffer(
JSON.stringify({
success: false,
code: 1,
host: ME.createHostInfo(),
me: ME.createMeInfo(req),
message: "INVALID_INPUT",
error: toErrorObject(e),
vscode: ME.createVSCodeInfo(),
}, null, 2),
'utf8'
)
);
}

if (!doc || deploy_helpers.isEmptyString(doc.content)) {
return resp.status(400).send(
new Buffer(
JSON.stringify({
success: false,
code: 2,
host: ME.createHostInfo(),
me: ME.createMeInfo(req),
message: "NO_DATA",
vscode: ME.createVSCodeInfo(),
}, null, 2),
'utf8'
)
);
}

let title = deploy_helpers.toStringSafe( doc.title ).trim();
if ('' === title) {
title = undefined;
}

const OPTS: deploy_html.MarkdownDocumentOptions = MergeDeep(doc.options, {
documentTitle: title,
}, doc.options);

await deploy_html.openMarkdownDocument(
deploy_helpers.toStringSafe( doc.content ),
OPTS,
);

return resp.status(204)
.send();
});

// [POST] /api/messages
app.post('/api/messages', async (req, resp) => {
const CONTENT_TYPE = deploy_helpers.normalizeString(
Expand Down Expand Up @@ -829,13 +937,14 @@ export class ApiHost extends deploy_helpers.DisposableBase {
try {
FROM_JSON();
}
catch (e) {
catch {
FROM_TEXT();
}
break;

default:
return resp.status(406);
return resp.status(406)
.send();
}
}
catch (e) {
Expand Down
8 changes: 8 additions & 0 deletions src/contracts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,10 @@ export interface ConditionalItem {
export interface Configuration extends deploy_packages.WithFastFileCheckSettings,
deploy_values.WithValueItems
{
/**
* Show workspace name in popups, even if there is only one workspace open.
*/
readonly alwaysShowWorkspaceNameInPopups?: boolean;
/**
* Always show workspace button, even if there is only one workspace open or not.
*/
Expand Down Expand Up @@ -262,6 +266,10 @@ export interface Configuration extends deploy_packages.WithFastFileCheckSettings
* Shows a popup when a deploy operation has been finished.
*/
readonly showPopupWhenFinished?: deploy_gui.ShowPopupWhenFinishedValue;
/**
* Show workspace name as prefix in popup messages or not.
*/
readonly showWorkspaceNameInPopups?: boolean;
/**
* One or more commands that should be run on startup.
*/
Expand Down
Loading

0 comments on commit b50d67f

Please sign in to comment.