Skip to content

Commit

Permalink
Added tslint and fixed all problems
Browse files Browse the repository at this point in the history
  • Loading branch information
SrZorro committed Jun 19, 2018
1 parent a106ca5 commit 664f3fa
Show file tree
Hide file tree
Showing 15 changed files with 2,791 additions and 2,795 deletions.
5,005 changes: 2,524 additions & 2,481 deletions package-lock.json

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,10 @@
"moment": "^2.22.2",
"ts-loader": "^4.4.1",
"ts-transform-inferno": "^2.2.0",
"tslint": "^5.10.0",
"typestyle": "^2.0.1",
"webpack": "^4.12.0",
"webpack-cli": "^3.0.3",
"webpack-dev-server": "^3.1.4"
}
}
}
18 changes: 9 additions & 9 deletions src/main/main.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
import { app, BrowserWindow } from "electron";
import * as path from "path";
declare var __dirname: string
let mainWindow: Electron.BrowserWindow
declare var __dirname: string;
let mainWindow: Electron.BrowserWindow;

function onReady() {
mainWindow = new BrowserWindow({
height: 700,
minHeight: 700,
minWidth: 390,
width: 390,
height: 700,
webPreferences: {
webSecurity: false
}
})
});

// mainWindow.setMenu(null);

mainWindow.loadURL(`file://${__dirname}/index.html`)
mainWindow.on("close", () => app.quit())
mainWindow.loadURL(`file://${__dirname}/index.html`);
mainWindow.on("close", () => app.quit());
}

app.on("ready", () => onReady())
app.on("window-all-closed", () => app.quit())
console.log(`Electron Version ${app.getVersion()}`)
app.on("ready", () => onReady());
app.on("window-all-closed", () => app.quit());
console.log(`Electron Version ${app.getVersion()}`);
78 changes: 40 additions & 38 deletions src/renderer/Amino/AminoClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,29 @@ import Endpoints from "./Endpoints";
import { v4 as UUID } from "uuid";
import * as AminoTypes from "./AminoTypes";

type headers = { [key: string]: string };
interface Iheaders { [key: string]: string; }

