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

Major Upgrade #123

Merged
merged 19 commits into from
Aug 21, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Cleanup and fixed some issues (#122)
* Fixed a high vulnerability in node

* Fixed authentication issues and updated packages

* Fixed promise issues in the highlight

* Removed declaration generation

* Updated webpack plugins and options
  • Loading branch information
parithon authored May 27, 2020
commit cad9ab2252a189f78fb70c1b4435a3ccf819114a
2,962 changes: 1,683 additions & 1,279 deletions package-lock.json

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -269,18 +269,18 @@
"@types/tmi.js": "^1.4.0",
"@types/uuid": "^3.4.5",
"bufferutil": "^4.0.1",
"clean-webpack-plugin": "^1.0.1",
"clean-webpack-plugin": "^3.0.0",
"copy-webpack-plugin": "^6.0.1",
"copyfiles": "^2.1.1",
"copy-webpack-plugin": "^5.0.4",
"mocha-junit-reporter": "^1.18.0",
"spec-xunit-file": "0.0.1-3",
"ts-loader": "^5.3.3",
"tslint": "^5.8.0",
"typescript": "^2.6.1",
"utf-8-validate": "^5.0.2",
"vscode": "^1.1.33",
"webpack": "^4.29.4",
"webpack-cli": "^3.2.3"
"webpack": "^4.43.0",
"webpack-cli": "^3.3.11"
},
"dependencies": {
"request": "^2.88.0",
Expand Down
111 changes: 60 additions & 51 deletions src/highlight/HighlightManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,70 +54,79 @@ export class HighlightManager {
return [];
}

public Add(document: TextDocument, userName: string, startLine: number, endLine?: number, comments?: string): void {
if (!endLine) {
endLine = startLine;
}

const range = new Range(
new Position(--startLine, 0),
new Position(--endLine, document.lineAt(endLine).text.length)
);
public Add(document: TextDocument, userName: string, startLine: number, endLine?: number, comments?: string): Promise<void> {
return new Promise(resolve => {

const highlight = new Highlight(userName, range, comments);

const idx = this.highlightCollection.findIndex(h => h.fileName === document.fileName);
if (idx > -1) {
if (!this.highlightCollection[idx].highlights.some(h => (h.userName === userName || userName === 'self') && h.startLine <= startLine && h.endLine >= endLine!)) {
this.highlightCollection[idx].highlights.push(highlight);
if (!endLine) {
endLine = startLine;
}
}
else {
this.highlightCollection.push({
fileName: document.fileName,
highlights: [highlight]
});
}

this._onHighlightsChanged.fire();

const range = new Range(
new Position(--startLine, 0),
new Position(--endLine, document.lineAt(endLine).text.length)
);

const highlight = new Highlight(userName, range, comments);

const idx = this.highlightCollection.findIndex(h => h.fileName === document.fileName);
if (idx > -1) {
if (!this.highlightCollection[idx].highlights.some(h => (h.userName === userName || userName === 'self') && h.startLine <= startLine && h.endLine >= endLine!)) {
this.highlightCollection[idx].highlights.push(highlight);
}
}
else {
this.highlightCollection.push({
fileName: document.fileName,
highlights: [highlight]
});
}

this._onHighlightsChanged.fire();
resolve();
});
}

public Remove(document: TextDocument, userName: string, lineNumber: number, deferRefresh?: boolean): void;
public Remove(fileName: string, userName: string, lineNumber: number, deferRefresh?: boolean): void;
public Remove(documentOrFileName: TextDocument | string, userName: string, lineNumber: number, deferRefresh: boolean = false): void {
if (!isString(documentOrFileName)) {
documentOrFileName = documentOrFileName.fileName;
}

const idx = this.highlightCollection.findIndex(h => h.fileName === documentOrFileName);
if (idx > -1) {
const hidx = this.highlightCollection[idx].highlights.findIndex(h => (h.userName === userName || userName === 'self') && h.startLine <= lineNumber && h.endLine >= lineNumber);
if (hidx > -1) {
this.highlightCollection[idx].highlights.splice(hidx, 1);
public Remove(document: TextDocument, userName: string, lineNumber: number, deferRefresh?: boolean): Promise<void>;
public Remove(fileName: string, userName: string, lineNumber: number, deferRefresh?: boolean): Promise<void>;
public Remove(documentOrFileName: TextDocument | string, userName: string, lineNumber: number, deferRefresh: boolean = false): Promise<void> {
return new Promise<void>(resolve =>{
if (!isString(documentOrFileName)) {
documentOrFileName = documentOrFileName.fileName;
}
if (!deferRefresh) {
this._onHighlightsChanged.fire();

const idx = this.highlightCollection.findIndex(h => h.fileName === documentOrFileName);
if (idx > -1) {
const hidx = this.highlightCollection[idx].highlights.findIndex(h => (h.userName === userName || userName === 'self') && h.startLine <= lineNumber && h.endLine >= lineNumber);
if (hidx > -1) {
this.highlightCollection[idx].highlights.splice(hidx, 1);
}
if (!deferRefresh) {
this._onHighlightsChanged.fire();
}
}
}
resolve();
});
}

public Refresh() {
this._onHighlightsChanged.fire();
}

public Clear(service?: string) {
if (service) {
this.highlightCollection.forEach(hc => {
const highlightsToRemove = hc.highlights.filter(h => h.userName.indexOf(`${service}:`) > -1);
highlightsToRemove.forEach(h => {
this.Remove(hc.fileName, h.userName, h.startLine, true);
public Clear(service?: string): Promise<void> {
return new Promise<void>(resolve =>{
if (service) {
this.highlightCollection.forEach(hc => {
const highlightsToRemove = hc.highlights.filter(h => h.userName.indexOf(`${service}:`) > -1);
highlightsToRemove.forEach(h => {
this.Remove(hc.fileName, h.userName, h.startLine, true);
});
});
});
}
else {
this.highlightCollection = new Array<HighlightCollection>();
}
this._onHighlightsChanged.fire();
}
else {
this.highlightCollection = new Array<HighlightCollection>();
}
this._onHighlightsChanged.fire();
});
}

public Rename(oldName: string, newName: string) {
Expand Down
10 changes: 5 additions & 5 deletions src/ttvchat/AuthenticationService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ export class AuthenticationService {
const mReqPath = mReq.pathname;

if (mReqPath === '/') {
res.writeHead(200, { 'Content-Type': 'text/html' });
res.writeHead(200, { 'Content-Type': 'text/html', 'Cache-Control': 'no-cache' });
res.end(file);
}
else if (mReqPath === '/oauth') {
Expand All @@ -93,18 +93,18 @@ export class AuthenticationService {
return;
}

res.writeHead(200);
res.end(file);

const validationResult = await API.validateToken(q.access_token);
if (keytar && validationResult.valid) {
keytar.setPassword(KeytarKeys.service, KeytarKeys.account, q.access_token);
keytar.setPassword(KeytarKeys.service, KeytarKeys.userLogin, validationResult.login);
this._onAuthStatusChanged.fire(true);
}

res.writeHead(200, { 'Content-Type': 'text/html', 'Cache-Control': 'no-cache' });
res.end(file);
}
else if (mReqPath === '/complete') {
res.writeHead(200);
res.writeHead(200, { 'Content-Type': 'text/html', 'Cache-Control': 'no-cache' });
res.end(file);
setTimeout(() => server.close(), 3000);
}
Expand Down
8 changes: 6 additions & 2 deletions src/ttvchat/login/index.htm
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,17 @@
<head>
<script type="text/javascript">
window.onload = function () {
window.location.href = 'oauth?' + window.location.hash.replace('#', '');
if (window.location.href.includes("/#")) {
window.location.href = 'oauth?' + window.location.hash.replace('#', '');
} else if (window.location.href.includes("oauth?")) {
window.location.href = 'complete'
}
};
</script>
</head>

<body>
<h1>You can close the browser</h1>
<h1>You can close the window</h1>
</body>

</html>
4 changes: 2 additions & 2 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
"es6",
"es2017"
],
"declaration": true,
"declarationDir": "types",
// "declaration": false,
// "declarationDir": "types",
"sourceMap": true,
"rootDir": "src",
/* Strict Type-Checking Option */
Expand Down
12 changes: 7 additions & 5 deletions webpack.config.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';

const path = require('path');
const CleanWebpackPlugin = require('clean-webpack-plugin');
const { CleanWebpackPlugin } = require('clean-webpack-plugin');
const CopyPlugin = require('copy-webpack-plugin');

module.exports = {
Expand All @@ -13,10 +13,12 @@ module.exports = {
},
devtool: 'source-map',
plugins: [
new CleanWebpackPlugin(['out']),
new CopyPlugin([
{ from: 'src/ttvchat/login', to: 'ttvchat/login' }
])
new CleanWebpackPlugin(),
new CopyPlugin({
patterns: [
{ from: 'src/ttvchat/login', to: 'ttvchat/login' }
]
})
],
module: {
rules: [
Expand Down