summaryrefslogtreecommitdiff
path: root/src/web/app/common/scripts
diff options
context:
space:
mode:
Diffstat (limited to 'src/web/app/common/scripts')
-rw-r--r--src/web/app/common/scripts/api.ts (renamed from src/web/app/common/scripts/api.js)4
-rw-r--r--src/web/app/common/scripts/bytes-to-size.ts (renamed from src/web/app/common/scripts/bytes-to-size.js)4
-rw-r--r--src/web/app/common/scripts/channel-stream.ts (renamed from src/web/app/common/scripts/channel-stream.js)0
-rw-r--r--src/web/app/common/scripts/check-for-update.ts (renamed from src/web/app/common/scripts/check-for-update.js)4
-rw-r--r--src/web/app/common/scripts/config.ts (renamed from src/web/app/common/scripts/config.js)0
-rw-r--r--src/web/app/common/scripts/contains.ts (renamed from src/web/app/common/scripts/contains.js)0
-rw-r--r--src/web/app/common/scripts/copy-to-clipboard.ts (renamed from src/web/app/common/scripts/copy-to-clipboard.js)0
-rw-r--r--src/web/app/common/scripts/date-stringify.ts (renamed from src/web/app/common/scripts/date-stringify.js)0
-rw-r--r--src/web/app/common/scripts/gcd.ts (renamed from src/web/app/common/scripts/gcd.js)0
-rw-r--r--src/web/app/common/scripts/get-kao.ts (renamed from src/web/app/common/scripts/get-kao.js)2
-rw-r--r--src/web/app/common/scripts/home-stream.ts (renamed from src/web/app/common/scripts/home-stream.js)4
-rw-r--r--src/web/app/common/scripts/is-promise.ts (renamed from src/web/app/common/scripts/is-promise.js)0
-rw-r--r--src/web/app/common/scripts/loading.ts (renamed from src/web/app/common/scripts/loading.js)0
-rw-r--r--src/web/app/common/scripts/messaging-stream.ts (renamed from src/web/app/common/scripts/messaging-stream.js)2
-rw-r--r--src/web/app/common/scripts/server-stream-manager.ts31
-rw-r--r--src/web/app/common/scripts/server-stream.ts (renamed from src/web/app/common/scripts/server-stream.js)0
-rw-r--r--src/web/app/common/scripts/signout.ts (renamed from src/web/app/common/scripts/signout.js)0
-rw-r--r--src/web/app/common/scripts/stream-manager.ts33
-rw-r--r--src/web/app/common/scripts/stream.ts (renamed from src/web/app/common/scripts/stream.js)31
-rw-r--r--src/web/app/common/scripts/text-compiler.ts (renamed from src/web/app/common/scripts/text-compiler.js)4
20 files changed, 63 insertions, 56 deletions
diff --git a/src/web/app/common/scripts/api.js b/src/web/app/common/scripts/api.ts
index 4855f736c7..2a9d78e87d 100644
--- a/src/web/app/common/scripts/api.js
+++ b/src/web/app/common/scripts/api.ts
@@ -14,7 +14,7 @@ let pending = 0;
* @param {any} [data={}] Data
* @return {Promise<any>} Response
*/
-export default (i, endpoint, data = {}) => {
+export default (i, endpoint, data = {}): Promise<any> => {
if (++pending === 1) {
spinner = document.createElement('div');
spinner.setAttribute('id', 'wait');
@@ -22,7 +22,7 @@ export default (i, endpoint, data = {}) => {
}
// Append the credential
- if (i != null) data.i = typeof i === 'object' ? i.token : i;
+ if (i != null) (data as any).i = typeof i === 'object' ? i.token : i;
return new Promise((resolve, reject) => {
// Send request
diff --git a/src/web/app/common/scripts/bytes-to-size.js b/src/web/app/common/scripts/bytes-to-size.ts
index af0268dbd0..1d2b1e7ce3 100644
--- a/src/web/app/common/scripts/bytes-to-size.js
+++ b/src/web/app/common/scripts/bytes-to-size.ts
@@ -1,6 +1,6 @@
export default (bytes, digits = 0) => {
- var sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB'];
+ const sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB'];
if (bytes == 0) return '0Byte';
- var i = parseInt(Math.floor(Math.log(bytes) / Math.log(1024)));
+ const i = Math.floor(Math.log(bytes) / Math.log(1024));
return (bytes / Math.pow(1024, i)).toFixed(digits).replace(/\.0+$/, '') + sizes[i];
};
diff --git a/src/web/app/common/scripts/channel-stream.js b/src/web/app/common/scripts/channel-stream.ts
index 17944dbe45..17944dbe45 100644
--- a/src/web/app/common/scripts/channel-stream.js
+++ b/src/web/app/common/scripts/channel-stream.ts
diff --git a/src/web/app/common/scripts/check-for-update.js b/src/web/app/common/scripts/check-for-update.ts
index 7cb7839d29..99d8b5d059 100644
--- a/src/web/app/common/scripts/check-for-update.js
+++ b/src/web/app/common/scripts/check-for-update.ts
@@ -1,5 +1,7 @@
import CONFIG from './config';
+declare var VERSION: string;
+
export default function() {
fetch(CONFIG.apiUrl + '/meta', {
method: 'POST'
@@ -11,4 +13,4 @@ export default function() {
}
});
});
-};
+}
diff --git a/src/web/app/common/scripts/config.js b/src/web/app/common/scripts/config.ts
index c5015622f0..c5015622f0 100644
--- a/src/web/app/common/scripts/config.js
+++ b/src/web/app/common/scripts/config.ts
diff --git a/src/web/app/common/scripts/contains.js b/src/web/app/common/scripts/contains.ts
index a5071b3f25..a5071b3f25 100644
--- a/src/web/app/common/scripts/contains.js
+++ b/src/web/app/common/scripts/contains.ts
diff --git a/src/web/app/common/scripts/copy-to-clipboard.js b/src/web/app/common/scripts/copy-to-clipboard.ts
index 3d2741f8d7..3d2741f8d7 100644
--- a/src/web/app/common/scripts/copy-to-clipboard.js
+++ b/src/web/app/common/scripts/copy-to-clipboard.ts
diff --git a/src/web/app/common/scripts/date-stringify.js b/src/web/app/common/scripts/date-stringify.ts
index e51de8833d..e51de8833d 100644
--- a/src/web/app/common/scripts/date-stringify.js
+++ b/src/web/app/common/scripts/date-stringify.ts
diff --git a/src/web/app/common/scripts/gcd.js b/src/web/app/common/scripts/gcd.ts
index 9a19f9da66..9a19f9da66 100644
--- a/src/web/app/common/scripts/gcd.js
+++ b/src/web/app/common/scripts/gcd.ts
diff --git a/src/web/app/common/scripts/get-kao.js b/src/web/app/common/scripts/get-kao.ts
index 0b77ee285a..2168c5be88 100644
--- a/src/web/app/common/scripts/get-kao.js
+++ b/src/web/app/common/scripts/get-kao.ts
@@ -1,5 +1,5 @@
export default () => [
'(=^・・^=)',
'v(‘ω’)v',
- '🐡( '-' 🐡 )フグパンチ!!!!'
+ '🐡( \'-\' 🐡 )フグパンチ!!!!'
][Math.floor(Math.random() * 3)];
diff --git a/src/web/app/common/scripts/home-stream.js b/src/web/app/common/scripts/home-stream.ts
index de9ceb3b51..c549f2b936 100644
--- a/src/web/app/common/scripts/home-stream.js
+++ b/src/web/app/common/scripts/home-stream.ts
@@ -17,9 +17,9 @@ class Connection extends Stream {
this.send({ type: 'alive' });
}, 1000 * 60);
- this.on('i_updated', me.update);
+ (this as any).on('i_updated', me.update);
- this.on('my_token_regenerated', () => {
+ (this as any).on('my_token_regenerated', () => {
alert('%i18n:common.my-token-regenerated%');
signout();
});
diff --git a/src/web/app/common/scripts/is-promise.js b/src/web/app/common/scripts/is-promise.ts
index 3b4cd70b49..3b4cd70b49 100644
--- a/src/web/app/common/scripts/is-promise.js
+++ b/src/web/app/common/scripts/is-promise.ts
diff --git a/src/web/app/common/scripts/loading.js b/src/web/app/common/scripts/loading.ts
index c48e626648..c48e626648 100644
--- a/src/web/app/common/scripts/loading.js
+++ b/src/web/app/common/scripts/loading.ts
diff --git a/src/web/app/common/scripts/messaging-stream.js b/src/web/app/common/scripts/messaging-stream.ts
index 261525d5f6..63830f7b17 100644
--- a/src/web/app/common/scripts/messaging-stream.js
+++ b/src/web/app/common/scripts/messaging-stream.ts
@@ -12,7 +12,7 @@ class Connection extends Stream {
otherparty
});
- this.on('_connected_', () => {
+ (this as any).on('_connected_', () => {
this.send({
i: me.token
});
diff --git a/src/web/app/common/scripts/server-stream-manager.ts b/src/web/app/common/scripts/server-stream-manager.ts
index 54333c8cf5..a170daebb9 100644
--- a/src/web/app/common/scripts/server-stream-manager.ts
+++ b/src/web/app/common/scripts/server-stream-manager.ts
@@ -1,14 +1,7 @@
+import StreamManager from './stream-manager';
import Connection from './server-stream';
-import * as uuid from 'uuid';
-
-export default class ServerStreamManager {
- private connection = null;
-
- /**
- * コネクションを必要としているユーザー
- */
- private users = [];
+export default class ServerStreamManager extends StreamManager<Connection> {
public getConnection() {
if (this.connection == null) {
this.connection = new Connection();
@@ -16,24 +9,4 @@ export default class ServerStreamManager {
return this.connection;
}
-
- public use() {
- // ユーザーID生成
- const userId = uuid();
-
- this.users.push(userId);
-
- return userId;
- }
-
- public dispose(userId) {
- this.users = this.users.filter(id => id != userId);
-
- // 誰もコネクションの利用者がいなくなったら
- if (this.users.length == 0) {
- // コネクションを切断する
- this.connection.close();
- this.connection = null;
- }
- }
}
diff --git a/src/web/app/common/scripts/server-stream.js b/src/web/app/common/scripts/server-stream.ts
index a1c466b35d..a1c466b35d 100644
--- a/src/web/app/common/scripts/server-stream.js
+++ b/src/web/app/common/scripts/server-stream.ts
diff --git a/src/web/app/common/scripts/signout.js b/src/web/app/common/scripts/signout.ts
index 6c95cfbc9c..6c95cfbc9c 100644
--- a/src/web/app/common/scripts/signout.js
+++ b/src/web/app/common/scripts/signout.ts
diff --git a/src/web/app/common/scripts/stream-manager.ts b/src/web/app/common/scripts/stream-manager.ts
new file mode 100644
index 0000000000..4eaf0f9a45
--- /dev/null
+++ b/src/web/app/common/scripts/stream-manager.ts
@@ -0,0 +1,33 @@
+import * as uuid from 'uuid';
+import Connection from './stream';
+
+export default abstract class StreamManager<T extends Connection> {
+ protected connection: T = null;
+
+ /**
+ * コネクションを必要としているユーザー
+ */
+ private users = [];
+
+ public abstract getConnection(): T;
+
+ public use() {
+ // ユーザーID生成
+ const userId = uuid();
+
+ this.users.push(userId);
+
+ return userId;
+ }
+
+ public dispose(userId) {
+ this.users = this.users.filter(id => id != userId);
+
+ // 誰もコネクションの利用者がいなくなったら
+ if (this.users.length == 0) {
+ // コネクションを切断する
+ this.connection.close();
+ this.connection = null;
+ }
+ }
+}
diff --git a/src/web/app/common/scripts/stream.js b/src/web/app/common/scripts/stream.ts
index a03b7bf200..9595246879 100644
--- a/src/web/app/common/scripts/stream.js
+++ b/src/web/app/common/scripts/stream.ts
@@ -8,7 +8,11 @@ import CONFIG from './config';
* Misskey stream connection
*/
class Connection {
- constructor(endpoint, params) {
+ private state: string;
+ private buffer: any[];
+ private socket: ReconnectingWebsocket;
+
+ constructor(endpoint, params?) {
// BIND -----------------------------------
this.onOpen = this.onOpen.bind(this);
this.onClose = this.onClose.bind(this);
@@ -37,11 +41,10 @@ class Connection {
/**
* Callback of when open connection
- * @private
*/
- onOpen() {
+ private onOpen() {
this.state = 'connected';
- this.trigger('_connected_');
+ (this as any).trigger('_connected_');
// バッファーを処理
const _buffer = [].concat(this.buffer); // Shallow copy
@@ -53,45 +56,41 @@ class Connection {
/**
* Callback of when close connection
- * @private
*/
- onClose() {
+ private onClose() {
this.state = 'reconnecting';
- this.trigger('_closed_');
+ (this as any).trigger('_closed_');
}
/**
* Callback of when received a message from connection
- * @private
*/
- onMessage(message) {
+ private onMessage(message) {
try {
const msg = JSON.parse(message.data);
- if (msg.type) this.trigger(msg.type, msg.body);
- } catch(e) {
+ if (msg.type) (this as any).trigger(msg.type, msg.body);
+ } catch (e) {
// noop
}
}
/**
* Send a message to connection
- * @public
*/
- send(message) {
+ public send(message) {
// まだ接続が確立されていなかったらバッファリングして次に接続した時に送信する
if (this.state != 'connected') {
this.buffer.push(message);
return;
- };
+ }
this.socket.send(JSON.stringify(message));
}
/**
* Close this connection
- * @public
*/
- close() {
+ public close() {
this.socket.removeEventListener('open', this.onOpen);
this.socket.removeEventListener('message', this.onMessage);
}
diff --git a/src/web/app/common/scripts/text-compiler.js b/src/web/app/common/scripts/text-compiler.ts
index 0a9b8022df..8c65d6a068 100644
--- a/src/web/app/common/scripts/text-compiler.js
+++ b/src/web/app/common/scripts/text-compiler.ts
@@ -1,5 +1,5 @@
import * as riot from 'riot';
-const pictograph = require('pictograph');
+import * as pictograph from 'pictograph';
import CONFIG from './config';
const escape = text =>
@@ -12,7 +12,7 @@ export default (tokens, shouldBreak) => {
shouldBreak = true;
}
- const me = riot.mixin('i').me;
+ const me = (riot as any).mixin('i').me;
let text = tokens.map(token => {
switch (token.type) {