declare global {
// tslint:disable-next-line
interface String {
format(...replacer: string[]): string;
}
}
String.prototype.format = function () {
var a = this;
for (var k in arguments) {
a = a.replace(new RegExp("\\{" + k + "\\}", 'g'), arguments[k]);
String.prototype.format = function() {
let a = this;
for (const k in arguments) {
if (arguments.hasOwnProperty(k))
a = a.replace(new RegExp("\\{" + k + "\\}", "g"), arguments[k]);
}
return a
}
return a;
};

class AminoClient {
private sid: string;
private deviceId: string;
public isLogged: boolean;
public onLogged: Function[];
public onLogged: Array<() => void>;
public uid: string;
private sid: string;
private deviceId: string;
constructor() {
this.isLogged = false;
this.onLogged = [];
Expand All @@ -32,13 +34,13 @@ class AminoClient {
public async login(email: string, password: string, deviceId: string) {
this.deviceId = deviceId;
const body = {
email: email,
email,
secret: `0 ${password}`,
deviceID: deviceId,
clientType: 100,
action: "normal",
timestamp: Math.round((new Date).getTime() / 1000)
}
timestamp: Math.round((new Date()).getTime() / 1000)
};

const result = await this.post(Endpoints.LOGIN, body, {
"NDCDEVICEID": this.deviceId,
Expand All @@ -51,7 +53,7 @@ class AminoClient {
case 0: break;
default:
if (!result["api:statuscode"])
throw Error("Unknown error")
throw Error("Unknown error");
const err = new Error(result["api:message"]);
err.name = result["api:statuscode"];
throw err;
Expand All @@ -63,12 +65,12 @@ class AminoClient {
this.isLogged = true;
this.onLogged.map((onLogged) => {
onLogged();
})
});
return result;
}

public async getCommunityCollectionSections(language_code: string, start: number, size: number): Promise<any> {
return await this.get(Endpoints.COMMUNITY_COLLECTION_SECTIONS.format(language_code, start.toString(), size.toString()));
public async getCommunityCollectionSections(languageCode: string, start: number, size: number): Promise<any> {
return await this.get(Endpoints.COMMUNITY_COLLECTION_SECTIONS.format(languageCode, start.toString(), size.toString()));
}

public async getJoinedCommunities(start: number, size: number): Promise<AminoTypes.JoinedCommunitiesInfo> {
Expand Down Expand Up @@ -99,44 +101,44 @@ class AminoClient {
public async sendMessageInThread(ndcId: number, threadId: string, content: string): Promise<AminoTypes.AminoMessage> {
const msg = await this.post(Endpoints.COMMUNITY_CHAT_SEND_MESSAGE.format(ndcId.toString(), threadId), {
attachedObject: null,
content: content,
content,
type: 0,
clientRefId: Math.round((new Date).getTime() / 1000),
timestamp: Math.round((new Date).getTime() / 1000)
clientRefId: Math.round((new Date()).getTime() / 1000),
timestamp: Math.round((new Date()).getTime() / 1000)
}, {
"NDCDEVICEID": this.deviceId,
"NDCAUTH": `sid=${this.sid}`,
"NDC-MSG-SIG": this.getMessageSignature()
})
});
return msg;
}
public async sendMediaInThread(ndcId: number, threadId: string, mediaB64: string, mediaType: string): Promise<AminoTypes.AminoMessage> {
const body = {
type: mediaType.includes("audio") ? 2 : 0,
clientRefId: Math.round((new Date).getTime() / 1000),
clientRefId: Math.round((new Date()).getTime() / 1000),
mediaType: mediaType.includes("audio") ? 110 : 100,
content: null,
mediaUploadValue: mediaB64,
attachedObject: null,
timestamp: Math.round((new Date).getTime() / 1000)
timestamp: Math.round((new Date()).getTime() / 1000)
};
//Note: PNG support is kinda wroken, its converted to jpg and creates artefacts where transparency was located.
// Note: PNG support is kinda wroken, its converted to jpg and creates artefacts where transparency was located.
if (mediaType.includes("image")) {
//@ts-ignore
body.mediaUhqEnabled = false; //High quality maybe?
//@ts-ignore
// @ts-ignore
body.mediaUhqEnabled = false; // High quality maybe?
// @ts-ignore
body.mediaUploadValueContentType = mediaType;
}

const msg = await this.post(Endpoints.COMMUNITY_CHAT_SEND_MESSAGE.format(ndcId.toString(), threadId), body, {
"NDCDEVICEID": this.deviceId,
"NDCAUTH": `sid=${this.sid}`
})
NDCDEVICEID: this.deviceId,
NDCAUTH: `sid=${this.sid}`
});
return msg;
}

private async get(url: string) {
const headers: headers = {
const headers: Iheaders = {
"NDCDEVICEID": this.deviceId,
"NDCAUTH": `sid=${this.sid}`,
"NDC-MSG-SIG": this.getMessageSignature(),
Expand All @@ -146,17 +148,17 @@ class AminoClient {
"Sec-WebSocket-Key": "86iFBnuI8GWLlgWmSToY6g==",
"Sec-WebSocket-Version": "13",
"Accept-Encoding": "gzip"
}
};
const response = await fetch(url, { method: "GET", headers });
return await response.json();
}

private async post(url: string, body: object, headers?: headers) {
const default_headers: headers = {
"NDCDEVICEID": this.deviceId,
"NDCAUTH": `sid=${this.sid}`
}
const response = await fetch(url, { method: "POST", headers: headers ? headers : default_headers, body: JSON.stringify(body) });
private async post(url: string, body: object, headers?: Iheaders) {
const defaultHeaders: Iheaders = {
NDCDEVICEID: this.deviceId,
NDCAUTH: `sid=${this.sid}`
};
const response = await fetch(url, { method: "POST", headers: headers ? headers : defaultHeaders, body: JSON.stringify(body) });
const json = await response.json();
return { ...json, response };
}
Expand Down
90 changes: 45 additions & 45 deletions src/renderer/Amino/Endpoints.ts
Original file line number Diff line number Diff line change
@@ -1,55 +1,55 @@

function generate_endpoints() {
const PREFIX = "http://service.narvii.com/api/v1";
const SECURE_WEBSOCKET = "https://ws3.narvii.com/";
const GET_BLOG_POST = PREFIX + "/{0}/s/blog/{1}";
return {
// // ===[ AUTH ENDPOINTS ]===
LOGIN: PREFIX + "/g/s/auth/login",
REGISTER: PREFIX + "/g/s/auth/register",
REGISTER_CHECK: PREFIX + "/g/s/auth/register-check",
const PREFIX = "http://service.narvii.com/api/v1";
const SECURE_WEBSOCKET = "https://ws3.narvii.com/";
const GET_BLOG_POST = PREFIX + "/{0}/s/blog/{1}";
return {
// // ===[ AUTH ENDPOINTS ]===
LOGIN: PREFIX + "/g/s/auth/login",
REGISTER: PREFIX + "/g/s/auth/register",
REGISTER_CHECK: PREFIX + "/g/s/auth/register-check",

// // ===[ USER ENDPOINTS ]===
AFFILIATIONS: PREFIX + "/g/s/account/affiliations?type=active",
HEADLINES: PREFIX + "/g/s/feed/headlines?start={0}&size={1}",
DEVICE_INFO: PREFIX + "/g/s/device",
// // ===[ USER ENDPOINTS ]===
AFFILIATIONS: PREFIX + "/g/s/account/affiliations?type=active",
HEADLINES: PREFIX + "/g/s/feed/headlines?start={0}&size={1}",
DEVICE_INFO: PREFIX + "/g/s/device",

// // ===[ COMMUNITY ENDPOINTS ]===
LINK_IDENTIFY: PREFIX + "/g/s/community/link-identify?q={0}",
JOIN_COMMUNITY: PREFIX + "/{0}/s/community/join",
LEAVE_COMMUNITY: PREFIX + "/{0}/s/community/leave",
COMMUNITY_INFO: PREFIX + "/g/s-x{0}/community/info",
SUGGESTED_COMMUNITIES: PREFIX + "/g/s/community/suggested?language={0}",
TRENDING_COMMUNITIES: PREFIX + "/g/s/community/trending?start={0}&size={1}&language={2}",
COMMUNITY_FEED: PREFIX + "/{0}/s/feed/blog-all?start={1}&size={2}",
COMMUNITY_ONLINE_MEMBERS: PREFIX + "/{0}/s/community/online-members-check",
SUGGESTED_KEYWORDS: PREFIX + "/g/s/community/search/suggested-keywords?q={0}&start={1}&size={2}&language={3}",
SEARCH_TAGS: PREFIX + "/g/s/community/search/tags?q={0}",
SEARCH_COMMUNITIES: PREFIX + "/g/s/community/search?q={0}&start={1}&size={2}&language={3}&completeKeyword={4}",
JOINED_COMMUNITIES: PREFIX + "/g/s/community/joined?start={0}&size={1}",
SUPPORTED_LANGUAGES: PREFIX + "/g/s/community-collection/supported-languages?start={0}&size={1}",
COMMUNITY_COLLECTION_SECTIONS: PREFIX + "/g/s/community-collection/view/explore/sections?language={0}&start={1}&size={2}",
COMMUNITY_CHECK_IN: PREFIX + "/x{0}/s/check-in",
// // ===[ COMMUNITY ENDPOINTS ]===
LINK_IDENTIFY: PREFIX + "/g/s/community/link-identify?q={0}",
JOIN_COMMUNITY: PREFIX + "/{0}/s/community/join",
LEAVE_COMMUNITY: PREFIX + "/{0}/s/community/leave",
COMMUNITY_INFO: PREFIX + "/g/s-x{0}/community/info",
SUGGESTED_COMMUNITIES: PREFIX + "/g/s/community/suggested?language={0}",
TRENDING_COMMUNITIES: PREFIX + "/g/s/community/trending?start={0}&size={1}&language={2}",
COMMUNITY_FEED: PREFIX + "/{0}/s/feed/blog-all?start={1}&size={2}",
COMMUNITY_ONLINE_MEMBERS: PREFIX + "/{0}/s/community/online-members-check",
SUGGESTED_KEYWORDS: PREFIX + "/g/s/community/search/suggested-keywords?q={0}&start={1}&size={2}&language={3}",
SEARCH_TAGS: PREFIX + "/g/s/community/search/tags?q={0}",
SEARCH_COMMUNITIES: PREFIX + "/g/s/community/search?q={0}&start={1}&size={2}&language={3}&completeKeyword={4}",
JOINED_COMMUNITIES: PREFIX + "/g/s/community/joined?start={0}&size={1}",
SUPPORTED_LANGUAGES: PREFIX + "/g/s/community-collection/supported-languages?start={0}&size={1}",
COMMUNITY_COLLECTION_SECTIONS: PREFIX + "/g/s/community-collection/view/explore/sections?language={0}&start={1}&size={2}",
COMMUNITY_CHECK_IN: PREFIX + "/x{0}/s/check-in",

// // ===[ NOTIFICATION ENDPOINTS ]===
COMMUNITY_NOTIFICATIONS: PREFIX + "/{0}/s/notification?start={1}&size={2}&cv={3}",
REMINDERS: PREFIX + "/g/s/reminder/check?ndcIds={0}&timezone={1}",
// // ===[ NOTIFICATION ENDPOINTS ]===
COMMUNITY_NOTIFICATIONS: PREFIX + "/{0}/s/notification?start={1}&size={2}&cv={3}",
REMINDERS: PREFIX + "/g/s/reminder/check?ndcIds={0}&timezone={1}",

// // ===[ BLOG ENDPOINTS ]===
GET_BLOG_POST,
POST_VOTE: GET_BLOG_POST + "/vote",
POST_COMMENT: GET_BLOG_POST + "/comment",
// // ===[ BLOG ENDPOINTS ]===
GET_BLOG_POST,
POST_VOTE: GET_BLOG_POST + "/vote",
POST_COMMENT: GET_BLOG_POST + "/comment",

// ===[ CHAT ENDPOINTS ]===
COMMUNITY_THREAD: PREFIX + "/x{0}/s/chat/thread/{1}",
COMMUNITY_CHAT_THREAD: PREFIX + "/x{0}/s/chat/thread?type={1}&start={2}&size={3}",
COMMUNITY_JOIN_CHAT_THREAD: PREFIX + "/x{0}/s/chat/thread/{1}/member/{2}",
COMMUNITY_CHAT_SEND_MESSAGE: PREFIX + "/x{0}/s/chat/thread/{1}/message",
COMMUNITY_CHAT_GET_MESSAGES: PREFIX + "/x{0}/s/chat/thread/{1}/message?start={2}&size={3}",
COMMUNITY_CHAT_GET_MESSAGES_SINCE: PREFIX + "/x{0}/s/chat/thread/{1}/message?start={2}&size={3}&starttime={4}",
// ===[ CHAT ENDPOINTS ]===
COMMUNITY_THREAD: PREFIX + "/x{0}/s/chat/thread/{1}",
COMMUNITY_CHAT_THREAD: PREFIX + "/x{0}/s/chat/thread?type={1}&start={2}&size={3}",
COMMUNITY_JOIN_CHAT_THREAD: PREFIX + "/x{0}/s/chat/thread/{1}/member/{2}",
COMMUNITY_CHAT_SEND_MESSAGE: PREFIX + "/x{0}/s/chat/thread/{1}/message",
COMMUNITY_CHAT_GET_MESSAGES: PREFIX + "/x{0}/s/chat/thread/{1}/message?start={2}&size={3}",
COMMUNITY_CHAT_GET_MESSAGES_SINCE: PREFIX + "/x{0}/s/chat/thread/{1}/message?start={2}&size={3}&starttime={4}",

// ===[ LIVE LAYERS ]===
LIVE_LAYERS_PUBLIC_CHAT: PREFIX + "/x{0}/s/live-layer/public-chats?start=0&size=25"
}
// ===[ LIVE LAYERS ]===
LIVE_LAYERS_PUBLIC_CHAT: PREFIX + "/x{0}/s/live-layer/public-chats?start=0&size=25"
};
}
export default generate_endpoints();
Loading

0 comments on commit 664f3fa

Please sign in to comment.