From 7401ac08e138da3efc414ba295d0a31950066100 Mon Sep 17 00:00:00 2001 From: "greenkeeper[bot]" Date: Tue, 15 Aug 2017 21:51:32 +0000 Subject: [PATCH 001/327] chore(package): update @types/js-yaml to version 3.9.1 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 875ffc3c6..1632eed24 100644 --- a/package.json +++ b/package.json @@ -46,7 +46,7 @@ "@types/inquirer": "0.0.34", "@types/is-root": "1.0.0", "@types/is-url": "1.2.28", - "@types/js-yaml": "3.9.0", + "@types/js-yaml": "3.9.1", "@types/mocha": "2.2.41", "@types/mongodb": "2.2.9", "@types/monk": "1.0.5", From 1ee77c5d8a0a1953e873f3d2a112edc64f1c8f7d Mon Sep 17 00:00:00 2001 From: "greenkeeper[bot]" Date: Mon, 21 Aug 2017 21:49:00 +0000 Subject: [PATCH 002/327] chore(package): update @types/bcryptjs to version 2.4.1 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 141e95c88..ff3f6c79f 100644 --- a/package.json +++ b/package.json @@ -21,7 +21,7 @@ "test": "gulp test" }, "devDependencies": { - "@types/bcryptjs": "2.4.0", + "@types/bcryptjs": "2.4.1", "@types/body-parser": "1.16.4", "@types/chai": "4.0.3", "@types/chai-http": "3.0.2", From 7d0f8b8389716ab235ded68442f6881c10d78620 Mon Sep 17 00:00:00 2001 From: "greenkeeper[bot]" Date: Mon, 21 Aug 2017 23:28:05 +0000 Subject: [PATCH 003/327] chore(package): update @types/rimraf to version 2.0.2 Closes #697 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 47006ae5d..f16c3c001 100644 --- a/package.json +++ b/package.json @@ -57,7 +57,7 @@ "@types/ratelimiter": "2.1.28", "@types/redis": "2.6.0", "@types/request": "2.0.1", - "@types/rimraf": "2.0.0", + "@types/rimraf": "2.0.2", "@types/riot": "3.6.0", "@types/serve-favicon": "2.2.28", "@types/uuid": "3.4.0", From 08f89d519cc9aea32f91bcd1f650b2b82ef0ebd2 Mon Sep 17 00:00:00 2001 From: "greenkeeper[bot]" Date: Mon, 21 Aug 2017 23:28:23 +0000 Subject: [PATCH 004/327] chore(package): update @types/serve-favicon to version 2.2.29 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 47006ae5d..639261cb9 100644 --- a/package.json +++ b/package.json @@ -59,7 +59,7 @@ "@types/request": "2.0.1", "@types/rimraf": "2.0.0", "@types/riot": "3.6.0", - "@types/serve-favicon": "2.2.28", + "@types/serve-favicon": "2.2.29", "@types/uuid": "3.4.0", "@types/webpack": "3.0.9", "@types/webpack-stream": "3.2.7", From f7abed655b4d318157579773dd8f954ceecf33e7 Mon Sep 17 00:00:00 2001 From: "greenkeeper[bot]" Date: Thu, 28 Sep 2017 07:55:56 +0000 Subject: [PATCH 005/327] chore(package): update @types/elasticsearch to version 5.0.17 Closes #698 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 0a437eefb..455204111 100644 --- a/package.json +++ b/package.json @@ -30,7 +30,7 @@ "@types/cors": "2.8.1", "@types/debug": "0.0.30", "@types/deep-equal": "1.0.1", - "@types/elasticsearch": "5.0.14", + "@types/elasticsearch": "5.0.17", "@types/event-stream": "3.3.32", "@types/express": "4.0.37", "@types/gm": "1.17.32", From b3ea7e10cd0ee93478d0b033e8bc78b33aec64ea Mon Sep 17 00:00:00 2001 From: "greenkeeper[bot]" Date: Fri, 6 Oct 2017 03:32:55 +0000 Subject: [PATCH 006/327] chore(package): update mocha to version 4.0.1 Closes #810 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index b56f97c79..4dc11b02f 100644 --- a/package.json +++ b/package.json @@ -80,7 +80,7 @@ "gulp-typescript": "3.2.2", "gulp-uglify": "3.0.0", "gulp-util": "3.0.8", - "mocha": "3.5.3", + "mocha": "4.0.1", "riot-tag-loader": "1.0.0", "string-replace-webpack-plugin": "0.1.3", "style-loader": "0.19.0", From dab6fd56628426aa1deb203e7f13b65504061017 Mon Sep 17 00:00:00 2001 From: "greenkeeper[bot]" Date: Tue, 17 Oct 2017 00:15:25 +0000 Subject: [PATCH 007/327] chore(package): update @types/gm to version 1.17.33 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 688664fa6..0c6d3ff3d 100644 --- a/package.json +++ b/package.json @@ -33,7 +33,7 @@ "@types/elasticsearch": "5.0.14", "@types/event-stream": "3.3.32", "@types/express": "4.0.37", - "@types/gm": "1.17.32", + "@types/gm": "1.17.33", "@types/gulp": "4.0.3", "@types/gulp-htmlmin": "1.3.30", "@types/gulp-mocha": "0.0.30", From f10f11292d26a83bf94556a2633604403724daba Mon Sep 17 00:00:00 2001 From: "greenkeeper[bot]" Date: Tue, 17 Oct 2017 07:08:45 +0000 Subject: [PATCH 008/327] fix(package): update file-type to version 7.2.0 Closes #821 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 688664fa6..a7f52d064 100644 --- a/package.json +++ b/package.json @@ -114,7 +114,7 @@ "elasticsearch": "13.3.1", "escape-regexp": "0.0.1", "express": "4.15.4", - "file-type": "6.2.0", + "file-type": "7.2.0", "fuckadblock": "3.2.1", "gm": "1.23.0", "inquirer": "3.3.0", From 7398f31b58571ba1509ef75fddbc27043ccd8351 Mon Sep 17 00:00:00 2001 From: "greenkeeper[bot]" Date: Tue, 17 Oct 2017 18:37:46 +0000 Subject: [PATCH 009/327] chore(package): update @types/uuid to version 3.4.3 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 688664fa6..daf3e3dc0 100644 --- a/package.json +++ b/package.json @@ -60,7 +60,7 @@ "@types/rimraf": "2.0.0", "@types/riot": "3.6.0", "@types/serve-favicon": "2.2.28", - "@types/uuid": "3.4.2", + "@types/uuid": "3.4.3", "@types/webpack": "3.0.13", "@types/webpack-stream": "3.2.7", "@types/websocket": "0.0.34", From b3a5f6ac92f28f6728090ab3f4e2693390cde81f Mon Sep 17 00:00:00 2001 From: "greenkeeper[bot]" Date: Fri, 20 Oct 2017 19:19:57 +0000 Subject: [PATCH 010/327] chore(package): update tslint to version 5.8.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index dd1622a37..09a8b7c88 100644 --- a/package.json +++ b/package.json @@ -88,7 +88,7 @@ "stylus": "0.54.5", "stylus-loader": "3.0.1", "swagger-jsdoc": "1.9.7", - "tslint": "5.7.0", + "tslint": "5.8.0", "uglify-es": "3.0.27", "uglify-es-webpack-plugin": "0.10.0", "uglify-js": "git+https://github.com/mishoo/UglifyJS2.git#harmony", From a9675b7407fb72971b86c0a1aefa8b3f040c7956 Mon Sep 17 00:00:00 2001 From: "greenkeeper[bot]" Date: Mon, 23 Oct 2017 20:25:17 +0000 Subject: [PATCH 011/327] chore(package): update gulp-typescript to version 3.2.3 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 4ddb3cb45..aa98122de 100644 --- a/package.json +++ b/package.json @@ -78,7 +78,7 @@ "gulp-rename": "1.2.2", "gulp-replace": "0.6.1", "gulp-tslint": "8.1.2", - "gulp-typescript": "3.2.2", + "gulp-typescript": "3.2.3", "gulp-uglify": "3.0.0", "gulp-util": "3.0.8", "mocha": "3.5.3", From f45b680d5012429a18229e07ce38362b496e6c33 Mon Sep 17 00:00:00 2001 From: "greenkeeper[bot]" Date: Tue, 24 Oct 2017 02:40:07 +0000 Subject: [PATCH 012/327] chore(package): update uglifyjs-webpack-plugin to version 1.0.1 Closes #841 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 4ddb3cb45..0b990ea40 100644 --- a/package.json +++ b/package.json @@ -91,7 +91,7 @@ "tslint": "5.7.0", "uglify-es": "3.0.27", "uglify-js": "git+https://github.com/mishoo/UglifyJS2.git#harmony", - "uglifyjs-webpack-plugin": "1.0.0-beta.2", + "uglifyjs-webpack-plugin": "1.0.1", "webpack": "3.8.1" }, "dependencies": { From 6ec1afb2c331454200bc7ac1aa3501576ee9b7fc Mon Sep 17 00:00:00 2001 From: "greenkeeper[bot]" Date: Tue, 24 Oct 2017 04:31:04 +0000 Subject: [PATCH 013/327] fix(package): update chalk to version 2.3.0 Closes #833 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 4ddb3cb45..2284bb01b 100644 --- a/package.json +++ b/package.json @@ -101,7 +101,7 @@ "bcryptjs": "2.4.3", "body-parser": "1.18.2", "cafy": "3.0.0", - "chalk": "2.1.0", + "chalk": "2.3.0", "compression": "1.7.1", "cors": "2.8.4", "cropperjs": "1.1.3", From afeea23a00d5d407e5c203d5a3d17203300853e4 Mon Sep 17 00:00:00 2001 From: "greenkeeper[bot]" Date: Wed, 25 Oct 2017 00:30:04 +0000 Subject: [PATCH 014/327] chore(package): update @types/gulp to version 4.0.5 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 4ddb3cb45..7be9e49d6 100644 --- a/package.json +++ b/package.json @@ -34,7 +34,7 @@ "@types/event-stream": "3.3.32", "@types/express": "4.0.37", "@types/gm": "1.17.32", - "@types/gulp": "4.0.3", + "@types/gulp": "4.0.5", "@types/gulp-htmlmin": "1.3.30", "@types/gulp-mocha": "0.0.30", "@types/gulp-rename": "0.0.32", From f7bf82aaa670a12c3ba2ad305726cd0b0f26a689 Mon Sep 17 00:00:00 2001 From: "greenkeeper[bot]" Date: Wed, 25 Oct 2017 01:05:05 +0000 Subject: [PATCH 015/327] chore(package): update @types/gulp-uglify to version 3.0.3 Closes #664 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 4ddb3cb45..96d397307 100644 --- a/package.json +++ b/package.json @@ -41,7 +41,7 @@ "@types/gulp-replace": "0.0.30", "@types/gulp-tslint": "3.6.31", "@types/gulp-typescript": "2.13.0", - "@types/gulp-uglify": "0.0.30", + "@types/gulp-uglify": "3.0.3", "@types/gulp-util": "3.0.31", "@types/inquirer": "0.0.34", "@types/is-root": "1.0.0", From 9eecd9f3d18c2e2f5a8bd4dda78fcef7e132655c Mon Sep 17 00:00:00 2001 From: "greenkeeper[bot]" Date: Wed, 25 Oct 2017 01:30:35 +0000 Subject: [PATCH 016/327] chore(package): update @types/mongodb to version 2.2.15 Closes #836 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 4ddb3cb45..5105ea727 100644 --- a/package.json +++ b/package.json @@ -48,7 +48,7 @@ "@types/is-url": "1.2.28", "@types/js-yaml": "3.9.0", "@types/mocha": "2.2.43", - "@types/mongodb": "2.2.13", + "@types/mongodb": "2.2.15", "@types/monk": "1.0.6", "@types/morgan": "1.7.33", "@types/ms": "0.7.30", From d68f30ad938ded1a35d6b7f14d2ee635dd9b591c Mon Sep 17 00:00:00 2001 From: "greenkeeper[bot]" Date: Wed, 25 Oct 2017 02:13:31 +0000 Subject: [PATCH 017/327] chore(package): update @types/node to version 8.0.47 Closes #822 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 4ddb3cb45..0f63f1f0a 100644 --- a/package.json +++ b/package.json @@ -53,7 +53,7 @@ "@types/morgan": "1.7.33", "@types/ms": "0.7.30", "@types/multer": "1.3.2", - "@types/node": "8.0.33", + "@types/node": "8.0.47", "@types/ratelimiter": "2.1.28", "@types/redis": "2.6.0", "@types/request": "2.0.4", From 19e9ea3624547f36e20019a5062e4a2de695025b Mon Sep 17 00:00:00 2001 From: "greenkeeper[bot]" Date: Wed, 25 Oct 2017 16:48:59 +0000 Subject: [PATCH 018/327] chore(package): update @types/riot to version 3.6.1 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 43a015961..1eb0e94cd 100644 --- a/package.json +++ b/package.json @@ -58,7 +58,7 @@ "@types/redis": "2.6.0", "@types/request": "2.0.4", "@types/rimraf": "2.0.0", - "@types/riot": "3.6.0", + "@types/riot": "3.6.1", "@types/serve-favicon": "2.2.28", "@types/uuid": "3.4.2", "@types/webpack": "3.0.13", From eff772d100a8028ec5542c91a9f2a7079fedbb8e Mon Sep 17 00:00:00 2001 From: "greenkeeper[bot]" Date: Wed, 25 Oct 2017 18:05:35 +0000 Subject: [PATCH 019/327] chore(package): update @types/webpack to version 3.0.14 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 43a015961..d15c25a28 100644 --- a/package.json +++ b/package.json @@ -61,7 +61,7 @@ "@types/riot": "3.6.0", "@types/serve-favicon": "2.2.28", "@types/uuid": "3.4.2", - "@types/webpack": "3.0.13", + "@types/webpack": "3.0.14", "@types/webpack-stream": "3.2.7", "@types/websocket": "0.0.34", "awesome-typescript-loader": "3.2.3", From 0d8246b42e4746af6268ab1253e32a921de6b870 Mon Sep 17 00:00:00 2001 From: "greenkeeper[bot]" Date: Wed, 25 Oct 2017 19:26:49 +0000 Subject: [PATCH 020/327] chore(package): update @types/webpack-stream to version 3.2.8 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 43a015961..f83f7ff0b 100644 --- a/package.json +++ b/package.json @@ -62,7 +62,7 @@ "@types/serve-favicon": "2.2.28", "@types/uuid": "3.4.2", "@types/webpack": "3.0.13", - "@types/webpack-stream": "3.2.7", + "@types/webpack-stream": "3.2.8", "@types/websocket": "0.0.34", "awesome-typescript-loader": "3.2.3", "chai": "4.1.2", From dfffde6366d05eb191fa8cbe74e802eba3429934 Mon Sep 17 00:00:00 2001 From: "greenkeeper[bot]" Date: Wed, 25 Oct 2017 20:20:52 +0000 Subject: [PATCH 021/327] chore(package): update @types/request to version 2.0.7 Closes #827 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 43a015961..473878e39 100644 --- a/package.json +++ b/package.json @@ -56,7 +56,7 @@ "@types/node": "8.0.33", "@types/ratelimiter": "2.1.28", "@types/redis": "2.6.0", - "@types/request": "2.0.4", + "@types/request": "2.0.7", "@types/rimraf": "2.0.0", "@types/riot": "3.6.0", "@types/serve-favicon": "2.2.28", From 7b6cf54f7a7f585c6d7387ac8acf0bc51b775336 Mon Sep 17 00:00:00 2001 From: "greenkeeper[bot]" Date: Thu, 26 Oct 2017 15:08:12 +0000 Subject: [PATCH 022/327] chore(package): update @types/gulp-util to version 3.0.33 Closes #846 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 43a015961..1da36f5be 100644 --- a/package.json +++ b/package.json @@ -42,7 +42,7 @@ "@types/gulp-tslint": "3.6.31", "@types/gulp-typescript": "2.13.0", "@types/gulp-uglify": "0.0.30", - "@types/gulp-util": "3.0.31", + "@types/gulp-util": "3.0.33", "@types/inquirer": "0.0.34", "@types/is-root": "1.0.0", "@types/is-url": "1.2.28", From 59e28a64f41ae825261dd8ee278d1368d39fef19 Mon Sep 17 00:00:00 2001 From: "greenkeeper[bot]" Date: Thu, 26 Oct 2017 15:09:38 +0000 Subject: [PATCH 023/327] chore(package): update @types/chalk to version 2.2.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 43a015961..0deb7dbb0 100644 --- a/package.json +++ b/package.json @@ -25,7 +25,7 @@ "@types/body-parser": "1.16.5", "@types/chai": "4.0.4", "@types/chai-http": "3.0.3", - "@types/chalk": "0.4.31", + "@types/chalk": "2.2.0", "@types/compression": "0.0.34", "@types/cors": "2.8.1", "@types/debug": "0.0.30", From cec34bf97ca9b199eb753705a1371fbfa8f5fa38 Mon Sep 17 00:00:00 2001 From: "greenkeeper[bot]" Date: Thu, 26 Oct 2017 18:06:50 +0000 Subject: [PATCH 024/327] chore(package): update @types/mocha to version 2.2.44 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 43a015961..163c2da57 100644 --- a/package.json +++ b/package.json @@ -47,7 +47,7 @@ "@types/is-root": "1.0.0", "@types/is-url": "1.2.28", "@types/js-yaml": "3.9.0", - "@types/mocha": "2.2.43", + "@types/mocha": "2.2.44", "@types/mongodb": "2.2.13", "@types/monk": "1.0.6", "@types/morgan": "1.7.33", From cff96fce45c8e64cd95b02ae48da6e23e8cbc3a9 Mon Sep 17 00:00:00 2001 From: "greenkeeper[bot]" Date: Thu, 26 Oct 2017 19:32:50 +0000 Subject: [PATCH 025/327] chore(package): update @types/body-parser to version 1.16.7 Closes #843 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 43a015961..8b32db9a8 100644 --- a/package.json +++ b/package.json @@ -22,7 +22,7 @@ }, "devDependencies": { "@types/bcryptjs": "2.4.0", - "@types/body-parser": "1.16.5", + "@types/body-parser": "1.16.7", "@types/chai": "4.0.4", "@types/chai-http": "3.0.3", "@types/chalk": "0.4.31", From c2befca344d91c554b862b19467ae7ef3d187367 Mon Sep 17 00:00:00 2001 From: "greenkeeper[bot]" Date: Thu, 26 Oct 2017 19:34:24 +0000 Subject: [PATCH 026/327] chore(package): update @types/express to version 4.0.39 Closes #844 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 43a015961..c6da419d2 100644 --- a/package.json +++ b/package.json @@ -32,7 +32,7 @@ "@types/deep-equal": "1.0.1", "@types/elasticsearch": "5.0.14", "@types/event-stream": "3.3.32", - "@types/express": "4.0.37", + "@types/express": "4.0.39", "@types/gm": "1.17.32", "@types/gulp": "4.0.3", "@types/gulp-htmlmin": "1.3.30", From e68df9925e2c8fc855b115c0f6c3171ee014e8ae Mon Sep 17 00:00:00 2001 From: "greenkeeper[bot]" Date: Thu, 26 Oct 2017 19:35:00 +0000 Subject: [PATCH 027/327] chore(package): update @types/morgan to version 1.7.35 Closes #847 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 43a015961..d2c8ac38a 100644 --- a/package.json +++ b/package.json @@ -50,7 +50,7 @@ "@types/mocha": "2.2.43", "@types/mongodb": "2.2.13", "@types/monk": "1.0.6", - "@types/morgan": "1.7.33", + "@types/morgan": "1.7.35", "@types/ms": "0.7.30", "@types/multer": "1.3.2", "@types/node": "8.0.33", From aedadc4e6591312d575b8413718906a589ba9235 Mon Sep 17 00:00:00 2001 From: "greenkeeper[bot]" Date: Thu, 26 Oct 2017 19:35:25 +0000 Subject: [PATCH 028/327] chore(package): update @types/multer to version 1.3.5 Closes #725 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 43a015961..7e1d481a4 100644 --- a/package.json +++ b/package.json @@ -52,7 +52,7 @@ "@types/monk": "1.0.6", "@types/morgan": "1.7.33", "@types/ms": "0.7.30", - "@types/multer": "1.3.2", + "@types/multer": "1.3.5", "@types/node": "8.0.33", "@types/ratelimiter": "2.1.28", "@types/redis": "2.6.0", From 950d16476a2bda4b8a7e12cda5a5f6c699854ade Mon Sep 17 00:00:00 2001 From: "greenkeeper[bot]" Date: Sat, 28 Oct 2017 00:55:09 +0000 Subject: [PATCH 029/327] chore(package): update @types/redis to version 2.8.1 Closes #829 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 43a015961..e278cadd8 100644 --- a/package.json +++ b/package.json @@ -55,7 +55,7 @@ "@types/multer": "1.3.2", "@types/node": "8.0.33", "@types/ratelimiter": "2.1.28", - "@types/redis": "2.6.0", + "@types/redis": "2.8.1", "@types/request": "2.0.4", "@types/rimraf": "2.0.0", "@types/riot": "3.6.0", From a91293e2c1f5c29dd191b338f892e0fd4789b2c0 Mon Sep 17 00:00:00 2001 From: "greenkeeper[bot]" Date: Tue, 31 Oct 2017 17:03:16 +0000 Subject: [PATCH 030/327] fix(package): update typescript to version 2.6.1 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 7a81bed7a..4c6cfb5f3 100644 --- a/package.json +++ b/package.json @@ -149,7 +149,7 @@ "tcp-port-used": "0.1.2", "textarea-caret": "3.0.2", "ts-node": "3.3.0", - "typescript": "2.5.3", + "typescript": "2.6.1", "uuid": "3.1.0", "vhost": "3.0.2", "websocket": "1.0.25", From f7e8bfae5b0a7a58abb42fda0e3107920e3cc7da Mon Sep 17 00:00:00 2001 From: "greenkeeper[bot]" Date: Wed, 1 Nov 2017 06:55:03 +0000 Subject: [PATCH 031/327] chore(package): update awesome-typescript-loader to version 3.3.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 87db0c8e1..dd5a57015 100644 --- a/package.json +++ b/package.json @@ -64,7 +64,7 @@ "@types/webpack": "3.0.13", "@types/webpack-stream": "3.2.7", "@types/websocket": "0.0.34", - "awesome-typescript-loader": "3.2.3", + "awesome-typescript-loader": "3.3.0", "chai": "4.1.2", "chai-http": "3.0.0", "css-loader": "0.28.7", From fc44bc1398f903e23ecdc4740a66e26776fcd19c Mon Sep 17 00:00:00 2001 From: "greenkeeper[bot]" Date: Sun, 5 Nov 2017 09:08:29 +0000 Subject: [PATCH 032/327] fix(package): update cafy to version 3.1.1 Closes #857 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 051eb1cb8..995fb1bb3 100644 --- a/package.json +++ b/package.json @@ -100,7 +100,7 @@ "autwh": "0.0.1", "bcryptjs": "2.4.3", "body-parser": "1.18.2", - "cafy": "3.0.0", + "cafy": "3.1.1", "chalk": "2.1.0", "compression": "1.7.1", "cors": "2.8.4", From 973439d40248022e6a09dacc846ef62069a63228 Mon Sep 17 00:00:00 2001 From: otofune Date: Sun, 5 Nov 2017 20:55:51 +0900 Subject: [PATCH 033/327] start to improve serializers From 717a7ccb3aef35b4e43da6c43a1e230df9fe7f9f Mon Sep 17 00:00:00 2001 From: otofune Date: Sun, 5 Nov 2017 21:11:16 +0900 Subject: [PATCH 034/327] selializers - posts: unneed async-await Promise.all resolves all Promise, and selializeDriveFile returns Promise. --- src/api/serializers/post.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/api/serializers/post.ts b/src/api/serializers/post.ts index 7c3690ef7..b2c54e9df 100644 --- a/src/api/serializers/post.ts +++ b/src/api/serializers/post.ts @@ -84,8 +84,8 @@ const self = ( // Populate media if (_post.media_ids) { - _post.media = await Promise.all(_post.media_ids.map(async fileId => - await serializeDriveFile(fileId) + _post.media = await Promise.all(_post.media_ids.map(fileId => + serializeDriveFile(fileId) )); } From 2e1887d0814a2498344507c3685e5036a055f668 Mon Sep 17 00:00:00 2001 From: otofune Date: Sun, 5 Nov 2017 22:13:28 +0900 Subject: [PATCH 035/327] serializers/post - run promises in parallel now w/ opts.detail, returns my_reaction field as 'null' w/ no reaction (before: field appears w/ some reaction) --- package.json | 1 + src/api/serializers/post.ts | 122 ++++++++++++++++++++---------------- 2 files changed, 70 insertions(+), 53 deletions(-) diff --git a/package.json b/package.json index 051eb1cb8..1e6e8d813 100644 --- a/package.json +++ b/package.json @@ -95,6 +95,7 @@ "webpack": "3.8.1" }, "dependencies": { + "@prezzemolo/rap": "^0.1.0", "accesses": "2.5.0", "animejs": "2.2.0", "autwh": "0.0.1", diff --git a/src/api/serializers/post.ts b/src/api/serializers/post.ts index b2c54e9df..352932acf 100644 --- a/src/api/serializers/post.ts +++ b/src/api/serializers/post.ts @@ -12,6 +12,7 @@ import serializeChannel from './channel'; import serializeUser from './user'; import serializeDriveFile from './drive-file'; import parse from '../common/text'; +import rap from '@prezzemolo/rap' /** * Serialize a post @@ -70,21 +71,21 @@ const self = ( } // Populate user - _post.user = await serializeUser(_post.user_id, meId); + _post.user = serializeUser(_post.user_id, meId); // Populate app if (_post.app_id) { - _post.app = await serializeApp(_post.app_id); + _post.app = serializeApp(_post.app_id); } // Populate channel if (_post.channel_id) { - _post.channel = await serializeChannel(_post.channel_id); + _post.channel = serializeChannel(_post.channel_id); } // Populate media if (_post.media_ids) { - _post.media = await Promise.all(_post.media_ids.map(fileId => + _post.media = Promise.all(_post.media_ids.map(fileId => serializeDriveFile(fileId) )); } @@ -92,82 +93,97 @@ const self = ( // When requested a detailed post data if (opts.detail) { // Get previous post info - const prev = await Post.findOne({ - user_id: _post.user_id, - _id: { - $lt: id - } - }, { - fields: { - _id: true - }, - sort: { - _id: -1 - } - }); - _post.prev = prev ? prev._id : null; + _post.prev = (async () => { + const prev = Post.findOne({ + user_id: _post.user_id, + _id: { + $lt: id + } + }, { + fields: { + _id: true + }, + sort: { + _id: -1 + } + }); + return prev ? prev._id : null; + })() // Get next post info - const next = await Post.findOne({ - user_id: _post.user_id, - _id: { - $gt: id - } - }, { - fields: { - _id: true - }, - sort: { - _id: 1 - } - }); - _post.next = next ? next._id : null; + _post.next = (async () => { + const next = await Post.findOne({ + user_id: _post.user_id, + _id: { + $gt: id + } + }, { + fields: { + _id: true + }, + sort: { + _id: 1 + } + }); + return next ? next._id : null; + })() if (_post.reply_id) { // Populate reply to post - _post.reply = await self(_post.reply_id, meId, { + _post.reply = self(_post.reply_id, meId, { detail: false }); } if (_post.repost_id) { // Populate repost - _post.repost = await self(_post.repost_id, meId, { + _post.repost = self(_post.repost_id, meId, { detail: _post.text == null }); } // Poll if (meId && _post.poll) { - const vote = await Vote - .findOne({ - user_id: meId, - post_id: id - }); + _post.poll = (async (poll) => { + const vote = await Vote + .findOne({ + user_id: meId, + post_id: id + }); - if (vote != null) { - const myChoice = _post.poll.choices - .filter(c => c.id == vote.choice)[0]; + if (vote != null) { + const myChoice = poll.choices + .filter(c => c.id == vote.choice)[0]; - myChoice.is_voted = true; - } + myChoice.is_voted = true; + } + + return poll + })(_post.poll) } // Fetch my reaction if (meId) { - const reaction = await Reaction - .findOne({ - user_id: meId, - post_id: id, - deleted_at: { $exists: false } - }); + _post.my_reaction = (async () => { + const reaction = await Reaction + .findOne({ + user_id: meId, + post_id: id, + deleted_at: { $exists: false } + }); - if (reaction) { - _post.my_reaction = reaction.reaction; - } + if (reaction) { + return reaction.reaction; + } + + return null + })(); } } + // resolve promises in _post object + _post = await rap(_post) + resolve(_post); }); From da10fdcfe0909267dc11ea5aee4303e2b65bf47a Mon Sep 17 00:00:00 2001 From: otofune Date: Sun, 5 Nov 2017 22:22:49 +0900 Subject: [PATCH 036/327] serializers - user: run promises in parallel as possible --- src/api/serializers/post.ts | 2 +- src/api/serializers/user.ts | 40 +++++++++++++++++++++---------------- 2 files changed, 24 insertions(+), 18 deletions(-) diff --git a/src/api/serializers/post.ts b/src/api/serializers/post.ts index 352932acf..99e9bb667 100644 --- a/src/api/serializers/post.ts +++ b/src/api/serializers/post.ts @@ -12,7 +12,7 @@ import serializeChannel from './channel'; import serializeUser from './user'; import serializeDriveFile from './drive-file'; import parse from '../common/text'; -import rap from '@prezzemolo/rap' +import rap from '@prezzemolo/rap'; /** * Serialize a post diff --git a/src/api/serializers/user.ts b/src/api/serializers/user.ts index 3deff2d00..3527921de 100644 --- a/src/api/serializers/user.ts +++ b/src/api/serializers/user.ts @@ -8,6 +8,7 @@ import serializePost from './post'; import Following from '../models/following'; import getFriends from '../common/get-friends'; import config from '../../conf'; +import rap from '@prezzemolo/rap'; /** * Serialize a user @@ -104,26 +105,30 @@ export default ( if (meId && !meId.equals(_user.id)) { // If the user is following - const follow = await Following.findOne({ - follower_id: meId, - followee_id: _user.id, - deleted_at: { $exists: false } - }); - _user.is_following = follow !== null; + _user.is_following = (async () => { + const follow = await Following.findOne({ + follower_id: meId, + followee_id: _user.id, + deleted_at: { $exists: false } + }); + return follow !== null; + })() // If the user is followed - const follow2 = await Following.findOne({ - follower_id: _user.id, - followee_id: meId, - deleted_at: { $exists: false } - }); - _user.is_followed = follow2 !== null; + _user.is_followed = (async () => { + const follow2 = await Following.findOne({ + follower_id: _user.id, + followee_id: meId, + deleted_at: { $exists: false } + }); + return follow2 !== null; + })() } if (opts.detail) { if (_user.pinned_post_id) { // Populate pinned post - _user.pinned_post = await serializePost(_user.pinned_post_id, meId, { + _user.pinned_post = serializePost(_user.pinned_post_id, meId, { detail: true }); } @@ -132,23 +137,24 @@ export default ( const myFollowingIds = await getFriends(meId); // Get following you know count - const followingYouKnowCount = await Following.count({ + _user.following_you_know_count = Following.count({ followee_id: { $in: myFollowingIds }, follower_id: _user.id, deleted_at: { $exists: false } }); - _user.following_you_know_count = followingYouKnowCount; // Get followers you know count - const followersYouKnowCount = await Following.count({ + _user.followers_you_know_count = Following.count({ followee_id: _user.id, follower_id: { $in: myFollowingIds }, deleted_at: { $exists: false } }); - _user.followers_you_know_count = followersYouKnowCount; } } + // resolve promises in _user object + _user = await rap(_user) + resolve(_user); }); /* From 8d6cf6993931b5aa16f95aea488d090e96c1b62c Mon Sep 17 00:00:00 2001 From: otofune Date: Sun, 5 Nov 2017 22:26:16 +0900 Subject: [PATCH 037/327] follow lint --- src/api/serializers/post.ts | 12 ++++++------ src/api/serializers/user.ts | 6 +++--- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/api/serializers/post.ts b/src/api/serializers/post.ts index 99e9bb667..e1ab78435 100644 --- a/src/api/serializers/post.ts +++ b/src/api/serializers/post.ts @@ -108,7 +108,7 @@ const self = ( } }); return prev ? prev._id : null; - })() + })(); // Get next post info _post.next = (async () => { @@ -126,7 +126,7 @@ const self = ( } }); return next ? next._id : null; - })() + })(); if (_post.reply_id) { // Populate reply to post @@ -158,8 +158,8 @@ const self = ( myChoice.is_voted = true; } - return poll - })(_post.poll) + return poll; + })(_post.poll); } // Fetch my reaction @@ -176,13 +176,13 @@ const self = ( return reaction.reaction; } - return null + return null; })(); } } // resolve promises in _post object - _post = await rap(_post) + _post = await rap(_post); resolve(_post); }); diff --git a/src/api/serializers/user.ts b/src/api/serializers/user.ts index 3527921de..d00f07389 100644 --- a/src/api/serializers/user.ts +++ b/src/api/serializers/user.ts @@ -112,7 +112,7 @@ export default ( deleted_at: { $exists: false } }); return follow !== null; - })() + })(); // If the user is followed _user.is_followed = (async () => { @@ -122,7 +122,7 @@ export default ( deleted_at: { $exists: false } }); return follow2 !== null; - })() + })(); } if (opts.detail) { @@ -153,7 +153,7 @@ export default ( } // resolve promises in _user object - _user = await rap(_user) + _user = await rap(_user); resolve(_user); }); From a0817c12ad30dd991c32cb427f4e4f227989e787 Mon Sep 17 00:00:00 2001 From: otofune Date: Sun, 5 Nov 2017 22:29:58 +0900 Subject: [PATCH 038/327] remove ^ from @prezzemolo/rap dependency --- package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 1e6e8d813..c3a093420 100644 --- a/package.json +++ b/package.json @@ -18,7 +18,7 @@ "clean": "gulp clean", "cleanall": "gulp cleanall", "lint": "gulp lint", - "test": "gulp test" + "test": "gulp test" }, "devDependencies": { "@types/bcryptjs": "2.4.0", @@ -95,7 +95,7 @@ "webpack": "3.8.1" }, "dependencies": { - "@prezzemolo/rap": "^0.1.0", + "@prezzemolo/rap": "0.1.0", "accesses": "2.5.0", "animejs": "2.2.0", "autwh": "0.0.1", From 5071de551125ab208c5ce1bb43a80b29030b4bd4 Mon Sep 17 00:00:00 2001 From: otofune Date: Sun, 5 Nov 2017 22:37:00 +0900 Subject: [PATCH 039/327] update @prezzemolo/rap to 0.1.1 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index c3a093420..27e292cc1 100644 --- a/package.json +++ b/package.json @@ -95,7 +95,7 @@ "webpack": "3.8.1" }, "dependencies": { - "@prezzemolo/rap": "0.1.0", + "@prezzemolo/rap": "0.1.1", "accesses": "2.5.0", "animejs": "2.2.0", "autwh": "0.0.1", From 5bfd7562a6cb3aa34f4f1a06185bce68adb24145 Mon Sep 17 00:00:00 2001 From: otofune Date: Sun, 5 Nov 2017 22:47:04 +0900 Subject: [PATCH 040/327] update @prezzemolo/rap to 0.1.2 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 27e292cc1..6ea91a7f5 100644 --- a/package.json +++ b/package.json @@ -95,7 +95,7 @@ "webpack": "3.8.1" }, "dependencies": { - "@prezzemolo/rap": "0.1.1", + "@prezzemolo/rap": "0.1.2", "accesses": "2.5.0", "animejs": "2.2.0", "autwh": "0.0.1", From a994888d2cca204f1ad5f3adc5da860a3e2841d6 Mon Sep 17 00:00:00 2001 From: "greenkeeper[bot]" Date: Sun, 5 Nov 2017 20:40:07 +0000 Subject: [PATCH 041/327] fix(package): update riot to version 3.7.4 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 051eb1cb8..7a7cd1c09 100644 --- a/package.json +++ b/package.json @@ -140,7 +140,7 @@ "redis": "2.8.0", "request": "2.83.0", "rimraf": "2.6.2", - "riot": "3.7.3", + "riot": "3.7.4", "rndstr": "1.0.0", "s-age": "1.1.0", "serve-favicon": "2.4.5", From 22714b05b6f14d1a6cf18776e4e7dbbf8c75c2cf Mon Sep 17 00:00:00 2001 From: otofune Date: Mon, 6 Nov 2017 14:37:00 +0900 Subject: [PATCH 042/327] support GridFS --- src/api/common/add-file-to-drive.ts | 37 ++++++++++++++++++----------- src/api/models/drive-file.ts | 15 ++++++++++-- src/db/mongodb.ts | 35 +++++++++++++++++++++++---- 3 files changed, 67 insertions(+), 20 deletions(-) diff --git a/src/api/common/add-file-to-drive.ts b/src/api/common/add-file-to-drive.ts index 714eeb520..f48f0cbcf 100644 --- a/src/api/common/add-file-to-drive.ts +++ b/src/api/common/add-file-to-drive.ts @@ -4,14 +4,27 @@ import * as gm from 'gm'; import * as debug from 'debug'; import fileType = require('file-type'); import prominence = require('prominence'); -import DriveFile from '../models/drive-file'; +import DriveFile, { getGridFSBucket } from '../models/drive-file'; import DriveFolder from '../models/drive-folder'; import serialize from '../serializers/drive-file'; import event from '../event'; import config from '../../conf'; +import { Duplex } from 'stream'; const log = debug('misskey:register-drive-file'); +const addToGridFS = (name, binary, metadata): Promise => new Promise(async (resolve, reject) => { + const dataStream = new Duplex() + dataStream.push(binary) + dataStream.push(null) + + const bucket = await getGridFSBucket() + const writeStream = bucket.openUploadStream(name, { metadata }) + writeStream.once('finish', (doc) => { resolve(doc) }) + writeStream.on('error', reject) + dataStream.pipe(writeStream) +}) + /** * Add file to drive * @@ -58,7 +71,7 @@ export default ( // Generate hash const hash = crypto - .createHash('sha256') + .createHash('md5') .update(data) .digest('hex') as string; @@ -67,8 +80,10 @@ export default ( if (!force) { // Check if there is a file with the same hash const much = await DriveFile.findOne({ - user_id: user._id, - hash: hash + md5: hash, + metadata: { + user_id: user._id + } }); if (much !== null) { @@ -82,13 +97,13 @@ export default ( // Calculate drive usage const usage = ((await DriveFile .aggregate([ - { $match: { user_id: user._id } }, + { $match: { metadata: { user_id: user._id } } }, { $project: { - datasize: true + length: true }}, { $group: { _id: null, - usage: { $sum: '$datasize' } + usage: { $sum: '$length' } }} ]))[0] || { usage: 0 @@ -131,21 +146,15 @@ export default ( } // Create DriveFile document - const file = await DriveFile.insert({ - created_at: new Date(), + const file = await addToGridFS(`${user._id}/${name}`, data, { user_id: user._id, folder_id: folder !== null ? folder._id : null, - data: data, - datasize: size, type: mime, name: name, comment: comment, - hash: hash, properties: properties }); - delete file.data; - log(`drive file has been created ${file._id}`); resolve(file); diff --git a/src/api/models/drive-file.ts b/src/api/models/drive-file.ts index 8d158cf56..79a87f657 100644 --- a/src/api/models/drive-file.ts +++ b/src/api/models/drive-file.ts @@ -1,11 +1,22 @@ -import db from '../../db/mongodb'; +import * as mongodb from 'mongodb'; +import monkDb, { nativeDbConn } from '../../db/mongodb'; -const collection = db.get('drive_files'); +const collection = monkDb.get('drive_files.files'); (collection as any).createIndex('hash'); // fuck type definition export default collection as any; // fuck type definition +const getGridFSBucket = async (): Promise => { + const db = await nativeDbConn() + const bucket = new mongodb.GridFSBucket(db, { + bucketName: 'drive_files' + }) + return bucket +} + +export { getGridFSBucket } + export function validateFileName(name: string): boolean { return ( (name.trim().length > 0) && diff --git a/src/db/mongodb.ts b/src/db/mongodb.ts index 6ee7f4534..75f1a1d3c 100644 --- a/src/db/mongodb.ts +++ b/src/db/mongodb.ts @@ -1,11 +1,38 @@ -import * as mongo from 'monk'; - import config from '../conf'; const uri = config.mongodb.user && config.mongodb.pass - ? `mongodb://${config.mongodb.user}:${config.mongodb.pass}@${config.mongodb.host}:${config.mongodb.port}/${config.mongodb.db}` - : `mongodb://${config.mongodb.host}:${config.mongodb.port}/${config.mongodb.db}`; +? `mongodb://${config.mongodb.user}:${config.mongodb.pass}@${config.mongodb.host}:${config.mongodb.port}/${config.mongodb.db}` +: `mongodb://${config.mongodb.host}:${config.mongodb.port}/${config.mongodb.db}`; + +/** + * monk + */ +import * as mongo from 'monk'; const db = mongo(uri); export default db; + +/** + * MongoDB native module (officialy) + */ +import * as mongodb from 'mongodb' + +let mdb: mongodb.Db; + +const nativeDbConn = async (): Promise => { + if (mdb) return mdb; + + const db = await ((): Promise => new Promise((resolve, reject) => { + mongodb.MongoClient.connect(uri, (e, db) => { + if (e) return reject(e) + resolve(db) + }) + }))() + + mdb = db + + return db +} + +export { nativeDbConn } From d25a71a4de124dd11b3031239e4b728fb5610465 Mon Sep 17 00:00:00 2001 From: otofune Date: Mon, 6 Nov 2017 15:18:45 +0900 Subject: [PATCH 043/327] migration to GridFS's DriveFile --- src/api/common/add-file-to-drive.ts | 1 + src/api/endpoints/drive.ts | 6 ++-- src/api/endpoints/drive/files.ts | 9 +++-- src/api/endpoints/drive/files/find.ts | 10 +++--- src/api/endpoints/drive/files/show.ts | 6 ++-- src/api/endpoints/drive/files/update.ts | 31 +++++++++-------- .../endpoints/messaging/messages/create.ts | 6 ++-- src/api/endpoints/posts/create.ts | 6 ++-- src/api/endpoints/posts/timeline.ts | 24 +++++++------- src/api/serializers/drive-file.ts | 33 ++++++++----------- src/api/serializers/drive-folder.ts | 4 ++- 11 files changed, 66 insertions(+), 70 deletions(-) diff --git a/src/api/common/add-file-to-drive.ts b/src/api/common/add-file-to-drive.ts index f48f0cbcf..376c470e9 100644 --- a/src/api/common/add-file-to-drive.ts +++ b/src/api/common/add-file-to-drive.ts @@ -154,6 +154,7 @@ export default ( comment: comment, properties: properties }); + console.dir(file) log(`drive file has been created ${file._id}`); diff --git a/src/api/endpoints/drive.ts b/src/api/endpoints/drive.ts index 41ad6301d..b9c4e3e50 100644 --- a/src/api/endpoints/drive.ts +++ b/src/api/endpoints/drive.ts @@ -14,16 +14,16 @@ module.exports = (params, user) => new Promise(async (res, rej) => { // Calculate drive usage const usage = ((await DriveFile .aggregate([ - { $match: { user_id: user._id } }, + { $match: { metadata: { user_id: user._id } } }, { $project: { - datasize: true + length: true } }, { $group: { _id: null, - usage: { $sum: '$datasize' } + usage: { $sum: '$length' } } } ]))[0] || { diff --git a/src/api/endpoints/drive/files.ts b/src/api/endpoints/drive/files.ts index a68ae3481..eb0bfe6ba 100644 --- a/src/api/endpoints/drive/files.ts +++ b/src/api/endpoints/drive/files.ts @@ -40,8 +40,10 @@ module.exports = (params, user, app) => new Promise(async (res, rej) => { _id: -1 }; const query = { - user_id: user._id, - folder_id: folderId + metadata: { + user_id: user._id, + folder_id: folderId + } } as any; if (sinceId) { sort._id = 1; @@ -57,9 +59,6 @@ module.exports = (params, user, app) => new Promise(async (res, rej) => { // Issue query const files = await DriveFile .find(query, { - fields: { - data: false - }, limit: limit, sort: sort }); diff --git a/src/api/endpoints/drive/files/find.ts b/src/api/endpoints/drive/files/find.ts index cd0b33f2c..255faf94e 100644 --- a/src/api/endpoints/drive/files/find.ts +++ b/src/api/endpoints/drive/files/find.ts @@ -24,12 +24,10 @@ module.exports = (params, user) => new Promise(async (res, rej) => { // Issue query const files = await DriveFile .find({ - name: name, - user_id: user._id, - folder_id: folderId - }, { - fields: { - data: false + metadata: { + name: name, + user_id: user._id, + folder_id: folderId } }); diff --git a/src/api/endpoints/drive/files/show.ts b/src/api/endpoints/drive/files/show.ts index 8dbc297e4..9135a04c5 100644 --- a/src/api/endpoints/drive/files/show.ts +++ b/src/api/endpoints/drive/files/show.ts @@ -21,10 +21,8 @@ module.exports = (params, user) => new Promise(async (res, rej) => { const file = await DriveFile .findOne({ _id: fileId, - user_id: user._id - }, { - fields: { - data: false + metadata: { + user_id: user._id } }); diff --git a/src/api/endpoints/drive/files/update.ts b/src/api/endpoints/drive/files/update.ts index 1cfbdd8f0..c4d267368 100644 --- a/src/api/endpoints/drive/files/update.ts +++ b/src/api/endpoints/drive/files/update.ts @@ -20,25 +20,29 @@ module.exports = (params, user) => new Promise(async (res, rej) => { const [fileId, fileIdErr] = $(params.file_id).id().$; if (fileIdErr) return rej('invalid file_id param'); + console.dir(user) + // Fetch file const file = await DriveFile .findOne({ _id: fileId, - user_id: user._id - }, { - fields: { - data: false + metadata: { + user_id: user._id } }); + console.dir(file) + if (file === null) { return rej('file-not-found'); } + const updateQuery: any = {} + // Get 'name' parameter const [name, nameErr] = $(params.name).optional.string().pipe(validateFileName).$; if (nameErr) return rej('invalid name param'); - if (name) file.name = name; + if (name) updateQuery.name = name; // Get 'folder_id' parameter const [folderId, folderIdErr] = $(params.folder_id).optional.nullable.id().$; @@ -46,7 +50,7 @@ module.exports = (params, user) => new Promise(async (res, rej) => { if (folderId !== undefined) { if (folderId === null) { - file.folder_id = null; + updateQuery.folder_id = null; } else { // Fetch folder const folder = await DriveFolder @@ -59,19 +63,20 @@ module.exports = (params, user) => new Promise(async (res, rej) => { return rej('folder-not-found'); } - file.folder_id = folder._id; + updateQuery.folder_id = folder._id; } } - DriveFile.update(file._id, { - $set: { - name: file.name, - folder_id: file.folder_id - } + const updated = await DriveFile.update(file._id, { + $set: { metadata: updateQuery } }); + console.dir(updated) + // Serialize - const fileObj = await serialize(file); + const fileObj = await serialize(updated); + + console.dir(fileObj) // Response res(fileObj); diff --git a/src/api/endpoints/messaging/messages/create.ts b/src/api/endpoints/messaging/messages/create.ts index 8af55d850..1d186268f 100644 --- a/src/api/endpoints/messaging/messages/create.ts +++ b/src/api/endpoints/messaging/messages/create.ts @@ -54,9 +54,9 @@ module.exports = (params, user) => new Promise(async (res, rej) => { if (fileId !== undefined) { file = await DriveFile.findOne({ _id: fileId, - user_id: user._id - }, { - data: false + metadata: { + user_id: user._id + } }); if (file === null) { diff --git a/src/api/endpoints/posts/create.ts b/src/api/endpoints/posts/create.ts index f982b9ee9..150763977 100644 --- a/src/api/endpoints/posts/create.ts +++ b/src/api/endpoints/posts/create.ts @@ -44,9 +44,9 @@ module.exports = (params, user: IUser, app) => new Promise(async (res, rej) => { // SELECT _id const entity = await DriveFile.findOne({ _id: mediaId, - user_id: user._id - }, { - _id: true + metadata: { + user_id: user._id + } }); if (entity === null) { diff --git a/src/api/endpoints/posts/timeline.ts b/src/api/endpoints/posts/timeline.ts index aa5aff5ba..496de62b6 100644 --- a/src/api/endpoints/posts/timeline.ts +++ b/src/api/endpoints/posts/timeline.ts @@ -2,6 +2,7 @@ * Module dependencies */ import $ from 'cafy'; +import rap from '@prezzemolo/rap'; import Post from '../../models/post'; import ChannelWatching from '../../models/channel-watching'; import getFriends from '../../common/get-friends'; @@ -33,14 +34,15 @@ module.exports = (params, user, app) => new Promise(async (res, rej) => { return rej('cannot set since_id and max_id'); } - // ID list of the user itself and other users who the user follows - const followingIds = await getFriends(user._id); - - // Watchしているチャンネルを取得 - const watches = await ChannelWatching.find({ - user_id: user._id, - // 削除されたドキュメントは除く - deleted_at: { $exists: false } + const { followingIds, watchChannelIds } = await rap({ + // ID list of the user itself and other users who the user follows + followingIds: getFriends(user._id), + // Watchしているチャンネルを取得 + watchChannelIds: ChannelWatching.find({ + user_id: user._id, + // 削除されたドキュメントは除く + deleted_at: { $exists: false } + }).then(watches => watches.map(w => w.channel_id)) }); //#region Construct query @@ -65,7 +67,7 @@ module.exports = (params, user, app) => new Promise(async (res, rej) => { }, { // Watchしているチャンネルへの投稿 channel_id: { - $in: watches.map(w => w.channel_id) + $in: watchChannelIds } }] } as any; @@ -90,7 +92,5 @@ module.exports = (params, user, app) => new Promise(async (res, rej) => { }); // Serialize - res(await Promise.all(timeline.map(async post => - await serialize(post, user) - ))); + res(Promise.all(timeline.map(post => serialize(post, user)))); }); diff --git a/src/api/serializers/drive-file.ts b/src/api/serializers/drive-file.ts index b4e2ab064..4c750f4c6 100644 --- a/src/api/serializers/drive-file.ts +++ b/src/api/serializers/drive-file.ts @@ -31,44 +31,37 @@ export default ( if (mongo.ObjectID.prototype.isPrototypeOf(file)) { _file = await DriveFile.findOne({ _id: file - }, { - fields: { - data: false - } - }); + }); } else if (typeof file === 'string') { _file = await DriveFile.findOne({ _id: new mongo.ObjectID(file) - }, { - fields: { - data: false - } - }); + }); } else { _file = deepcopy(file); } - // Rename _id to id - _file.id = _file._id; - delete _file._id; + // rendered target + let _target: any = {}; - delete _file.data; + _target.id = _file._id; - _file.url = `${config.drive_url}/${_file.id}/${encodeURIComponent(_file.name)}`; + _target = Object.assign(_target, _file.metadata); - if (opts.detail && _file.folder_id) { + _target.url = `${config.drive_url}/${_target.id}/${encodeURIComponent(_target.name)}`; + + if (opts.detail && _target.folder_id) { // Populate folder - _file.folder = await serializeDriveFolder(_file.folder_id, { + _target.folder = await serializeDriveFolder(_target.folder_id, { detail: true }); } - if (opts.detail && _file.tags) { + if (opts.detail && _target.tags) { // Populate tags - _file.tags = await _file.tags.map(async (tag: any) => + _target.tags = await _target.tags.map(async (tag: any) => await serializeDriveTag(tag) ); } - resolve(_file); + resolve(_target); }); diff --git a/src/api/serializers/drive-folder.ts b/src/api/serializers/drive-folder.ts index a42846410..3b5f61aee 100644 --- a/src/api/serializers/drive-folder.ts +++ b/src/api/serializers/drive-folder.ts @@ -44,7 +44,9 @@ const self = ( }); const childFilesCount = await DriveFile.count({ - folder_id: _folder.id + metadata: { + folder_id: _folder.id + } }); _folder.folders_count = childFoldersCount; From 0e9e7c9ac668ed74ccc3999cc69dc0f70989df9d Mon Sep 17 00:00:00 2001 From: otofune Date: Mon, 6 Nov 2017 15:27:16 +0900 Subject: [PATCH 044/327] serializers - drive-file: add created_at field by uploadedDate --- src/api/serializers/drive-file.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/api/serializers/drive-file.ts b/src/api/serializers/drive-file.ts index 4c750f4c6..f98cdaa59 100644 --- a/src/api/serializers/drive-file.ts +++ b/src/api/serializers/drive-file.ts @@ -44,6 +44,7 @@ export default ( let _target: any = {}; _target.id = _file._id; + _target.created_at = _file.uploadDate _target = Object.assign(_target, _file.metadata); From 7cc99d2e742a9bb34679ace89aa84d974ee2d1cc Mon Sep 17 00:00:00 2001 From: otofune Date: Mon, 6 Nov 2017 15:35:20 +0900 Subject: [PATCH 045/327] fileserver - support DriveFile w/ GridFS --- src/file/server.ts | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/src/file/server.ts b/src/file/server.ts index ee67cf786..bd29e13c5 100644 --- a/src/file/server.ts +++ b/src/file/server.ts @@ -9,7 +9,7 @@ import * as cors from 'cors'; import * as mongodb from 'mongodb'; import * as gm from 'gm'; -import File from '../api/models/drive-file'; +import DriveFile, { getGridFSBucket } from '../api/models/drive-file'; /** * Init app @@ -97,17 +97,28 @@ app.get('/:id', async (req, res) => { return; } - const file = await File.findOne({ _id: new mongodb.ObjectID(req.params.id) }); + const fileId = new mongodb.ObjectID(req.params.id) + const file = await DriveFile.findOne({ _id: fileId }); if (file == null) { res.status(404).sendFile(`${__dirname} / assets / dummy.png`); return; - } else if (file.data == null) { - res.sendStatus(400); - return; } - send(file.data.buffer, file.type, req, res); + const bucket = await getGridFSBucket() + + const buffer = await ((id): Promise => new Promise((resolve, reject) => { + const chunks = [] + const readableStream = bucket.openDownloadStream(id) + readableStream.on('data', chunk => { + chunks.push(chunk); + }) + readableStream.on('end', () => { + resolve(Buffer.concat(chunks)) + }) + }))(fileId) + + send(buffer, file.metadata.type, req, res); }); app.get('/:id/:name', async (req, res) => { From f9b4c04b3b9d6e54dbed3a6f514cf77878940e96 Mon Sep 17 00:00:00 2001 From: otofune Date: Mon, 6 Nov 2017 15:37:04 +0900 Subject: [PATCH 046/327] fileserver - fix dummy path --- src/file/server.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/file/server.ts b/src/file/server.ts index bd29e13c5..068e88546 100644 --- a/src/file/server.ts +++ b/src/file/server.ts @@ -101,7 +101,7 @@ app.get('/:id', async (req, res) => { const file = await DriveFile.findOne({ _id: fileId }); if (file == null) { - res.status(404).sendFile(`${__dirname} / assets / dummy.png`); + res.status(404).sendFile(`${__dirname}/assets/dummy.png`); return; } From 650eab96e7ff0a203edfa4174299aa3a2f99b2b6 Mon Sep 17 00:00:00 2001 From: otofune Date: Mon, 6 Nov 2017 15:39:16 +0900 Subject: [PATCH 047/327] file-server - support new DriveFile w/ GridFS on '/:id/:name' --- src/file/server.ts | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/src/file/server.ts b/src/file/server.ts index 068e88546..f38599b89 100644 --- a/src/file/server.ts +++ b/src/file/server.ts @@ -128,17 +128,28 @@ app.get('/:id/:name', async (req, res) => { return; } - const file = await File.findOne({ _id: new mongodb.ObjectID(req.params.id) }); + const fileId = new mongodb.ObjectID(req.params.id) + const file = await DriveFile.findOne({ _id: fileId }); if (file == null) { res.status(404).sendFile(`${__dirname}/assets/dummy.png`); return; - } else if (file.data == null) { - res.sendStatus(400); - return; } - send(file.data.buffer, file.type, req, res); + const bucket = await getGridFSBucket() + + const buffer = await ((id): Promise => new Promise((resolve, reject) => { + const chunks = [] + const readableStream = bucket.openDownloadStream(id) + readableStream.on('data', chunk => { + chunks.push(chunk); + }) + readableStream.on('end', () => { + resolve(Buffer.concat(chunks)) + }) + }))(fileId) + + send(buffer, file.metadata.type, req, res); }); module.exports = app; From cd12c7fced5d2a0894bff6291091dcc1fc7e35e0 Mon Sep 17 00:00:00 2001 From: otofune Date: Mon, 6 Nov 2017 15:45:21 +0900 Subject: [PATCH 048/327] fix timeline --- src/api/endpoints/posts/timeline.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/api/endpoints/posts/timeline.ts b/src/api/endpoints/posts/timeline.ts index 496de62b6..19578e59b 100644 --- a/src/api/endpoints/posts/timeline.ts +++ b/src/api/endpoints/posts/timeline.ts @@ -92,5 +92,5 @@ module.exports = (params, user, app) => new Promise(async (res, rej) => { }); // Serialize - res(Promise.all(timeline.map(post => serialize(post, user)))); + res(await Promise.all(timeline.map(post => serialize(post, user)))); }); From 67a2e70d6387b0f26306a45bb4f3a274b145ddf4 Mon Sep 17 00:00:00 2001 From: otofune Date: Mon, 6 Nov 2017 15:52:09 +0900 Subject: [PATCH 049/327] serializers - posts: no need Promise wrapping --- src/api/serializers/post.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/api/serializers/post.ts b/src/api/serializers/post.ts index e1ab78435..d1dcb6600 100644 --- a/src/api/serializers/post.ts +++ b/src/api/serializers/post.ts @@ -22,13 +22,13 @@ import rap from '@prezzemolo/rap'; * @param options? serialize options * @return response */ -const self = ( +const self = async ( post: string | mongo.ObjectID | IPost, me?: string | mongo.ObjectID | IUser, options?: { detail: boolean } -) => new Promise(async (resolve, reject) => { +) => { const opts = options || { detail: true, }; @@ -184,7 +184,7 @@ const self = ( // resolve promises in _post object _post = await rap(_post); - resolve(_post); -}); + return _post; +}; export default self; From 8dc272beba5e05e51a01495542092584d65769e6 Mon Sep 17 00:00:00 2001 From: otofune Date: Mon, 6 Nov 2017 15:55:47 +0900 Subject: [PATCH 050/327] api - endpoint:timeline: unneed promise wrapping --- src/api/endpoints/posts/timeline.ts | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/api/endpoints/posts/timeline.ts b/src/api/endpoints/posts/timeline.ts index 19578e59b..978825a10 100644 --- a/src/api/endpoints/posts/timeline.ts +++ b/src/api/endpoints/posts/timeline.ts @@ -16,22 +16,22 @@ import serialize from '../../serializers/post'; * @param {any} app * @return {Promise} */ -module.exports = (params, user, app) => new Promise(async (res, rej) => { +module.exports = async (params, user, app) => { // Get 'limit' parameter const [limit = 10, limitErr] = $(params.limit).optional.number().range(1, 100).$; - if (limitErr) return rej('invalid limit param'); + if (limitErr) throw 'invalid limit param'; // Get 'since_id' parameter const [sinceId, sinceIdErr] = $(params.since_id).optional.id().$; - if (sinceIdErr) return rej('invalid since_id param'); + if (sinceIdErr) throw 'invalid since_id param'; // Get 'max_id' parameter const [maxId, maxIdErr] = $(params.max_id).optional.id().$; - if (maxIdErr) return rej('invalid max_id param'); + if (maxIdErr) throw 'invalid max_id param'; // Check if both of since_id and max_id is specified if (sinceId && maxId) { - return rej('cannot set since_id and max_id'); + throw 'cannot set since_id and max_id'; } const { followingIds, watchChannelIds } = await rap({ @@ -92,5 +92,6 @@ module.exports = (params, user, app) => new Promise(async (res, rej) => { }); // Serialize - res(await Promise.all(timeline.map(post => serialize(post, user)))); -}); + const _timeline = await Promise.all(timeline.map(post => serialize(post, user))) + return _timeline +}; From c46f6db19cd93915ba9ab9b225731995d2e1bf2e Mon Sep 17 00:00:00 2001 From: otofune Date: Mon, 6 Nov 2017 15:58:39 +0900 Subject: [PATCH 051/327] serializers - posts: fix awaiting --- src/api/serializers/post.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/api/serializers/post.ts b/src/api/serializers/post.ts index d1dcb6600..5788b226f 100644 --- a/src/api/serializers/post.ts +++ b/src/api/serializers/post.ts @@ -94,7 +94,7 @@ const self = async ( if (opts.detail) { // Get previous post info _post.prev = (async () => { - const prev = Post.findOne({ + const prev = await Post.findOne({ user_id: _post.user_id, _id: { $lt: id From 267cec0da1ad63bd3f00c9ced8fc648df6e7cd36 Mon Sep 17 00:00:00 2001 From: otofune Date: Mon, 6 Nov 2017 16:09:51 +0900 Subject: [PATCH 052/327] fix --- src/api/endpoints/drive/files.ts | 18 +++++++++--------- src/api/endpoints/drive/files/show.ts | 14 ++++++++------ src/api/endpoints/drive/folders/find.ts | 3 +-- src/api/serializers/drive-file.ts | 2 ++ 4 files changed, 20 insertions(+), 17 deletions(-) diff --git a/src/api/endpoints/drive/files.ts b/src/api/endpoints/drive/files.ts index eb0bfe6ba..41687c499 100644 --- a/src/api/endpoints/drive/files.ts +++ b/src/api/endpoints/drive/files.ts @@ -13,27 +13,27 @@ import serialize from '../../serializers/drive-file'; * @param {any} app * @return {Promise} */ -module.exports = (params, user, app) => new Promise(async (res, rej) => { +module.exports = async (params, user, app) => { // Get 'limit' parameter const [limit = 10, limitErr] = $(params.limit).optional.number().range(1, 100).$; - if (limitErr) return rej('invalid limit param'); + if (limitErr) throw 'invalid limit param'; // Get 'since_id' parameter const [sinceId, sinceIdErr] = $(params.since_id).optional.id().$; - if (sinceIdErr) return rej('invalid since_id param'); + if (sinceIdErr) throw 'invalid since_id param'; // Get 'max_id' parameter const [maxId, maxIdErr] = $(params.max_id).optional.id().$; - if (maxIdErr) return rej('invalid max_id param'); + if (maxIdErr) throw 'invalid max_id param'; // Check if both of since_id and max_id is specified if (sinceId && maxId) { - return rej('cannot set since_id and max_id'); + throw 'cannot set since_id and max_id'; } // Get 'folder_id' parameter const [folderId = null, folderIdErr] = $(params.folder_id).optional.nullable.id().$; - if (folderIdErr) return rej('invalid folder_id param'); + if (folderIdErr) throw 'invalid folder_id param'; // Construct query const sort = { @@ -64,6 +64,6 @@ module.exports = (params, user, app) => new Promise(async (res, rej) => { }); // Serialize - res(await Promise.all(files.map(async file => - await serialize(file)))); -}); + const _files = await Promise.all(files.map(file => serialize(file))); + return _files +}; diff --git a/src/api/endpoints/drive/files/show.ts b/src/api/endpoints/drive/files/show.ts index 9135a04c5..883034600 100644 --- a/src/api/endpoints/drive/files/show.ts +++ b/src/api/endpoints/drive/files/show.ts @@ -12,10 +12,10 @@ import serialize from '../../../serializers/drive-file'; * @param {any} user * @return {Promise} */ -module.exports = (params, user) => new Promise(async (res, rej) => { +module.exports = async (params, user) => { // Get 'file_id' parameter const [fileId, fileIdErr] = $(params.file_id).id().$; - if (fileIdErr) return rej('invalid file_id param'); + if (fileIdErr) throw 'invalid file_id param'; // Fetch file const file = await DriveFile @@ -27,11 +27,13 @@ module.exports = (params, user) => new Promise(async (res, rej) => { }); if (file === null) { - return rej('file-not-found'); + throw 'file-not-found'; } // Serialize - res(await serialize(file, { + const _file = await serialize(file, { detail: true - })); -}); + }); + + return _file +}; diff --git a/src/api/endpoints/drive/folders/find.ts b/src/api/endpoints/drive/folders/find.ts index cdf055839..a5eb8e015 100644 --- a/src/api/endpoints/drive/folders/find.ts +++ b/src/api/endpoints/drive/folders/find.ts @@ -30,6 +30,5 @@ module.exports = (params, user) => new Promise(async (res, rej) => { }); // Serialize - res(await Promise.all(folders.map(async folder => - await serialize(folder)))); + res(await Promise.all(folders.map(folder => serialize(folder)))); }); diff --git a/src/api/serializers/drive-file.ts b/src/api/serializers/drive-file.ts index f98cdaa59..9858c3b3c 100644 --- a/src/api/serializers/drive-file.ts +++ b/src/api/serializers/drive-file.ts @@ -25,6 +25,8 @@ export default ( detail: false }, options); + if (!file) return reject('invalid file arg.') + let _file: any; // Populate the file if 'file' is ID From 50b56803896827ba76e9e88cd882687fa38aa722 Mon Sep 17 00:00:00 2001 From: otofune Date: Mon, 6 Nov 2017 16:11:24 +0900 Subject: [PATCH 053/327] fix --- src/api/serializers/drive-file.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/api/serializers/drive-file.ts b/src/api/serializers/drive-file.ts index 9858c3b3c..e749f8038 100644 --- a/src/api/serializers/drive-file.ts +++ b/src/api/serializers/drive-file.ts @@ -25,8 +25,6 @@ export default ( detail: false }, options); - if (!file) return reject('invalid file arg.') - let _file: any; // Populate the file if 'file' is ID @@ -42,6 +40,8 @@ export default ( _file = deepcopy(file); } + if (!_file) return reject('invalid file arg.') + // rendered target let _target: any = {}; From 02429277ff6f7c169c9a95d5cacdf1d6a88928c9 Mon Sep 17 00:00:00 2001 From: otofune Date: Mon, 6 Nov 2017 16:22:18 +0900 Subject: [PATCH 054/327] =?UTF-8?q?MongoDB=E3=81=AE=E9=9A=8E=E5=B1=A4?= =?UTF-8?q?=E6=A7=8B=E9=80=A0=E6=A4=9C=E7=B4=A2=E3=81=AB=E9=96=A2=E3=81=99?= =?UTF-8?q?=E3=82=8B=E6=80=9D=E3=81=84=E9=81=95=E3=81=84=E3=81=AE=E4=BF=AE?= =?UTF-8?q?=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api/endpoints/drive.ts | 2 +- src/api/endpoints/drive/files.ts | 6 ++---- src/api/endpoints/drive/files/find.ts | 8 +++----- src/api/endpoints/drive/files/show.ts | 4 +--- src/api/endpoints/drive/files/update.ts | 19 +++++-------------- .../endpoints/messaging/messages/create.ts | 4 +--- src/api/endpoints/posts/create.ts | 4 +--- src/api/serializers/drive-folder.ts | 4 +--- 8 files changed, 15 insertions(+), 36 deletions(-) diff --git a/src/api/endpoints/drive.ts b/src/api/endpoints/drive.ts index b9c4e3e50..d92473633 100644 --- a/src/api/endpoints/drive.ts +++ b/src/api/endpoints/drive.ts @@ -14,7 +14,7 @@ module.exports = (params, user) => new Promise(async (res, rej) => { // Calculate drive usage const usage = ((await DriveFile .aggregate([ - { $match: { metadata: { user_id: user._id } } }, + { $match: { 'metadata.user_id': user._id } }, { $project: { length: true diff --git a/src/api/endpoints/drive/files.ts b/src/api/endpoints/drive/files.ts index 41687c499..035916b30 100644 --- a/src/api/endpoints/drive/files.ts +++ b/src/api/endpoints/drive/files.ts @@ -40,10 +40,8 @@ module.exports = async (params, user, app) => { _id: -1 }; const query = { - metadata: { - user_id: user._id, - folder_id: folderId - } + 'metadata.user_id': user._id, + 'metadata.folder_id': folderId } as any; if (sinceId) { sort._id = 1; diff --git a/src/api/endpoints/drive/files/find.ts b/src/api/endpoints/drive/files/find.ts index 255faf94e..1c818131d 100644 --- a/src/api/endpoints/drive/files/find.ts +++ b/src/api/endpoints/drive/files/find.ts @@ -24,11 +24,9 @@ module.exports = (params, user) => new Promise(async (res, rej) => { // Issue query const files = await DriveFile .find({ - metadata: { - name: name, - user_id: user._id, - folder_id: folderId - } + 'metadata.name': name, + 'metadata.user_id': user._id, + 'metadata.folder_id': folderId }); // Serialize diff --git a/src/api/endpoints/drive/files/show.ts b/src/api/endpoints/drive/files/show.ts index 883034600..0a19b1993 100644 --- a/src/api/endpoints/drive/files/show.ts +++ b/src/api/endpoints/drive/files/show.ts @@ -21,9 +21,7 @@ module.exports = async (params, user) => { const file = await DriveFile .findOne({ _id: fileId, - metadata: { - user_id: user._id - } + 'metadata.user_id': user._id }); if (file === null) { diff --git a/src/api/endpoints/drive/files/update.ts b/src/api/endpoints/drive/files/update.ts index c4d267368..7a6d2562f 100644 --- a/src/api/endpoints/drive/files/update.ts +++ b/src/api/endpoints/drive/files/update.ts @@ -20,19 +20,14 @@ module.exports = (params, user) => new Promise(async (res, rej) => { const [fileId, fileIdErr] = $(params.file_id).id().$; if (fileIdErr) return rej('invalid file_id param'); - console.dir(user) // Fetch file const file = await DriveFile .findOne({ _id: fileId, - metadata: { - user_id: user._id - } + 'metadata.user_id': user._id }); - console.dir(file) - if (file === null) { return rej('file-not-found'); } @@ -42,7 +37,7 @@ module.exports = (params, user) => new Promise(async (res, rej) => { // Get 'name' parameter const [name, nameErr] = $(params.name).optional.string().pipe(validateFileName).$; if (nameErr) return rej('invalid name param'); - if (name) updateQuery.name = name; + if (name) updateQuery['metadata.name'] = name; // Get 'folder_id' parameter const [folderId, folderIdErr] = $(params.folder_id).optional.nullable.id().$; @@ -50,7 +45,7 @@ module.exports = (params, user) => new Promise(async (res, rej) => { if (folderId !== undefined) { if (folderId === null) { - updateQuery.folder_id = null; + updateQuery['metadata.folder_id'] = null; } else { // Fetch folder const folder = await DriveFolder @@ -63,21 +58,17 @@ module.exports = (params, user) => new Promise(async (res, rej) => { return rej('folder-not-found'); } - updateQuery.folder_id = folder._id; + updateQuery['metadata.folder_id'] = folder._id; } } const updated = await DriveFile.update(file._id, { - $set: { metadata: updateQuery } + $set: { updateQuery } }); - console.dir(updated) - // Serialize const fileObj = await serialize(updated); - console.dir(fileObj) - // Response res(fileObj); diff --git a/src/api/endpoints/messaging/messages/create.ts b/src/api/endpoints/messaging/messages/create.ts index 1d186268f..149852c09 100644 --- a/src/api/endpoints/messaging/messages/create.ts +++ b/src/api/endpoints/messaging/messages/create.ts @@ -54,9 +54,7 @@ module.exports = (params, user) => new Promise(async (res, rej) => { if (fileId !== undefined) { file = await DriveFile.findOne({ _id: fileId, - metadata: { - user_id: user._id - } + 'metadata.user_id': user._id }); if (file === null) { diff --git a/src/api/endpoints/posts/create.ts b/src/api/endpoints/posts/create.ts index 150763977..4f4b7e2e8 100644 --- a/src/api/endpoints/posts/create.ts +++ b/src/api/endpoints/posts/create.ts @@ -44,9 +44,7 @@ module.exports = (params, user: IUser, app) => new Promise(async (res, rej) => { // SELECT _id const entity = await DriveFile.findOne({ _id: mediaId, - metadata: { - user_id: user._id - } + 'metadata.user_id': user._id }); if (entity === null) { diff --git a/src/api/serializers/drive-folder.ts b/src/api/serializers/drive-folder.ts index 3b5f61aee..6ebf454a2 100644 --- a/src/api/serializers/drive-folder.ts +++ b/src/api/serializers/drive-folder.ts @@ -44,9 +44,7 @@ const self = ( }); const childFilesCount = await DriveFile.count({ - metadata: { - folder_id: _folder.id - } + 'metadata.folder_id': _folder.id }); _folder.folders_count = childFoldersCount; From c8c5be3d7ae4558a4000eeb8e7dc4eab57d26417 Mon Sep 17 00:00:00 2001 From: otofune Date: Mon, 6 Nov 2017 16:26:17 +0900 Subject: [PATCH 055/327] core - fix metadata searching --- src/api/common/add-file-to-drive.ts | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/api/common/add-file-to-drive.ts b/src/api/common/add-file-to-drive.ts index 376c470e9..1f882389a 100644 --- a/src/api/common/add-file-to-drive.ts +++ b/src/api/common/add-file-to-drive.ts @@ -81,9 +81,7 @@ export default ( // Check if there is a file with the same hash const much = await DriveFile.findOne({ md5: hash, - metadata: { - user_id: user._id - } + 'metadata.user_id': user._id }); if (much !== null) { @@ -97,7 +95,7 @@ export default ( // Calculate drive usage const usage = ((await DriveFile .aggregate([ - { $match: { metadata: { user_id: user._id } } }, + { $match: { 'metadata.user_id': user._id } }, { $project: { length: true }}, From 623206eed40bd244370a182cfd19d97d64e77d64 Mon Sep 17 00:00:00 2001 From: otofune Date: Mon, 6 Nov 2017 16:29:13 +0900 Subject: [PATCH 056/327] remove console --- src/api/common/add-file-to-drive.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/api/common/add-file-to-drive.ts b/src/api/common/add-file-to-drive.ts index 1f882389a..dff2d5235 100644 --- a/src/api/common/add-file-to-drive.ts +++ b/src/api/common/add-file-to-drive.ts @@ -152,7 +152,6 @@ export default ( comment: comment, properties: properties }); - console.dir(file) log(`drive file has been created ${file._id}`); From f1571e223bd62f7a3f7d54dc470b820e30b0dae7 Mon Sep 17 00:00:00 2001 From: otofune Date: Mon, 6 Nov 2017 16:32:01 +0900 Subject: [PATCH 057/327] fix lint (automattic) --- src/api/common/add-file-to-drive.ts | 18 ++++++------- src/api/endpoints/drive/files.ts | 2 +- src/api/endpoints/drive/files/show.ts | 2 +- src/api/endpoints/drive/files/update.ts | 3 +-- src/api/endpoints/posts/timeline.ts | 4 +-- src/api/models/drive-file.ts | 10 +++---- src/api/serializers/drive-file.ts | 4 +-- src/db/mongodb.ts | 18 ++++++------- src/file/server.ts | 36 ++++++++++++------------- 9 files changed, 48 insertions(+), 49 deletions(-) diff --git a/src/api/common/add-file-to-drive.ts b/src/api/common/add-file-to-drive.ts index dff2d5235..f9c22ccac 100644 --- a/src/api/common/add-file-to-drive.ts +++ b/src/api/common/add-file-to-drive.ts @@ -14,16 +14,16 @@ import { Duplex } from 'stream'; const log = debug('misskey:register-drive-file'); const addToGridFS = (name, binary, metadata): Promise => new Promise(async (resolve, reject) => { - const dataStream = new Duplex() - dataStream.push(binary) - dataStream.push(null) + const dataStream = new Duplex(); + dataStream.push(binary); + dataStream.push(null); - const bucket = await getGridFSBucket() - const writeStream = bucket.openUploadStream(name, { metadata }) - writeStream.once('finish', (doc) => { resolve(doc) }) - writeStream.on('error', reject) - dataStream.pipe(writeStream) -}) + const bucket = await getGridFSBucket(); + const writeStream = bucket.openUploadStream(name, { metadata }); + writeStream.once('finish', (doc) => { resolve(doc); }); + writeStream.on('error', reject); + dataStream.pipe(writeStream); +}); /** * Add file to drive diff --git a/src/api/endpoints/drive/files.ts b/src/api/endpoints/drive/files.ts index 035916b30..53b48a8be 100644 --- a/src/api/endpoints/drive/files.ts +++ b/src/api/endpoints/drive/files.ts @@ -63,5 +63,5 @@ module.exports = async (params, user, app) => { // Serialize const _files = await Promise.all(files.map(file => serialize(file))); - return _files + return _files; }; diff --git a/src/api/endpoints/drive/files/show.ts b/src/api/endpoints/drive/files/show.ts index 0a19b1993..3c7cf774f 100644 --- a/src/api/endpoints/drive/files/show.ts +++ b/src/api/endpoints/drive/files/show.ts @@ -33,5 +33,5 @@ module.exports = async (params, user) => { detail: true }); - return _file + return _file; }; diff --git a/src/api/endpoints/drive/files/update.ts b/src/api/endpoints/drive/files/update.ts index 7a6d2562f..4e56b30ac 100644 --- a/src/api/endpoints/drive/files/update.ts +++ b/src/api/endpoints/drive/files/update.ts @@ -20,7 +20,6 @@ module.exports = (params, user) => new Promise(async (res, rej) => { const [fileId, fileIdErr] = $(params.file_id).id().$; if (fileIdErr) return rej('invalid file_id param'); - // Fetch file const file = await DriveFile .findOne({ @@ -32,7 +31,7 @@ module.exports = (params, user) => new Promise(async (res, rej) => { return rej('file-not-found'); } - const updateQuery: any = {} + const updateQuery: any = {}; // Get 'name' parameter const [name, nameErr] = $(params.name).optional.string().pipe(validateFileName).$; diff --git a/src/api/endpoints/posts/timeline.ts b/src/api/endpoints/posts/timeline.ts index 978825a10..203413e23 100644 --- a/src/api/endpoints/posts/timeline.ts +++ b/src/api/endpoints/posts/timeline.ts @@ -92,6 +92,6 @@ module.exports = async (params, user, app) => { }); // Serialize - const _timeline = await Promise.all(timeline.map(post => serialize(post, user))) - return _timeline + const _timeline = await Promise.all(timeline.map(post => serialize(post, user))); + return _timeline; }; diff --git a/src/api/models/drive-file.ts b/src/api/models/drive-file.ts index 79a87f657..8968d065c 100644 --- a/src/api/models/drive-file.ts +++ b/src/api/models/drive-file.ts @@ -8,14 +8,14 @@ const collection = monkDb.get('drive_files.files'); export default collection as any; // fuck type definition const getGridFSBucket = async (): Promise => { - const db = await nativeDbConn() + const db = await nativeDbConn(); const bucket = new mongodb.GridFSBucket(db, { bucketName: 'drive_files' - }) - return bucket -} + }); + return bucket; +}; -export { getGridFSBucket } +export { getGridFSBucket }; export function validateFileName(name: string): boolean { return ( diff --git a/src/api/serializers/drive-file.ts b/src/api/serializers/drive-file.ts index e749f8038..2af7db572 100644 --- a/src/api/serializers/drive-file.ts +++ b/src/api/serializers/drive-file.ts @@ -40,13 +40,13 @@ export default ( _file = deepcopy(file); } - if (!_file) return reject('invalid file arg.') + if (!_file) return reject('invalid file arg.'); // rendered target let _target: any = {}; _target.id = _file._id; - _target.created_at = _file.uploadDate + _target.created_at = _file.uploadDate; _target = Object.assign(_target, _file.metadata); diff --git a/src/db/mongodb.ts b/src/db/mongodb.ts index 75f1a1d3c..c978e6460 100644 --- a/src/db/mongodb.ts +++ b/src/db/mongodb.ts @@ -16,7 +16,7 @@ export default db; /** * MongoDB native module (officialy) */ -import * as mongodb from 'mongodb' +import * as mongodb from 'mongodb'; let mdb: mongodb.Db; @@ -25,14 +25,14 @@ const nativeDbConn = async (): Promise => { const db = await ((): Promise => new Promise((resolve, reject) => { mongodb.MongoClient.connect(uri, (e, db) => { - if (e) return reject(e) - resolve(db) - }) - }))() + if (e) return reject(e); + resolve(db); + }); + }))(); - mdb = db + mdb = db; - return db -} + return db; +}; -export { nativeDbConn } +export { nativeDbConn }; diff --git a/src/file/server.ts b/src/file/server.ts index f38599b89..375f29487 100644 --- a/src/file/server.ts +++ b/src/file/server.ts @@ -97,7 +97,7 @@ app.get('/:id', async (req, res) => { return; } - const fileId = new mongodb.ObjectID(req.params.id) + const fileId = new mongodb.ObjectID(req.params.id); const file = await DriveFile.findOne({ _id: fileId }); if (file == null) { @@ -105,18 +105,18 @@ app.get('/:id', async (req, res) => { return; } - const bucket = await getGridFSBucket() + const bucket = await getGridFSBucket(); const buffer = await ((id): Promise => new Promise((resolve, reject) => { - const chunks = [] - const readableStream = bucket.openDownloadStream(id) - readableStream.on('data', chunk => { + const chunks = []; + const readableStream = bucket.openDownloadStream(id); + readableStream.on('data', chunk => { chunks.push(chunk); - }) + }); readableStream.on('end', () => { - resolve(Buffer.concat(chunks)) - }) - }))(fileId) + resolve(Buffer.concat(chunks)); + }); + }))(fileId); send(buffer, file.metadata.type, req, res); }); @@ -128,7 +128,7 @@ app.get('/:id/:name', async (req, res) => { return; } - const fileId = new mongodb.ObjectID(req.params.id) + const fileId = new mongodb.ObjectID(req.params.id); const file = await DriveFile.findOne({ _id: fileId }); if (file == null) { @@ -136,18 +136,18 @@ app.get('/:id/:name', async (req, res) => { return; } - const bucket = await getGridFSBucket() + const bucket = await getGridFSBucket(); const buffer = await ((id): Promise => new Promise((resolve, reject) => { - const chunks = [] - const readableStream = bucket.openDownloadStream(id) - readableStream.on('data', chunk => { + const chunks = []; + const readableStream = bucket.openDownloadStream(id); + readableStream.on('data', chunk => { chunks.push(chunk); - }) + }); readableStream.on('end', () => { - resolve(Buffer.concat(chunks)) - }) - }))(fileId) + resolve(Buffer.concat(chunks)); + }); + }))(fileId); send(buffer, file.metadata.type, req, res); }); From f2b4f3c3048dfa4354bb4280aa317ecae7000220 Mon Sep 17 00:00:00 2001 From: otofune Date: Mon, 6 Nov 2017 16:49:07 +0900 Subject: [PATCH 058/327] /drive/files/update - return collectly value --- src/api/endpoints/drive/files/update.ts | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/src/api/endpoints/drive/files/update.ts b/src/api/endpoints/drive/files/update.ts index 4e56b30ac..d7b858c2b 100644 --- a/src/api/endpoints/drive/files/update.ts +++ b/src/api/endpoints/drive/files/update.ts @@ -31,12 +31,10 @@ module.exports = (params, user) => new Promise(async (res, rej) => { return rej('file-not-found'); } - const updateQuery: any = {}; - // Get 'name' parameter const [name, nameErr] = $(params.name).optional.string().pipe(validateFileName).$; if (nameErr) return rej('invalid name param'); - if (name) updateQuery['metadata.name'] = name; + if (name) file.metadata.name = name; // Get 'folder_id' parameter const [folderId, folderIdErr] = $(params.folder_id).optional.nullable.id().$; @@ -44,7 +42,7 @@ module.exports = (params, user) => new Promise(async (res, rej) => { if (folderId !== undefined) { if (folderId === null) { - updateQuery['metadata.folder_id'] = null; + file.metadata.folder_id = null; } else { // Fetch folder const folder = await DriveFolder @@ -57,16 +55,19 @@ module.exports = (params, user) => new Promise(async (res, rej) => { return rej('folder-not-found'); } - updateQuery['metadata.folder_id'] = folder._id; + file.metadata.folder_id = folder._id; } } - const updated = await DriveFile.update(file._id, { - $set: { updateQuery } + await DriveFile.update(file._id, { + $set: { + 'metadata.name': file.metadata.name, + 'metadata.folder_id': file.metadata.folder_id + } }); // Serialize - const fileObj = await serialize(updated); + const fileObj = await serialize(file); // Response res(fileObj); From b008253f38c1bcb64c05ad0088ec84d6e9ccce2c Mon Sep 17 00:00:00 2001 From: otofune Date: Mon, 6 Nov 2017 16:59:09 +0900 Subject: [PATCH 059/327] update test for GridFS --- test/api.js | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/test/api.js b/test/api.js index b43eb7ff6..c0da9d6c5 100644 --- a/test/api.js +++ b/test/api.js @@ -1152,9 +1152,12 @@ async function insertHimawari(opts) { } async function insertDriveFile(opts) { - return await db.get('drive_files').insert(Object.assign({ - name: 'strawberry-pasta.png' - }, opts)); + return await db.get('drive_files.files').insert({ + length: opts.datasize, + metadata: Object.assign({ + name: 'strawberry-pasta.png' + }, opts) + }); } async function insertDriveFolder(opts) { From dcbcbb556ed409aa16c81a8e101d6515222ad4a6 Mon Sep 17 00:00:00 2001 From: otofune Date: Mon, 6 Nov 2017 17:57:03 +0900 Subject: [PATCH 060/327] migration - add GridFS migration --- tools/migration/use-gridfs.js | 49 +++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 tools/migration/use-gridfs.js diff --git a/tools/migration/use-gridfs.js b/tools/migration/use-gridfs.js new file mode 100644 index 000000000..d41514416 --- /dev/null +++ b/tools/migration/use-gridfs.js @@ -0,0 +1,49 @@ +// for Node.js interpret + +const { default: db } = require('../../built/db/mongodb') +const { default: DriveFile, getGridFSBucket } = require('../../built/api/models/drive-file') +const { Duplex } = require('stream') + +const writeToGridFS = (bucket, buffer, ...rest) => new Promise((resolve, reject) => { + const writeStream = bucket.openUploadStreamWithId(...rest) + + const dataStream = new Duplex() + dataStream.push(buffer) + dataStream.push(null) + + writeStream.once('finish', resolve) + writeStream.on('error', reject) + + dataStream.pipe(writeStream) +}) + +const migrateToGridFS = async (doc) => { + const id = doc._id + const buffer = doc.data.buffer + const created_at = doc.created_at + + delete doc._id + delete doc.created_at + delete doc.datasize + delete doc.hash + delete doc.data + + const bucket = await getGridFSBucket() + const added = await writeToGridFS(bucket, buffer, id, `${id}/${doc.name}`, { metadata: doc }) + + const result = await DriveFile.update(id, { + $set: { + uploadDate: created_at + } + }) + + return added && result.ok === 1 +} + +const main = async () => { + const docs = await db.get('drive_files').find() + const all = await Promise.all(docs.map(migrateToGridFS)) + return all +} + +main().then(console.dir).catch(console.error) From 3ab030387f8dfb1bd75de9a59633ce25795b264f Mon Sep 17 00:00:00 2001 From: otofune Date: Mon, 6 Nov 2017 18:30:49 +0900 Subject: [PATCH 061/327] add safety guard to serializers & fix importing uncorrect serializer --- src/api/endpoints/drive/folders/update.ts | 2 +- src/api/serializers/post.ts | 2 ++ src/api/serializers/user.ts | 2 ++ 3 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/api/endpoints/drive/folders/update.ts b/src/api/endpoints/drive/folders/update.ts index eec275787..4f2e3d2a7 100644 --- a/src/api/endpoints/drive/folders/update.ts +++ b/src/api/endpoints/drive/folders/update.ts @@ -4,7 +4,7 @@ import $ from 'cafy'; import DriveFolder from '../../../models/drive-folder'; import { isValidFolderName } from '../../../models/drive-folder'; -import serialize from '../../../serializers/drive-file'; +import serialize from '../../../serializers/drive-folder'; import event from '../../../event'; /** diff --git a/src/api/serializers/post.ts b/src/api/serializers/post.ts index 5788b226f..5a63384f0 100644 --- a/src/api/serializers/post.ts +++ b/src/api/serializers/post.ts @@ -57,6 +57,8 @@ const self = async ( _post = deepcopy(post); } + if (!_post) throw 'invalid post arg.'; + const id = _post._id; // Rename _id to id diff --git a/src/api/serializers/user.ts b/src/api/serializers/user.ts index d00f07389..0d24d6cc0 100644 --- a/src/api/serializers/user.ts +++ b/src/api/serializers/user.ts @@ -56,6 +56,8 @@ export default ( _user = deepcopy(user); } + if (!_user) return reject('invalid user arg.'); + // Me const meId: mongo.ObjectID = me ? mongo.ObjectID.prototype.isPrototypeOf(me) From 2f2c541245565bf08b6ba996d233188e51156d74 Mon Sep 17 00:00:00 2001 From: otofune Date: Mon, 6 Nov 2017 18:38:59 +0900 Subject: [PATCH 062/327] remove whitespace --- src/api/serializers/post.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/api/serializers/post.ts b/src/api/serializers/post.ts index 5a63384f0..03fd12077 100644 --- a/src/api/serializers/post.ts +++ b/src/api/serializers/post.ts @@ -57,7 +57,7 @@ const self = async ( _post = deepcopy(post); } - if (!_post) throw 'invalid post arg.'; + if (!_post) throw 'invalid post arg.'; const id = _post._id; From 27cf4521114bcb8bf8a0d6b9c4f7081ab27d6469 Mon Sep 17 00:00:00 2001 From: syuilo Date: Mon, 6 Nov 2017 19:16:14 +0900 Subject: [PATCH 063/327] Use tab for indentation --- package.json | 316 +++++++++++++++++++++++++-------------------------- 1 file changed, 158 insertions(+), 158 deletions(-) diff --git a/package.json b/package.json index 2bf77fa14..7fa56321d 100644 --- a/package.json +++ b/package.json @@ -1,161 +1,161 @@ { - "name": "misskey", - "author": "syuilo ", - "version": "0.0.2807", - "license": "MIT", - "description": "A miniblog-based SNS", - "bugs": "https://github.com/syuilo/misskey/issues", - "repository": "https://github.com/syuilo/misskey.git", - "main": "./built/index.js", - "private": true, - "scripts": { - "config": "node ./tools/init.js", - "start": "node ./built", - "debug": "DEBUG=misskey:* node ./built", - "swagger": "node ./swagger.js", - "build": "gulp build", - "rebuild": "gulp rebuild", - "clean": "gulp clean", - "cleanall": "gulp cleanall", - "lint": "gulp lint", + "name": "misskey", + "author": "syuilo ", + "version": "0.0.2807", + "license": "MIT", + "description": "A miniblog-based SNS", + "bugs": "https://github.com/syuilo/misskey/issues", + "repository": "https://github.com/syuilo/misskey.git", + "main": "./built/index.js", + "private": true, + "scripts": { + "config": "node ./tools/init.js", + "start": "node ./built", + "debug": "DEBUG=misskey:* node ./built", + "swagger": "node ./swagger.js", + "build": "gulp build", + "rebuild": "gulp rebuild", + "clean": "gulp clean", + "cleanall": "gulp cleanall", + "lint": "gulp lint", "test": "gulp test" - }, - "devDependencies": { - "@types/bcryptjs": "2.4.1", - "@types/body-parser": "1.16.7", - "@types/chai": "4.0.4", - "@types/chai-http": "3.0.3", - "@types/chalk": "2.2.0", - "@types/compression": "0.0.34", - "@types/cors": "2.8.1", - "@types/debug": "0.0.30", - "@types/deep-equal": "1.0.1", - "@types/elasticsearch": "5.0.17", - "@types/event-stream": "3.3.32", - "@types/express": "4.0.37", - "@types/gm": "1.17.33", - "@types/gulp": "4.0.3", - "@types/gulp-htmlmin": "1.3.30", - "@types/gulp-mocha": "0.0.30", - "@types/gulp-rename": "0.0.32", - "@types/gulp-replace": "0.0.30", - "@types/gulp-tslint": "3.6.31", - "@types/gulp-typescript": "2.13.0", - "@types/gulp-uglify": "3.0.3", - "@types/gulp-util": "3.0.33", - "@types/inquirer": "0.0.34", - "@types/is-root": "1.0.0", - "@types/is-url": "1.2.28", - "@types/js-yaml": "3.9.1", - "@types/mocha": "2.2.44", - "@types/mongodb": "2.2.13", - "@types/monk": "1.0.6", - "@types/morgan": "1.7.35", - "@types/ms": "0.7.30", - "@types/multer": "1.3.5", - "@types/node": "8.0.47", - "@types/ratelimiter": "2.1.28", - "@types/redis": "2.8.1", - "@types/request": "2.0.7", - "@types/rimraf": "2.0.2", - "@types/riot": "3.6.1", - "@types/serve-favicon": "2.2.29", - "@types/uuid": "3.4.3", - "@types/webpack": "3.0.14", - "@types/uuid": "3.4.3", - "@types/webpack": "3.0.13", - "@types/webpack-stream": "3.2.8", - "@types/websocket": "0.0.34", - "awesome-typescript-loader": "3.3.0", - "chai": "4.1.2", - "chai-http": "3.0.0", - "css-loader": "0.28.7", - "event-stream": "3.3.4", - "gulp": "3.9.1", - "gulp-cssnano": "2.1.2", - "gulp-htmlmin": "3.0.0", - "gulp-imagemin": "3.4.0", - "gulp-mocha": "4.3.1", - "gulp-pug": "3.3.0", - "gulp-rename": "1.2.2", - "gulp-replace": "0.6.1", - "gulp-tslint": "8.1.2", - "gulp-typescript": "3.2.3", - "gulp-uglify": "3.0.0", - "gulp-util": "3.0.8", - "mocha": "4.0.1", - "riot-tag-loader": "1.0.0", - "string-replace-webpack-plugin": "0.1.3", - "style-loader": "0.19.0", - "stylus": "0.54.5", - "stylus-loader": "3.0.1", - "swagger-jsdoc": "1.9.7", - "tslint": "5.8.0", - "uglify-es": "3.0.27", - "uglify-js": "git+https://github.com/mishoo/UglifyJS2.git#harmony", - "uglifyjs-webpack-plugin": "1.0.1", - "webpack": "3.8.1" - }, - "dependencies": { - "@prezzemolo/rap": "0.1.2", - "accesses": "2.5.0", - "animejs": "2.2.0", - "autwh": "0.0.1", - "bcryptjs": "2.4.3", - "body-parser": "1.18.2", - "cafy": "3.1.1", - "chalk": "2.3.0", - "compression": "1.7.1", - "cors": "2.8.4", - "cropperjs": "1.1.3", - "crypto": "1.0.1", - "debug": "3.1.0", - "deep-equal": "1.0.1", - "deepcopy": "0.6.3", - "diskusage": "0.2.2", - "download": "6.2.5", - "elasticsearch": "13.3.1", - "escape-regexp": "0.0.1", - "express": "4.15.4", - "file-type": "7.2.0", - "fuckadblock": "3.2.1", - "gm": "1.23.0", - "inquirer": "3.3.0", - "is-root": "1.0.0", - "is-url": "1.2.2", - "js-yaml": "3.10.0", - "mecab-async": "^0.1.0", - "moji": "^0.5.1", - "mongodb": "2.2.33", - "monk": "6.0.5", - "morgan": "1.9.0", - "ms": "2.0.0", - "multer": "1.3.0", - "nprogress": "0.2.0", - "os-utils": "0.0.14", - "page": "1.7.1", - "pictograph": "2.0.4", - "prominence": "0.2.0", - "pug": "2.0.0-rc.4", - "ratelimiter": "3.0.3", - "recaptcha-promise": "0.1.3", - "reconnecting-websocket": "3.2.2", - "redis": "2.8.0", - "request": "2.83.0", - "rimraf": "2.6.2", - "riot": "3.7.4", - "rndstr": "1.0.0", - "s-age": "1.1.0", - "serve-favicon": "2.4.5", - "summaly": "2.0.3", - "syuilo-password-strength": "0.0.1", - "tcp-port-used": "0.1.2", - "textarea-caret": "3.0.2", - "ts-node": "3.3.0", - "typescript": "2.6.1", - "uuid": "3.1.0", - "vhost": "3.0.2", - "websocket": "1.0.25", - "xev": "2.0.0" - } + }, + "devDependencies": { + "@types/bcryptjs": "2.4.1", + "@types/body-parser": "1.16.7", + "@types/chai": "4.0.4", + "@types/chai-http": "3.0.3", + "@types/chalk": "2.2.0", + "@types/compression": "0.0.34", + "@types/cors": "2.8.1", + "@types/debug": "0.0.30", + "@types/deep-equal": "1.0.1", + "@types/elasticsearch": "5.0.17", + "@types/event-stream": "3.3.32", + "@types/express": "4.0.37", + "@types/gm": "1.17.33", + "@types/gulp": "4.0.3", + "@types/gulp-htmlmin": "1.3.30", + "@types/gulp-mocha": "0.0.30", + "@types/gulp-rename": "0.0.32", + "@types/gulp-replace": "0.0.30", + "@types/gulp-tslint": "3.6.31", + "@types/gulp-typescript": "2.13.0", + "@types/gulp-uglify": "3.0.3", + "@types/gulp-util": "3.0.33", + "@types/inquirer": "0.0.34", + "@types/is-root": "1.0.0", + "@types/is-url": "1.2.28", + "@types/js-yaml": "3.9.1", + "@types/mocha": "2.2.44", + "@types/mongodb": "2.2.13", + "@types/monk": "1.0.6", + "@types/morgan": "1.7.35", + "@types/ms": "0.7.30", + "@types/multer": "1.3.5", + "@types/node": "8.0.47", + "@types/ratelimiter": "2.1.28", + "@types/redis": "2.8.1", + "@types/request": "2.0.7", + "@types/rimraf": "2.0.2", + "@types/riot": "3.6.1", + "@types/serve-favicon": "2.2.29", + "@types/uuid": "3.4.3", + "@types/webpack": "3.0.14", + "@types/uuid": "3.4.3", + "@types/webpack": "3.0.13", + "@types/webpack-stream": "3.2.8", + "@types/websocket": "0.0.34", + "awesome-typescript-loader": "3.3.0", + "chai": "4.1.2", + "chai-http": "3.0.0", + "css-loader": "0.28.7", + "event-stream": "3.3.4", + "gulp": "3.9.1", + "gulp-cssnano": "2.1.2", + "gulp-htmlmin": "3.0.0", + "gulp-imagemin": "3.4.0", + "gulp-mocha": "4.3.1", + "gulp-pug": "3.3.0", + "gulp-rename": "1.2.2", + "gulp-replace": "0.6.1", + "gulp-tslint": "8.1.2", + "gulp-typescript": "3.2.3", + "gulp-uglify": "3.0.0", + "gulp-util": "3.0.8", + "mocha": "4.0.1", + "riot-tag-loader": "1.0.0", + "string-replace-webpack-plugin": "0.1.3", + "style-loader": "0.19.0", + "stylus": "0.54.5", + "stylus-loader": "3.0.1", + "swagger-jsdoc": "1.9.7", + "tslint": "5.8.0", + "uglify-es": "3.0.27", + "uglify-js": "git+https://github.com/mishoo/UglifyJS2.git#harmony", + "uglifyjs-webpack-plugin": "1.0.1", + "webpack": "3.8.1" + }, + "dependencies": { + "@prezzemolo/rap": "0.1.2", + "accesses": "2.5.0", + "animejs": "2.2.0", + "autwh": "0.0.1", + "bcryptjs": "2.4.3", + "body-parser": "1.18.2", + "cafy": "3.1.1", + "chalk": "2.3.0", + "compression": "1.7.1", + "cors": "2.8.4", + "cropperjs": "1.1.3", + "crypto": "1.0.1", + "debug": "3.1.0", + "deep-equal": "1.0.1", + "deepcopy": "0.6.3", + "diskusage": "0.2.2", + "download": "6.2.5", + "elasticsearch": "13.3.1", + "escape-regexp": "0.0.1", + "express": "4.15.4", + "file-type": "7.2.0", + "fuckadblock": "3.2.1", + "gm": "1.23.0", + "inquirer": "3.3.0", + "is-root": "1.0.0", + "is-url": "1.2.2", + "js-yaml": "3.10.0", + "mecab-async": "^0.1.0", + "moji": "^0.5.1", + "mongodb": "2.2.33", + "monk": "6.0.5", + "morgan": "1.9.0", + "ms": "2.0.0", + "multer": "1.3.0", + "nprogress": "0.2.0", + "os-utils": "0.0.14", + "page": "1.7.1", + "pictograph": "2.0.4", + "prominence": "0.2.0", + "pug": "2.0.0-rc.4", + "ratelimiter": "3.0.3", + "recaptcha-promise": "0.1.3", + "reconnecting-websocket": "3.2.2", + "redis": "2.8.0", + "request": "2.83.0", + "rimraf": "2.6.2", + "riot": "3.7.4", + "rndstr": "1.0.0", + "s-age": "1.1.0", + "serve-favicon": "2.4.5", + "summaly": "2.0.3", + "syuilo-password-strength": "0.0.1", + "tcp-port-used": "0.1.2", + "textarea-caret": "3.0.2", + "ts-node": "3.3.0", + "typescript": "2.6.1", + "uuid": "3.1.0", + "vhost": "3.0.2", + "websocket": "1.0.25", + "xev": "2.0.0" + } } From 990975a70e6c76cfbbeabe5e715ccdc608ce215d Mon Sep 17 00:00:00 2001 From: syuilo Date: Mon, 6 Nov 2017 19:39:55 +0900 Subject: [PATCH 064/327] Remove needless dependent This is a stub types definition for chalk (https://github.com/chalk/chalk). chalk provides its own type definitions, so yo u don't need @types/chalk installed! --- package.json | 1 - 1 file changed, 1 deletion(-) diff --git a/package.json b/package.json index 7fa56321d..da5badc94 100644 --- a/package.json +++ b/package.json @@ -25,7 +25,6 @@ "@types/body-parser": "1.16.7", "@types/chai": "4.0.4", "@types/chai-http": "3.0.3", - "@types/chalk": "2.2.0", "@types/compression": "0.0.34", "@types/cors": "2.8.1", "@types/debug": "0.0.30", From 0c787c0a9fed28f9af974d050d671ef35abe23b5 Mon Sep 17 00:00:00 2001 From: syuilo Date: Mon, 6 Nov 2017 19:59:14 +0900 Subject: [PATCH 065/327] :v: --- gulpfile.ts | 4 ++-- package.json | 3 --- src/index.ts | 2 +- src/utils/cli/progressbar.ts | 2 +- src/utils/logger.ts | 4 ++-- 5 files changed, 6 insertions(+), 9 deletions(-) diff --git a/gulpfile.ts b/gulpfile.ts index 4ee5fbce0..448b6b7fe 100644 --- a/gulpfile.ts +++ b/gulpfile.ts @@ -13,7 +13,7 @@ import cssnano = require('gulp-cssnano'); import * as uglifyComposer from 'gulp-uglify/composer'; import pug = require('gulp-pug'); import * as rimraf from 'rimraf'; -import * as chalk from 'chalk'; +import chalk from 'chalk'; import imagemin = require('gulp-imagemin'); import * as rename from 'gulp-rename'; import * as mocha from 'gulp-mocha'; @@ -123,7 +123,7 @@ gulp.task('build:client:script', () => .pipe(replace('VERSION', JSON.stringify(version))) .pipe(isProduction ? uglify({ toplevel: true - }) : gutil.noop()) + } as any) : gutil.noop()) .pipe(gulp.dest('./built/web/assets/')) as any ); diff --git a/package.json b/package.json index da5badc94..606ce9f0f 100644 --- a/package.json +++ b/package.json @@ -60,8 +60,6 @@ "@types/riot": "3.6.1", "@types/serve-favicon": "2.2.29", "@types/uuid": "3.4.3", - "@types/webpack": "3.0.14", - "@types/uuid": "3.4.3", "@types/webpack": "3.0.13", "@types/webpack-stream": "3.2.8", "@types/websocket": "0.0.34", @@ -91,7 +89,6 @@ "swagger-jsdoc": "1.9.7", "tslint": "5.8.0", "uglify-es": "3.0.27", - "uglify-js": "git+https://github.com/mishoo/UglifyJS2.git#harmony", "uglifyjs-webpack-plugin": "1.0.1", "webpack": "3.8.1" }, diff --git a/src/index.ts b/src/index.ts index aa53c9123..218455d6f 100644 --- a/src/index.ts +++ b/src/index.ts @@ -8,7 +8,7 @@ import * as fs from 'fs'; import * as os from 'os'; import * as cluster from 'cluster'; import * as debug from 'debug'; -import * as chalk from 'chalk'; +import chalk from 'chalk'; // import portUsed = require('tcp-port-used'); import isRoot = require('is-root'); import { master } from 'accesses'; diff --git a/src/utils/cli/progressbar.ts b/src/utils/cli/progressbar.ts index 4afb4b090..72496fded 100644 --- a/src/utils/cli/progressbar.ts +++ b/src/utils/cli/progressbar.ts @@ -1,6 +1,6 @@ import { EventEmitter } from 'events'; import * as readline from 'readline'; -import * as chalk from 'chalk'; +import chalk from 'chalk'; /** * Progress bar diff --git a/src/utils/logger.ts b/src/utils/logger.ts index ecfacbc95..fae1042c3 100644 --- a/src/utils/logger.ts +++ b/src/utils/logger.ts @@ -1,8 +1,8 @@ -import * as chalk from 'chalk'; +import chalk, { Chalk } from 'chalk'; export type LogLevel = 'Error' | 'Warn' | 'Info'; -function toLevelColor(level: LogLevel): chalk.ChalkStyle { +function toLevelColor(level: LogLevel): Chalk { switch (level) { case 'Error': return chalk.red; case 'Warn': return chalk.yellow; From 59799c7b193400ee93f5705f0d5f65c75f92e751 Mon Sep 17 00:00:00 2001 From: syuilo Date: Mon, 6 Nov 2017 20:03:50 +0900 Subject: [PATCH 066/327] Refactor --- src/api/endpoints/posts/timeline.ts | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/api/endpoints/posts/timeline.ts b/src/api/endpoints/posts/timeline.ts index 203413e23..7af435e82 100644 --- a/src/api/endpoints/posts/timeline.ts +++ b/src/api/endpoints/posts/timeline.ts @@ -34,11 +34,11 @@ module.exports = async (params, user, app) => { throw 'cannot set since_id and max_id'; } - const { followingIds, watchChannelIds } = await rap({ + const { followingIds, watchingChannelIds } = await rap({ // ID list of the user itself and other users who the user follows followingIds: getFriends(user._id), // Watchしているチャンネルを取得 - watchChannelIds: ChannelWatching.find({ + watchingChannelIds: ChannelWatching.find({ user_id: user._id, // 削除されたドキュメントは除く deleted_at: { $exists: false } @@ -67,7 +67,7 @@ module.exports = async (params, user, app) => { }, { // Watchしているチャンネルへの投稿 channel_id: { - $in: watchChannelIds + $in: watchingChannelIds } }] } as any; @@ -92,6 +92,5 @@ module.exports = async (params, user, app) => { }); // Serialize - const _timeline = await Promise.all(timeline.map(post => serialize(post, user))); - return _timeline; + return await Promise.all(timeline.map(post => serialize(post, user))); }; From 39762791a028564c6db92f6366d3b5d2230ded16 Mon Sep 17 00:00:00 2001 From: syuilo Date: Mon, 6 Nov 2017 22:10:40 +0900 Subject: [PATCH 067/327] Fix index creation --- src/api/models/drive-file.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/api/models/drive-file.ts b/src/api/models/drive-file.ts index 8968d065c..976c97e18 100644 --- a/src/api/models/drive-file.ts +++ b/src/api/models/drive-file.ts @@ -3,7 +3,7 @@ import monkDb, { nativeDbConn } from '../../db/mongodb'; const collection = monkDb.get('drive_files.files'); -(collection as any).createIndex('hash'); // fuck type definition +(collection as any).createIndex('md5'); // fuck type definition export default collection as any; // fuck type definition From e471a9e8b9ecc7e948bfb0e9ac2c5bd47bee35c1 Mon Sep 17 00:00:00 2001 From: syuilo Date: Mon, 6 Nov 2017 22:22:48 +0900 Subject: [PATCH 068/327] =?UTF-8?q?=E3=83=8F=E3=83=83=E3=82=B7=E3=83=A5?= =?UTF-8?q?=E5=80=A4=E3=81=AFMongoDB=E5=81=B4=E3=81=A7=E7=AE=A1=E7=90=86?= =?UTF-8?q?=E3=81=95=E3=82=8C=E3=81=A6=E3=81=84=E3=82=8B=E3=81=8B=E3=82=89?= =?UTF-8?q?=E6=89=8B=E5=8B=95=E3=81=A7=E3=82=A4=E3=83=B3=E3=83=87=E3=83=83?= =?UTF-8?q?=E3=82=AF=E3=82=B9=E3=82=92=E6=98=8E=E7=A4=BA=E3=81=99=E3=82=8B?= =?UTF-8?q?=E5=BF=85=E8=A6=81=E3=81=AF=E3=81=AA=E3=81=95=E3=81=9D=E3=81=86?= =?UTF-8?q?=E3=81=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api/models/drive-file.ts | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/api/models/drive-file.ts b/src/api/models/drive-file.ts index 976c97e18..802ee5a5f 100644 --- a/src/api/models/drive-file.ts +++ b/src/api/models/drive-file.ts @@ -3,8 +3,6 @@ import monkDb, { nativeDbConn } from '../../db/mongodb'; const collection = monkDb.get('drive_files.files'); -(collection as any).createIndex('md5'); // fuck type definition - export default collection as any; // fuck type definition const getGridFSBucket = async (): Promise => { From aa31c0f7d225d38ce5cefaea77dd554a6a7f0d46 Mon Sep 17 00:00:00 2001 From: "greenkeeper[bot]" Date: Mon, 6 Nov 2017 19:02:39 +0000 Subject: [PATCH 069/327] chore(package): update @types/webpack to version 3.8.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 606ce9f0f..15239c719 100644 --- a/package.json +++ b/package.json @@ -60,7 +60,7 @@ "@types/riot": "3.6.1", "@types/serve-favicon": "2.2.29", "@types/uuid": "3.4.3", - "@types/webpack": "3.0.13", + "@types/webpack": "3.8.0", "@types/webpack-stream": "3.2.8", "@types/websocket": "0.0.34", "awesome-typescript-loader": "3.3.0", From 903da06a28d98373bff9b31107c6b7977a64ae70 Mon Sep 17 00:00:00 2001 From: "greenkeeper[bot]" Date: Mon, 6 Nov 2017 19:54:17 +0000 Subject: [PATCH 070/327] chore(package): update @types/node to version 8.0.49 Closes #878 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 606ce9f0f..0048e63ba 100644 --- a/package.json +++ b/package.json @@ -52,7 +52,7 @@ "@types/morgan": "1.7.35", "@types/ms": "0.7.30", "@types/multer": "1.3.5", - "@types/node": "8.0.47", + "@types/node": "8.0.49", "@types/ratelimiter": "2.1.28", "@types/redis": "2.8.1", "@types/request": "2.0.7", From 9c38edb7516a6c5ad29290195c5f5dc0f259aa09 Mon Sep 17 00:00:00 2001 From: "greenkeeper[bot]" Date: Mon, 6 Nov 2017 22:58:57 +0000 Subject: [PATCH 071/327] chore(package): update uglify-es to version 3.1.8 Closes #602 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 606ce9f0f..710cb0e6c 100644 --- a/package.json +++ b/package.json @@ -88,7 +88,7 @@ "stylus-loader": "3.0.1", "swagger-jsdoc": "1.9.7", "tslint": "5.8.0", - "uglify-es": "3.0.27", + "uglify-es": "3.1.8", "uglifyjs-webpack-plugin": "1.0.1", "webpack": "3.8.1" }, From 20a00cda98af2cf1c6a846a1cf90e4c9f4fd1fd3 Mon Sep 17 00:00:00 2001 From: otofune Date: Tue, 7 Nov 2017 09:03:56 +0900 Subject: [PATCH 072/327] remove unneed dependencies --- package.json | 3 --- 1 file changed, 3 deletions(-) diff --git a/package.json b/package.json index 606ce9f0f..c384edb22 100644 --- a/package.json +++ b/package.json @@ -38,8 +38,6 @@ "@types/gulp-mocha": "0.0.30", "@types/gulp-rename": "0.0.32", "@types/gulp-replace": "0.0.30", - "@types/gulp-tslint": "3.6.31", - "@types/gulp-typescript": "2.13.0", "@types/gulp-uglify": "3.0.3", "@types/gulp-util": "3.0.33", "@types/inquirer": "0.0.34", @@ -104,7 +102,6 @@ "compression": "1.7.1", "cors": "2.8.4", "cropperjs": "1.1.3", - "crypto": "1.0.1", "debug": "3.1.0", "deep-equal": "1.0.1", "deepcopy": "0.6.3", From c31f7787469373d7bce88775b9a986c87fa48d1f Mon Sep 17 00:00:00 2001 From: otofune Date: Tue, 7 Nov 2017 09:04:16 +0900 Subject: [PATCH 073/327] add 'format' script to use autofix w/ tslint --- gulpfile.ts | 9 +++++++++ package.json | 3 ++- src/file/server.ts | 4 ++-- 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/gulpfile.ts b/gulpfile.ts index 448b6b7fe..04bd2b1c4 100644 --- a/gulpfile.ts +++ b/gulpfile.ts @@ -81,6 +81,15 @@ gulp.task('lint', () => .pipe(tslint.report()) ); +gulp.task('format', () => +gulp.src('./src/**/*.ts') + .pipe(tslint({ + formatter: 'verbose', + fix: true + })) + .pipe(tslint.report()) +); + gulp.task('mocha', () => gulp.src([]) .pipe(mocha({ diff --git a/package.json b/package.json index c384edb22..1593cd7d0 100644 --- a/package.json +++ b/package.json @@ -18,7 +18,8 @@ "clean": "gulp clean", "cleanall": "gulp cleanall", "lint": "gulp lint", - "test": "gulp test" + "test": "gulp test", + "format": "gulp format" }, "devDependencies": { "@types/bcryptjs": "2.4.1", diff --git a/src/file/server.ts b/src/file/server.ts index 375f29487..39e21d10e 100644 --- a/src/file/server.ts +++ b/src/file/server.ts @@ -110,7 +110,7 @@ app.get('/:id', async (req, res) => { const buffer = await ((id): Promise => new Promise((resolve, reject) => { const chunks = []; const readableStream = bucket.openDownloadStream(id); - readableStream.on('data', chunk => { + readableStream.on('data', chunk => { chunks.push(chunk); }); readableStream.on('end', () => { @@ -141,7 +141,7 @@ app.get('/:id/:name', async (req, res) => { const buffer = await ((id): Promise => new Promise((resolve, reject) => { const chunks = []; const readableStream = bucket.openDownloadStream(id); - readableStream.on('data', chunk => { + readableStream.on('data', chunk => { chunks.push(chunk); }); readableStream.on('end', () => { From 8801496d1441089530e4942fadfe660cc1733a68 Mon Sep 17 00:00:00 2001 From: otofune Date: Tue, 7 Nov 2017 09:14:39 +0900 Subject: [PATCH 074/327] file - unify '/:id' & '/:id/:name' --- src/file/server.ts | 94 ++++++++++++++++------------------------------ 1 file changed, 33 insertions(+), 61 deletions(-) diff --git a/src/file/server.ts b/src/file/server.ts index 39e21d10e..e83acd4f2 100644 --- a/src/file/server.ts +++ b/src/file/server.ts @@ -86,70 +86,42 @@ function send(data: Buffer, type: string, req: express.Request, res: express.Res } } +async function sendFileById (req: express.Request, res: express.Response): Promise { + // Validate id + if (!mongodb.ObjectID.isValid(req.params.id)) { + res.status(400).send('incorrect id'); + return; + } + + const fileId = new mongodb.ObjectID(req.params.id); + const file = await DriveFile.findOne({ _id: fileId }); + + if (file == null) { + res.status(404).sendFile(`${__dirname}/assets/dummy.png`); + return; + } + + const bucket = await getGridFSBucket(); + + const buffer = await ((id): Promise => new Promise((resolve, reject) => { + const chunks = []; + const readableStream = bucket.openDownloadStream(id); + readableStream.on('data', chunk => { + chunks.push(chunk); + }); + readableStream.on('end', () => { + resolve(Buffer.concat(chunks)); + }); + }))(fileId); + + send(buffer, file.metadata.type, req, res); +} + /** * Routing */ -app.get('/:id', async (req, res) => { - // Validate id - if (!mongodb.ObjectID.isValid(req.params.id)) { - res.status(400).send('incorrect id'); - return; - } - - const fileId = new mongodb.ObjectID(req.params.id); - const file = await DriveFile.findOne({ _id: fileId }); - - if (file == null) { - res.status(404).sendFile(`${__dirname}/assets/dummy.png`); - return; - } - - const bucket = await getGridFSBucket(); - - const buffer = await ((id): Promise => new Promise((resolve, reject) => { - const chunks = []; - const readableStream = bucket.openDownloadStream(id); - readableStream.on('data', chunk => { - chunks.push(chunk); - }); - readableStream.on('end', () => { - resolve(Buffer.concat(chunks)); - }); - }))(fileId); - - send(buffer, file.metadata.type, req, res); -}); - -app.get('/:id/:name', async (req, res) => { - // Validate id - if (!mongodb.ObjectID.isValid(req.params.id)) { - res.status(400).send('incorrect id'); - return; - } - - const fileId = new mongodb.ObjectID(req.params.id); - const file = await DriveFile.findOne({ _id: fileId }); - - if (file == null) { - res.status(404).sendFile(`${__dirname}/assets/dummy.png`); - return; - } - - const bucket = await getGridFSBucket(); - - const buffer = await ((id): Promise => new Promise((resolve, reject) => { - const chunks = []; - const readableStream = bucket.openDownloadStream(id); - readableStream.on('data', chunk => { - chunks.push(chunk); - }); - readableStream.on('end', () => { - resolve(Buffer.concat(chunks)); - }); - }))(fileId); - - send(buffer, file.metadata.type, req, res); -}); +app.get('/:id', sendFileById); +app.get('/:id/:name', sendFileById); module.exports = app; From 4e90fbe557a981b19ee20363f59eb4ea5258bfe1 Mon Sep 17 00:00:00 2001 From: otofune Date: Tue, 7 Nov 2017 09:18:40 +0900 Subject: [PATCH 075/327] file - if 'name' param given, validate --- src/file/server.ts | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/file/server.ts b/src/file/server.ts index e83acd4f2..1152b650b 100644 --- a/src/file/server.ts +++ b/src/file/server.ts @@ -86,7 +86,7 @@ function send(data: Buffer, type: string, req: express.Request, res: express.Res } } -async function sendFileById (req: express.Request, res: express.Response): Promise { +async function sendFileById(req: express.Request, res: express.Response): Promise { // Validate id if (!mongodb.ObjectID.isValid(req.params.id)) { res.status(400).send('incorrect id'); @@ -96,6 +96,12 @@ async function sendFileById (req: express.Request, res: express.Response): Promi const fileId = new mongodb.ObjectID(req.params.id); const file = await DriveFile.findOne({ _id: fileId }); + // validate name + if (req.params.name !== undefined && req.params.name !== file.metadata.name) { + res.status(404).send('there is no file has given name'); + return; + } + if (file == null) { res.status(404).sendFile(`${__dirname}/assets/dummy.png`); return; From 0a555d50dc32ecd1ca3687fa0f92454cee4dd7d2 Mon Sep 17 00:00:00 2001 From: otofune Date: Tue, 7 Nov 2017 09:30:51 +0900 Subject: [PATCH 076/327] use 'name' param as GridFS file's 'filename' --- src/api/common/add-file-to-drive.ts | 3 +-- src/api/endpoints/drive/files/find.ts | 2 +- src/api/endpoints/drive/files/update.ts | 4 ++-- src/api/serializers/drive-file.ts | 1 + src/file/server.ts | 2 +- tools/migration/use-gridfs.js | 4 +++- 6 files changed, 9 insertions(+), 7 deletions(-) diff --git a/src/api/common/add-file-to-drive.ts b/src/api/common/add-file-to-drive.ts index f9c22ccac..e1baf0819 100644 --- a/src/api/common/add-file-to-drive.ts +++ b/src/api/common/add-file-to-drive.ts @@ -144,11 +144,10 @@ export default ( } // Create DriveFile document - const file = await addToGridFS(`${user._id}/${name}`, data, { + const file = await addToGridFS(name, data, { user_id: user._id, folder_id: folder !== null ? folder._id : null, type: mime, - name: name, comment: comment, properties: properties }); diff --git a/src/api/endpoints/drive/files/find.ts b/src/api/endpoints/drive/files/find.ts index 1c818131d..a1cdf1643 100644 --- a/src/api/endpoints/drive/files/find.ts +++ b/src/api/endpoints/drive/files/find.ts @@ -24,7 +24,7 @@ module.exports = (params, user) => new Promise(async (res, rej) => { // Issue query const files = await DriveFile .find({ - 'metadata.name': name, + filename: name, 'metadata.user_id': user._id, 'metadata.folder_id': folderId }); diff --git a/src/api/endpoints/drive/files/update.ts b/src/api/endpoints/drive/files/update.ts index d7b858c2b..f265142c4 100644 --- a/src/api/endpoints/drive/files/update.ts +++ b/src/api/endpoints/drive/files/update.ts @@ -34,7 +34,7 @@ module.exports = (params, user) => new Promise(async (res, rej) => { // Get 'name' parameter const [name, nameErr] = $(params.name).optional.string().pipe(validateFileName).$; if (nameErr) return rej('invalid name param'); - if (name) file.metadata.name = name; + if (name) file.filename = name; // Get 'folder_id' parameter const [folderId, folderIdErr] = $(params.folder_id).optional.nullable.id().$; @@ -61,7 +61,7 @@ module.exports = (params, user) => new Promise(async (res, rej) => { await DriveFile.update(file._id, { $set: { - 'metadata.name': file.metadata.name, + filename: file.filename, 'metadata.folder_id': file.metadata.folder_id } }); diff --git a/src/api/serializers/drive-file.ts b/src/api/serializers/drive-file.ts index 2af7db572..57b74cd97 100644 --- a/src/api/serializers/drive-file.ts +++ b/src/api/serializers/drive-file.ts @@ -47,6 +47,7 @@ export default ( _target.id = _file._id; _target.created_at = _file.uploadDate; + _target.name = _file.filename; _target = Object.assign(_target, _file.metadata); diff --git a/src/file/server.ts b/src/file/server.ts index 1152b650b..39c2cdd2a 100644 --- a/src/file/server.ts +++ b/src/file/server.ts @@ -97,7 +97,7 @@ async function sendFileById(req: express.Request, res: express.Response): Promis const file = await DriveFile.findOne({ _id: fileId }); // validate name - if (req.params.name !== undefined && req.params.name !== file.metadata.name) { + if (req.params.name !== undefined && req.params.name !== file.filename) { res.status(404).send('there is no file has given name'); return; } diff --git a/tools/migration/use-gridfs.js b/tools/migration/use-gridfs.js index d41514416..148f9be26 100644 --- a/tools/migration/use-gridfs.js +++ b/tools/migration/use-gridfs.js @@ -21,15 +21,17 @@ const migrateToGridFS = async (doc) => { const id = doc._id const buffer = doc.data.buffer const created_at = doc.created_at + const name = doc.name delete doc._id delete doc.created_at delete doc.datasize delete doc.hash delete doc.data + delete doc.name const bucket = await getGridFSBucket() - const added = await writeToGridFS(bucket, buffer, id, `${id}/${doc.name}`, { metadata: doc }) + const added = await writeToGridFS(bucket, buffer, id, name, { metadata: doc }) const result = await DriveFile.update(id, { $set: { From d24990a4908430016e23da148291e9cf8f0316e0 Mon Sep 17 00:00:00 2001 From: otofune Date: Tue, 7 Nov 2017 09:47:59 +0900 Subject: [PATCH 077/327] test - remove unneed async wrappings, drop GridFS drive_file correctly --- test/api.js | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/test/api.js b/test/api.js index c0da9d6c5..7e26dfe07 100644 --- a/test/api.js +++ b/test/api.js @@ -46,7 +46,8 @@ describe('API', () => { beforeEach(() => Promise.all([ db.get('users').drop(), db.get('posts').drop(), - db.get('drive_files').drop(), + db.get('drive_files.files').drop(), + db.get('drive_files.chunks').drop(), db.get('drive_folders').drop(), db.get('apps').drop(), db.get('access_tokens').drop(), @@ -1131,8 +1132,8 @@ describe('API', () => { }); }); -async function insertSakurako(opts) { - return await db.get('users').insert(Object.assign({ +function insertSakurako(opts) { + return db.get('users').insert(Object.assign({ token: '!00000000000000000000000000000000', username: 'sakurako', username_lower: 'sakurako', @@ -1141,8 +1142,8 @@ async function insertSakurako(opts) { }, opts)); } -async function insertHimawari(opts) { - return await db.get('users').insert(Object.assign({ +function insertHimawari(opts) { + return db.get('users').insert(Object.assign({ token: '!00000000000000000000000000000001', username: 'himawari', username_lower: 'himawari', @@ -1151,8 +1152,8 @@ async function insertHimawari(opts) { }, opts)); } -async function insertDriveFile(opts) { - return await db.get('drive_files.files').insert({ +function insertDriveFile(opts) { + return db.get('drive_files.files').insert({ length: opts.datasize, metadata: Object.assign({ name: 'strawberry-pasta.png' @@ -1160,15 +1161,15 @@ async function insertDriveFile(opts) { }); } -async function insertDriveFolder(opts) { - return await db.get('drive_folders').insert(Object.assign({ +function insertDriveFolder(opts) { + return db.get('drive_folders').insert(Object.assign({ name: 'my folder', parent_id: null }, opts)); } -async function insertApp(opts) { - return await db.get('apps').insert(Object.assign({ +function insertApp(opts) { + return db.get('apps').insert(Object.assign({ name: 'my app', secret: 'mysecret' }, opts)); From 3dd517f7fd27dc90da873ea10d40eb5b44e9b5fd Mon Sep 17 00:00:00 2001 From: otofune Date: Tue, 7 Nov 2017 09:49:48 +0900 Subject: [PATCH 078/327] gulpfile - shutdown mocha after test run see: - http://mochajs.org/#usage - https://boneskull.com/mocha-v4-nears-release/#mochawontforceexit --- gulpfile.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/gulpfile.ts b/gulpfile.ts index 04bd2b1c4..93002cbf3 100644 --- a/gulpfile.ts +++ b/gulpfile.ts @@ -93,6 +93,7 @@ gulp.src('./src/**/*.ts') gulp.task('mocha', () => gulp.src([]) .pipe(mocha({ + exit: true //compilers: 'ts:ts-node/register' } as any)) ); From a0c3cb2c6ed2f69eafd710e666ec795a8f8c1c5c Mon Sep 17 00:00:00 2001 From: otofune Date: Tue, 7 Nov 2017 09:58:02 +0900 Subject: [PATCH 079/327] migration - add migration to support changed filename usage --- ...change-gridfs-metadata-name-to-filename.js | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 tools/migration/change-gridfs-metadata-name-to-filename.js diff --git a/tools/migration/change-gridfs-metadata-name-to-filename.js b/tools/migration/change-gridfs-metadata-name-to-filename.js new file mode 100644 index 000000000..0d9e977c6 --- /dev/null +++ b/tools/migration/change-gridfs-metadata-name-to-filename.js @@ -0,0 +1,30 @@ +// for Node.js interpret +/** + * change usage of GridFS filename + * see commit fb422b4d603c53a70712caba55b35a48a8c2e619 + */ + +const { default: DriveFile } = require('../../built/api/models/drive-file') + +async function applyNewChange (doc) { + const result = await DriveFile.update(doc._id, { + $set: { + filename: doc.metadata.name + }, + $unset: { + 'metadata.name': '' + } + }) + return result.ok === 1 +} + +async function main () { + const oldTypeDocs = await DriveFile.find({ + 'metadata.name': { + $exists: true + } + }) + return await Promise.all(oldTypeDocs.map(applyNewChange)) +} + +main().then(console.dir).catch(console.error) From 1e58cf1dc7f52d9ed26a175783b24f50174d3669 Mon Sep 17 00:00:00 2001 From: otofune Date: Tue, 7 Nov 2017 09:59:58 +0900 Subject: [PATCH 080/327] test - fix insertDriveFile (use GridFS filename) --- test/api.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/test/api.js b/test/api.js index 7e26dfe07..a2eaa4e62 100644 --- a/test/api.js +++ b/test/api.js @@ -1155,9 +1155,8 @@ function insertHimawari(opts) { function insertDriveFile(opts) { return db.get('drive_files.files').insert({ length: opts.datasize, - metadata: Object.assign({ - name: 'strawberry-pasta.png' - }, opts) + filename: 'strawberry-pasta.png', + metadata: opts }); } From 816728d4caa874d356f535ec9a52a51714a621e4 Mon Sep 17 00:00:00 2001 From: syuilo Date: Tue, 7 Nov 2017 12:08:44 +0900 Subject: [PATCH 081/327] Disable minification due to artifacts --- webpack/plugins/index.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/webpack/plugins/index.ts b/webpack/plugins/index.ts index 345af7df9..d37047b67 100644 --- a/webpack/plugins/index.ts +++ b/webpack/plugins/index.ts @@ -2,7 +2,7 @@ const StringReplacePlugin = require('string-replace-webpack-plugin'); import constant from './const'; import hoist from './hoist'; -import minify from './minify'; +//import minify from './minify'; import banner from './banner'; const env = process.env.NODE_ENV; @@ -16,7 +16,7 @@ export default (version, lang) => { ]; if (isProduction) { - plugins.push(minify()); + //plugins.push(minify()); } plugins.push(banner(version)); From c574f5ac7df8a841d2deaf16a49da04f14293b9c Mon Sep 17 00:00:00 2001 From: syuilo Date: Tue, 7 Nov 2017 12:11:52 +0900 Subject: [PATCH 082/327] v2944 --- CHANGELOG.md | 6 ++++++ package.json | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f8018e4e2..cfafcc3b6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,12 @@ ChangeLog (Release Notes) ========================= 主に notable な changes を書いていきます +2944 (2017/11/07) +----------------- +* パフォーマンスの向上 + * GirdFSになるなどした +* 依存関係の更新 + 2807 (2017/11/02) ----------------- * いい感じに diff --git a/package.json b/package.json index 21f2c57de..cf291fe2b 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "misskey", "author": "syuilo ", - "version": "0.0.2807", + "version": "0.0.2944", "license": "MIT", "description": "A miniblog-based SNS", "bugs": "https://github.com/syuilo/misskey/issues", From 07b90b2355467fb8854b754535367ee07a5a3596 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=81=93=E3=81=B4=E3=81=AA=E3=81=9F=E3=81=BF=E3=81=BD?= Date: Tue, 7 Nov 2017 18:47:23 +0900 Subject: [PATCH 083/327] Fix bug MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit アップロードのバグなのか知らないけどなぜか data が存在しない drive_file ドキュメントがまれにあることがわかったので --- tools/migration/use-gridfs.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/migration/use-gridfs.js b/tools/migration/use-gridfs.js index 148f9be26..f13d3c874 100644 --- a/tools/migration/use-gridfs.js +++ b/tools/migration/use-gridfs.js @@ -19,7 +19,7 @@ const writeToGridFS = (bucket, buffer, ...rest) => new Promise((resolve, reject) const migrateToGridFS = async (doc) => { const id = doc._id - const buffer = doc.data.buffer + const buffer = doc.data ? doc.data.buffer : Buffer.from([0x00]) // アップロードのバグなのか知らないけどなぜか data が存在しない drive_file ドキュメントがまれにあることがわかったので const created_at = doc.created_at const name = doc.name From f929c984e373916e99804f915e3c4e1bf1ba9490 Mon Sep 17 00:00:00 2001 From: syuilo Date: Tue, 7 Nov 2017 19:17:42 +0900 Subject: [PATCH 084/327] Better memory usage --- tools/migration/use-gridfs.js | 30 +++++++++++++++++++++++++----- 1 file changed, 25 insertions(+), 5 deletions(-) diff --git a/tools/migration/use-gridfs.js b/tools/migration/use-gridfs.js index f13d3c874..313b10859 100644 --- a/tools/migration/use-gridfs.js +++ b/tools/migration/use-gridfs.js @@ -6,7 +6,7 @@ const { Duplex } = require('stream') const writeToGridFS = (bucket, buffer, ...rest) => new Promise((resolve, reject) => { const writeStream = bucket.openUploadStreamWithId(...rest) - + const dataStream = new Duplex() dataStream.push(buffer) dataStream.push(null) @@ -42,10 +42,30 @@ const migrateToGridFS = async (doc) => { return added && result.ok === 1 } -const main = async () => { - const docs = await db.get('drive_files').find() - const all = await Promise.all(docs.map(migrateToGridFS)) - return all +async function main() { + let i = 0; + + const count = db.get('drive_files').count; + + const iterate = async () => { + if (i == count) return true; + const doc = await db.get('drive_files').find({}, { skip: i }) + const res = await migrateToGridFS(doc); + if (!res) { + return false; + } else { + i++ + return await iterate(); + } + } + + const res = await iterate(); + + if (res) { + return 'ok'; + } else { + throw 'something happened'; + } } main().then(console.dir).catch(console.error) From a47015e5824f5bc413d30c483c0d96727e92c31e Mon Sep 17 00:00:00 2001 From: syuilo Date: Tue, 7 Nov 2017 19:19:19 +0900 Subject: [PATCH 085/327] Fix bug --- tools/migration/use-gridfs.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/migration/use-gridfs.js b/tools/migration/use-gridfs.js index 313b10859..02c0b2f6a 100644 --- a/tools/migration/use-gridfs.js +++ b/tools/migration/use-gridfs.js @@ -49,7 +49,7 @@ async function main() { const iterate = async () => { if (i == count) return true; - const doc = await db.get('drive_files').find({}, { skip: i }) + const doc = await db.get('drive_files').find({}, { limit: 1, skip: i }) const res = await migrateToGridFS(doc); if (!res) { return false; From c78d30f50023fdbd0559209ec9bc7445287dc170 Mon Sep 17 00:00:00 2001 From: syuilo Date: Tue, 7 Nov 2017 19:27:02 +0900 Subject: [PATCH 086/327] Fix bug --- tools/migration/use-gridfs.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/migration/use-gridfs.js b/tools/migration/use-gridfs.js index 02c0b2f6a..4401e8301 100644 --- a/tools/migration/use-gridfs.js +++ b/tools/migration/use-gridfs.js @@ -45,7 +45,7 @@ const migrateToGridFS = async (doc) => { async function main() { let i = 0; - const count = db.get('drive_files').count; + const count = await db.get('drive_files').count({}); const iterate = async () => { if (i == count) return true; From 10eee32035d9afbb20d2676899f7b0bd8d213adf Mon Sep 17 00:00:00 2001 From: syuilo Date: Tue, 7 Nov 2017 19:33:54 +0900 Subject: [PATCH 087/327] Fix bug --- tools/migration/use-gridfs.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/migration/use-gridfs.js b/tools/migration/use-gridfs.js index 4401e8301..804f2aa27 100644 --- a/tools/migration/use-gridfs.js +++ b/tools/migration/use-gridfs.js @@ -49,7 +49,7 @@ async function main() { const iterate = async () => { if (i == count) return true; - const doc = await db.get('drive_files').find({}, { limit: 1, skip: i }) + const doc = (await db.get('drive_files').find({}, { limit: 1, skip: i }))[0] const res = await migrateToGridFS(doc); if (!res) { return false; From 823a3d765e433cdf85db039b5fa01b3cca5b6f81 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=81=93=E3=81=B4=E3=81=AA=E3=81=9F=E3=81=BF=E3=81=BD?= Date: Tue, 7 Nov 2017 19:42:29 +0900 Subject: [PATCH 088/327] Display progress --- tools/migration/use-gridfs.js | 1 + 1 file changed, 1 insertion(+) diff --git a/tools/migration/use-gridfs.js b/tools/migration/use-gridfs.js index 804f2aa27..c5883e456 100644 --- a/tools/migration/use-gridfs.js +++ b/tools/migration/use-gridfs.js @@ -49,6 +49,7 @@ async function main() { const iterate = async () => { if (i == count) return true; + console.log(`${i} / ${count}`); const doc = (await db.get('drive_files').find({}, { limit: 1, skip: i }))[0] const res = await migrateToGridFS(doc); if (!res) { From 934debd68e5943ccf360a0a11011cb23c540ef99 Mon Sep 17 00:00:00 2001 From: syuilo Date: Tue, 7 Nov 2017 21:04:32 +0900 Subject: [PATCH 089/327] #882 --- src/api/common/add-file-to-drive.ts | 7 ++--- src/api/serializers/drive-file.ts | 1 + tools/migration/issue_882.js | 44 +++++++++++++++++++++++++++++ tools/migration/use-gridfs.js | 4 ++- 4 files changed, 51 insertions(+), 5 deletions(-) create mode 100644 tools/migration/issue_882.js diff --git a/src/api/common/add-file-to-drive.ts b/src/api/common/add-file-to-drive.ts index e1baf0819..a96906d29 100644 --- a/src/api/common/add-file-to-drive.ts +++ b/src/api/common/add-file-to-drive.ts @@ -13,13 +13,13 @@ import { Duplex } from 'stream'; const log = debug('misskey:register-drive-file'); -const addToGridFS = (name, binary, metadata): Promise => new Promise(async (resolve, reject) => { +const addToGridFS = (name, binary, type, metadata): Promise => new Promise(async (resolve, reject) => { const dataStream = new Duplex(); dataStream.push(binary); dataStream.push(null); const bucket = await getGridFSBucket(); - const writeStream = bucket.openUploadStream(name, { metadata }); + const writeStream = bucket.openUploadStream(name, { contentType: type, metadata }); writeStream.once('finish', (doc) => { resolve(doc); }); writeStream.on('error', reject); dataStream.pipe(writeStream); @@ -144,10 +144,9 @@ export default ( } // Create DriveFile document - const file = await addToGridFS(name, data, { + const file = await addToGridFS(name, data, mime, { user_id: user._id, folder_id: folder !== null ? folder._id : null, - type: mime, comment: comment, properties: properties }); diff --git a/src/api/serializers/drive-file.ts b/src/api/serializers/drive-file.ts index 57b74cd97..3b76979a4 100644 --- a/src/api/serializers/drive-file.ts +++ b/src/api/serializers/drive-file.ts @@ -48,6 +48,7 @@ export default ( _target.id = _file._id; _target.created_at = _file.uploadDate; _target.name = _file.filename; + _target.type = _file.contentType; _target = Object.assign(_target, _file.metadata); diff --git a/tools/migration/issue_882.js b/tools/migration/issue_882.js new file mode 100644 index 000000000..67a1551e0 --- /dev/null +++ b/tools/migration/issue_882.js @@ -0,0 +1,44 @@ +// for Node.js interpret + +const { default: DriveFile } = require('../../built/api/models/drive-file') + +const migrate = async (doc) => { + const result = await DriveFile.update(doc._id, { + $set: { + contentType: doc.metadata.type + }, + $unset: { + 'metadata.type': '' + } + }) + return result.ok === 1 +} + +async function main() { + let i = 0; + + const count = await db.get('drive_files').count({}); + + const iterate = async () => { + if (i == count) return true; + console.log(`${i} / ${count}`); + const doc = (await db.get('drive_files').find({}, { limit: 1, skip: i }))[0] + const res = await migrate(doc); + if (!res) { + return false; + } else { + i++ + return await iterate(); + } + } + + const res = await iterate(); + + if (res) { + return 'ok'; + } else { + throw 'something happened'; + } +} + +main().then(console.dir).catch(console.error) diff --git a/tools/migration/use-gridfs.js b/tools/migration/use-gridfs.js index c5883e456..106cbd388 100644 --- a/tools/migration/use-gridfs.js +++ b/tools/migration/use-gridfs.js @@ -22,6 +22,7 @@ const migrateToGridFS = async (doc) => { const buffer = doc.data ? doc.data.buffer : Buffer.from([0x00]) // アップロードのバグなのか知らないけどなぜか data が存在しない drive_file ドキュメントがまれにあることがわかったので const created_at = doc.created_at const name = doc.name + const type = doc.type delete doc._id delete doc.created_at @@ -29,9 +30,10 @@ const migrateToGridFS = async (doc) => { delete doc.hash delete doc.data delete doc.name + delete doc.type const bucket = await getGridFSBucket() - const added = await writeToGridFS(bucket, buffer, id, name, { metadata: doc }) + const added = await writeToGridFS(bucket, buffer, id, name, { contentType: type, metadata: doc }) const result = await DriveFile.update(id, { $set: { From f2fc1348397e5d86805f0446d1b32e29ddf56394 Mon Sep 17 00:00:00 2001 From: syuilo Date: Tue, 7 Nov 2017 21:12:08 +0900 Subject: [PATCH 090/327] Fix bug --- tools/migration/issue_882.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/migration/issue_882.js b/tools/migration/issue_882.js index 67a1551e0..8dab9bb43 100644 --- a/tools/migration/issue_882.js +++ b/tools/migration/issue_882.js @@ -17,12 +17,12 @@ const migrate = async (doc) => { async function main() { let i = 0; - const count = await db.get('drive_files').count({}); + const count = await DriveFile.count({}); const iterate = async () => { if (i == count) return true; console.log(`${i} / ${count}`); - const doc = (await db.get('drive_files').find({}, { limit: 1, skip: i }))[0] + const doc = (await DriveFile.find({}, { limit: 1, skip: i }))[0] const res = await migrate(doc); if (!res) { return false; From 5696f19a60412e5f7ed53012ec32e566bb52eab2 Mon Sep 17 00:00:00 2001 From: syuilo Date: Tue, 7 Nov 2017 21:16:13 +0900 Subject: [PATCH 091/327] Fix bug --- src/file/server.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/file/server.ts b/src/file/server.ts index 39c2cdd2a..2007667a8 100644 --- a/src/file/server.ts +++ b/src/file/server.ts @@ -120,7 +120,7 @@ async function sendFileById(req: express.Request, res: express.Response): Promis }); }))(fileId); - send(buffer, file.metadata.type, req, res); + send(buffer, file.contentType, req, res); } /** From 2446dbc3339f91152d533a423a64170178722c3d Mon Sep 17 00:00:00 2001 From: syuilo Date: Tue, 7 Nov 2017 21:23:09 +0900 Subject: [PATCH 092/327] :v: --- src/file/assets/not-an-image.png | 3 +++ src/file/server.ts | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) create mode 100644 src/file/assets/not-an-image.png diff --git a/src/file/assets/not-an-image.png b/src/file/assets/not-an-image.png new file mode 100644 index 000000000..cfbc04fcc --- /dev/null +++ b/src/file/assets/not-an-image.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:bc2bc9656bc98009e2e7b58959a4ce2a0ecbd3ec00519118e8b2a0eca0356d9c +size 4711 diff --git a/src/file/server.ts b/src/file/server.ts index 2007667a8..449fa2d74 100644 --- a/src/file/server.ts +++ b/src/file/server.ts @@ -54,7 +54,7 @@ async function raw(data: Buffer, type: string, download: boolean, res: express.R async function thumbnail(data: Buffer, type: string, resize: number, res: express.Response): Promise { if (!/^image\/.*$/.test(type)) { - data = fs.readFileSync(`${__dirname}/assets/dummy.png`); + data = fs.readFileSync(`${__dirname}/assets/not-an-image.png`); } let g = gm(data); From fba613883df2935937a27690ebc2b44eddf03ffd Mon Sep 17 00:00:00 2001 From: otofune Date: Tue, 7 Nov 2017 22:08:21 +0900 Subject: [PATCH 093/327] run parallely --- package.json | 1 + tools/migration/use-gridfs.js | 33 +++++++++++---------------------- 2 files changed, 12 insertions(+), 22 deletions(-) diff --git a/package.json b/package.json index cf291fe2b..96831a3c4 100644 --- a/package.json +++ b/package.json @@ -22,6 +22,7 @@ "format": "gulp format" }, "devDependencies": { + "@prezzemolo/zip": "0.0.3", "@types/bcryptjs": "2.4.1", "@types/body-parser": "1.16.7", "@types/chai": "4.0.4", diff --git a/tools/migration/use-gridfs.js b/tools/migration/use-gridfs.js index 106cbd388..228943f49 100644 --- a/tools/migration/use-gridfs.js +++ b/tools/migration/use-gridfs.js @@ -3,6 +3,7 @@ const { default: db } = require('../../built/db/mongodb') const { default: DriveFile, getGridFSBucket } = require('../../built/api/models/drive-file') const { Duplex } = require('stream') +const { default: zip } = require('@prezzemolo/zip') const writeToGridFS = (bucket, buffer, ...rest) => new Promise((resolve, reject) => { const writeStream = bucket.openUploadStreamWithId(...rest) @@ -45,30 +46,18 @@ const migrateToGridFS = async (doc) => { } async function main() { - let i = 0; + const count = await DriveFile.count({}); - const count = await db.get('drive_files').count({}); + const dop = Number.parseInt(process.argv[2]) || 5 - const iterate = async () => { - if (i == count) return true; - console.log(`${i} / ${count}`); - const doc = (await db.get('drive_files').find({}, { limit: 1, skip: i }))[0] - const res = await migrateToGridFS(doc); - if (!res) { - return false; - } else { - i++ - return await iterate(); - } - } - - const res = await iterate(); - - if (res) { - return 'ok'; - } else { - throw 'something happened'; - } + return zip( + 1, + async (time) => { + const doc = await DriveFile.find({}, { limit: dop, skip: time * dop }) + return Promise.all(doc.map(migrateToGridFS)) + }, + ((count - (count % dop)) / dop) + 1 + ) } main().then(console.dir).catch(console.error) From 402d70e74fc218b6401548ca4f5f7f315b162ae3 Mon Sep 17 00:00:00 2001 From: otofune Date: Tue, 7 Nov 2017 22:39:17 +0900 Subject: [PATCH 094/327] fix --- tools/migration/use-gridfs.js | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/tools/migration/use-gridfs.js b/tools/migration/use-gridfs.js index 228943f49..bb7070f55 100644 --- a/tools/migration/use-gridfs.js +++ b/tools/migration/use-gridfs.js @@ -48,16 +48,24 @@ const migrateToGridFS = async (doc) => { async function main() { const count = await DriveFile.count({}); + console.log(`there are ${count} files.`) + const dop = Number.parseInt(process.argv[2]) || 5 + const idop = ((count - (count % dop)) / dop) + 1 return zip( 1, async (time) => { - const doc = await DriveFile.find({}, { limit: dop, skip: time * dop }) + console.log(`${time} / ${idop}`) + const doc = await db.get('drive_files').find({}, { limit: dop, skip: time * dop }) return Promise.all(doc.map(migrateToGridFS)) }, - ((count - (count % dop)) / dop) + 1 - ) + idop + ).then(a => { + const rv = [] + a.forEach(e => rv.push(...e)) + return rv + }) } main().then(console.dir).catch(console.error) From 8424a0d61c0342c43b1481aa8ddd55adc4010cab Mon Sep 17 00:00:00 2001 From: otofune Date: Tue, 7 Nov 2017 22:57:48 +0900 Subject: [PATCH 095/327] fix --- tools/migration/use-gridfs.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/migration/use-gridfs.js b/tools/migration/use-gridfs.js index bb7070f55..a9d2b12e9 100644 --- a/tools/migration/use-gridfs.js +++ b/tools/migration/use-gridfs.js @@ -46,7 +46,7 @@ const migrateToGridFS = async (doc) => { } async function main() { - const count = await DriveFile.count({}); + const count = await db.get('drive_files').count({}); console.log(`there are ${count} files.`) From 0a7e60f342c0459f132e391d8b302ae7add82abc Mon Sep 17 00:00:00 2001 From: syuilo Date: Tue, 7 Nov 2017 23:09:15 +0900 Subject: [PATCH 096/327] #860 --- tools/migration/README.md | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 tools/migration/README.md diff --git a/tools/migration/README.md b/tools/migration/README.md new file mode 100644 index 000000000..266be9240 --- /dev/null +++ b/tools/migration/README.md @@ -0,0 +1,4 @@ +Misskeyの破壊的変更に対応するいくつかのスニペットがあります。 +MongoDBシェルで実行する必要のあるものとnodeで直接実行する必要のあるものがあります。 + +MongoDBシェルで実行する場合、`use`でデータベースを選択しておく必要があります。 From fd3aeb969b1608ab7bd78ea033d352e666020e95 Mon Sep 17 00:00:00 2001 From: otofune Date: Tue, 7 Nov 2017 23:10:38 +0900 Subject: [PATCH 097/327] change all migrations to parallely --- ...change-gridfs-metadata-name-to-filename.js | 24 ++++++++++- tools/migration/issue_882.js | 43 ++++++++++--------- 2 files changed, 45 insertions(+), 22 deletions(-) diff --git a/tools/migration/change-gridfs-metadata-name-to-filename.js b/tools/migration/change-gridfs-metadata-name-to-filename.js index 0d9e977c6..9128d852c 100644 --- a/tools/migration/change-gridfs-metadata-name-to-filename.js +++ b/tools/migration/change-gridfs-metadata-name-to-filename.js @@ -19,12 +19,32 @@ async function applyNewChange (doc) { } async function main () { - const oldTypeDocs = await DriveFile.find({ + const query = { 'metadata.name': { $exists: true } + } + + const count = await DriveFile.count(query) + + const dop = Number.parseInt(process.argv[2]) || 5 + const idop = ((count - (count % dop)) / dop) + 1 + + return zip( + 1, + async (time) => { + console.log(`${time} / ${idop}`) + const doc = await db.get('drive_files').find(query, { + limit: dop, skip: time * dop + }) + return Promise.all(doc.map(applyNewChange)) + }, + idop + ).then(a => { + const rv = [] + a.forEach(e => rv.push(...e)) + return rv }) - return await Promise.all(oldTypeDocs.map(applyNewChange)) } main().then(console.dir).catch(console.error) diff --git a/tools/migration/issue_882.js b/tools/migration/issue_882.js index 8dab9bb43..aa1141325 100644 --- a/tools/migration/issue_882.js +++ b/tools/migration/issue_882.js @@ -1,6 +1,7 @@ // for Node.js interpret const { default: DriveFile } = require('../../built/api/models/drive-file') +const { default: zip } = require('@prezzemolo/zip') const migrate = async (doc) => { const result = await DriveFile.update(doc._id, { @@ -15,30 +16,32 @@ const migrate = async (doc) => { } async function main() { - let i = 0; - - const count = await DriveFile.count({}); - - const iterate = async () => { - if (i == count) return true; - console.log(`${i} / ${count}`); - const doc = (await DriveFile.find({}, { limit: 1, skip: i }))[0] - const res = await migrate(doc); - if (!res) { - return false; - } else { - i++ - return await iterate(); + const query = { + 'metadata.type': { + $exists: true } } - const res = await iterate(); + const count = await DriveFile.count(query); - if (res) { - return 'ok'; - } else { - throw 'something happened'; - } + const dop = Number.parseInt(process.argv[2]) || 5 + const idop = ((count - (count % dop)) / dop) + 1 + + return zip( + 1, + async (time) => { + console.log(`${time} / ${idop}`) + const doc = await db.get('drive_files').find(query, { + limit: dop, skip: time * dop + }) + return Promise.all(doc.map(migrate)) + }, + idop + ).then(a => { + const rv = [] + a.forEach(e => rv.push(...e)) + return rv + }) } main().then(console.dir).catch(console.error) From 337f81e32a88d6354cafb72a0f0d4ba59254b3cb Mon Sep 17 00:00:00 2001 From: syuilo Date: Tue, 7 Nov 2017 23:21:54 +0900 Subject: [PATCH 098/327] :v: --- tools/migration/README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tools/migration/README.md b/tools/migration/README.md index 266be9240..cd553efb9 100644 --- a/tools/migration/README.md +++ b/tools/migration/README.md @@ -2,3 +2,7 @@ Misskeyの破壊的変更に対応するいくつかのスニペットがあり MongoDBシェルで実行する必要のあるものとnodeで直接実行する必要のあるものがあります。 MongoDBシェルで実行する場合、`use`でデータベースを選択しておく必要があります。 + +nodeで実行するいくつかのスニペットは、並列処理させる数を引数で設定できるものがあります。 +処理中にエラーで落ちる場合は、メモリが足りていない可能性があるので、少ない数に設定してみてください。 +※デフォルトは`5`です。 From 072ff53a73f119598289cfe76292787ddc3354c5 Mon Sep 17 00:00:00 2001 From: otofune Date: Tue, 7 Nov 2017 23:38:18 +0900 Subject: [PATCH 099/327] rename with execution order, add desc & initial creation script --- tools/init-migration-file.sh | 37 +++++++++++++++++++ tools/migration/README.md | 3 ++ ...ridfs.js => node.1509958623.use-gridfs.js} | 0 ...hange-gridfs-metadata-name-to-filename.js} | 0 ...ue_882.js => node.1510056272.issue_882.js} | 0 ...le.js => shell.1487734995.user-profile.js} | 0 ... => shell.1489951459.like-to-reactions.js} | 0 ... => shell.1509507382.reply_to-to-reply.js} | 0 8 files changed, 40 insertions(+) create mode 100755 tools/init-migration-file.sh rename tools/migration/{use-gridfs.js => node.1509958623.use-gridfs.js} (100%) rename tools/migration/{change-gridfs-metadata-name-to-filename.js => node.1510016282.change-gridfs-metadata-name-to-filename.js} (100%) rename tools/migration/{issue_882.js => node.1510056272.issue_882.js} (100%) rename tools/migration/{user-profile.js => shell.1487734995.user-profile.js} (100%) rename tools/migration/{like-to-reactions.js => shell.1489951459.like-to-reactions.js} (100%) rename tools/migration/{reply_to-to-reply.js => shell.1509507382.reply_to-to-reply.js} (100%) diff --git a/tools/init-migration-file.sh b/tools/init-migration-file.sh new file mode 100755 index 000000000..c6a2b862e --- /dev/null +++ b/tools/init-migration-file.sh @@ -0,0 +1,37 @@ +#!/bin/bash + +usage() { + echo "$0 [-t type] [-n name]" + echo " type: [node | shell]" + echo " name: if no present, set untitled" + exit 0 +} + +while getopts :t:n:h OPT +do + case $OPT in + t) type=$OPTARG + ;; + n) name=$OPTARG + ;; + h) usage + ;; + \?) usage + ;; + :) usage + ;; + esac +done + +if [ "$type" = "" ] +then + echo "no type present!!!" + usage +fi + +if [ "$name" = "" ] +then + name="untitled" +fi + +touch "$(realpath $(dirname $BASH_SOURCE))/migration/$type.$(date +%s).$name.js" diff --git a/tools/migration/README.md b/tools/migration/README.md index cd553efb9..d52e84b35 100644 --- a/tools/migration/README.md +++ b/tools/migration/README.md @@ -1,8 +1,11 @@ Misskeyの破壊的変更に対応するいくつかのスニペットがあります。 MongoDBシェルで実行する必要のあるものとnodeで直接実行する必要のあるものがあります。 +ファイル名が `shell.` から始まるものは前者、 `node.` から始まるものは後者です。 MongoDBシェルで実行する場合、`use`でデータベースを選択しておく必要があります。 nodeで実行するいくつかのスニペットは、並列処理させる数を引数で設定できるものがあります。 処理中にエラーで落ちる場合は、メモリが足りていない可能性があるので、少ない数に設定してみてください。 ※デフォルトは`5`です。 + +ファイルを作成する際は `../init-migration-file.sh -t _type_ -n _name_` を実行すると _type_._unixtime_._name_.js が生成されます diff --git a/tools/migration/use-gridfs.js b/tools/migration/node.1509958623.use-gridfs.js similarity index 100% rename from tools/migration/use-gridfs.js rename to tools/migration/node.1509958623.use-gridfs.js diff --git a/tools/migration/change-gridfs-metadata-name-to-filename.js b/tools/migration/node.1510016282.change-gridfs-metadata-name-to-filename.js similarity index 100% rename from tools/migration/change-gridfs-metadata-name-to-filename.js rename to tools/migration/node.1510016282.change-gridfs-metadata-name-to-filename.js diff --git a/tools/migration/issue_882.js b/tools/migration/node.1510056272.issue_882.js similarity index 100% rename from tools/migration/issue_882.js rename to tools/migration/node.1510056272.issue_882.js diff --git a/tools/migration/user-profile.js b/tools/migration/shell.1487734995.user-profile.js similarity index 100% rename from tools/migration/user-profile.js rename to tools/migration/shell.1487734995.user-profile.js diff --git a/tools/migration/like-to-reactions.js b/tools/migration/shell.1489951459.like-to-reactions.js similarity index 100% rename from tools/migration/like-to-reactions.js rename to tools/migration/shell.1489951459.like-to-reactions.js diff --git a/tools/migration/reply_to-to-reply.js b/tools/migration/shell.1509507382.reply_to-to-reply.js similarity index 100% rename from tools/migration/reply_to-to-reply.js rename to tools/migration/shell.1509507382.reply_to-to-reply.js From 1a469ed4cd573a95bfc1d988d0e00e0df62ab89f Mon Sep 17 00:00:00 2001 From: syuilo Date: Wed, 8 Nov 2017 14:43:42 +0900 Subject: [PATCH 100/327] Fix bugs --- src/api/endpoints/drive/stream.ts | 5 +---- src/api/serializers/drive-file.ts | 2 ++ src/web/app/mobile/tags/drive/file-viewer.tag | 2 +- 3 files changed, 4 insertions(+), 5 deletions(-) diff --git a/src/api/endpoints/drive/stream.ts b/src/api/endpoints/drive/stream.ts index 32f7ac7e0..58e7d1167 100644 --- a/src/api/endpoints/drive/stream.ts +++ b/src/api/endpoints/drive/stream.ts @@ -52,15 +52,12 @@ module.exports = (params, user) => new Promise(async (res, rej) => { }; } if (type) { - query.type = new RegExp(`^${type.replace(/\*/g, '.+?')}$`); + query.contentType = new RegExp(`^${type.replace(/\*/g, '.+?')}$`); } // Issue query const files = await DriveFile .find(query, { - fields: { - data: false - }, limit: limit, sort: sort }); diff --git a/src/api/serializers/drive-file.ts b/src/api/serializers/drive-file.ts index 3b76979a4..dcdaa01fa 100644 --- a/src/api/serializers/drive-file.ts +++ b/src/api/serializers/drive-file.ts @@ -49,6 +49,8 @@ export default ( _target.created_at = _file.uploadDate; _target.name = _file.filename; _target.type = _file.contentType; + _target.datasize = _file.length; + _target.md5 = _file.md5; _target = Object.assign(_target, _file.metadata); diff --git a/src/web/app/mobile/tags/drive/file-viewer.tag b/src/web/app/mobile/tags/drive/file-viewer.tag index e6129652b..8dc49a086 100644 --- a/src/web/app/mobile/tags/drive/file-viewer.tag +++ b/src/web/app/mobile/tags/drive/file-viewer.tag @@ -44,7 +44,7 @@

%i18n:mobile.tags.mk-drive-file-viewer.hash%

- { file.hash } + { file.md5 } + + diff --git a/src/web/app/desktop/tags/pages/selectdrive.tag b/src/web/app/desktop/tags/pages/selectdrive.tag index 63fc588fa..9c3ac16eb 100644 --- a/src/web/app/desktop/tags/pages/selectdrive.tag +++ b/src/web/app/desktop/tags/pages/selectdrive.tag @@ -1,15 +1,16 @@
- - - + + +
diff --git a/src/web/app/desktop/tags/index.js b/src/web/app/desktop/tags/index.js index 7997bcc7f..c36a06e49 100644 --- a/src/web/app/desktop/tags/index.js +++ b/src/web/app/desktop/tags/index.js @@ -57,6 +57,7 @@ require('./pages/entrance.tag'); require('./pages/entrance/signin.tag'); require('./pages/entrance/signup.tag'); require('./pages/home.tag'); +require('./pages/home-customize.tag'); require('./pages/user.tag'); require('./pages/post.tag'); require('./pages/search.tag'); diff --git a/src/web/app/desktop/tags/pages/home-customize.tag b/src/web/app/desktop/tags/pages/home-customize.tag new file mode 100644 index 000000000..443401561 --- /dev/null +++ b/src/web/app/desktop/tags/pages/home-customize.tag @@ -0,0 +1,14 @@ + + + + + + + diff --git a/src/web/app/desktop/tags/settings.tag b/src/web/app/desktop/tags/settings.tag index eabddfb43..4c16f9eaa 100644 --- a/src/web/app/desktop/tags/settings.tag +++ b/src/web/app/desktop/tags/settings.tag @@ -38,6 +38,7 @@

デザイン

+ ホームをカスタマイズ
diff --git a/src/web/app/desktop/tags/ui.tag b/src/web/app/desktop/tags/ui.tag index 0a3e8d9c5..6a4982877 100644 --- a/src/web/app/desktop/tags/ui.tag +++ b/src/web/app/desktop/tags/ui.tag @@ -37,7 +37,7 @@ - +
diff --git a/src/web/app/init.js b/src/web/app/init.js index 5a6899ed4..7e3c2ee37 100644 --- a/src/web/app/init.js +++ b/src/web/app/init.js @@ -11,7 +11,6 @@ import checkForUpdate from './common/scripts/check-for-update'; import Connection from './common/scripts/home-stream'; import Progress from './common/scripts/loading'; import mixin from './common/mixins'; -import generateDefaultUserdata from './common/scripts/generate-default-userdata'; import CONFIG from './common/scripts/config'; require('./common/tags'); @@ -156,9 +155,7 @@ function fetchme(token, cb) { res.json().then(i => { me = i; me.token = token; - - // initialize it if user data is empty - me.data ? done() : init(); + done(); }); }, () => { // When failure // Render the error screen @@ -170,17 +167,6 @@ function fetchme(token, cb) { function done() { if (cb) cb(me); } - - // Initialize user data - function init() { - const data = generateDefaultUserdata(); - api(token, 'i/appdata/set', { - data - }).then(() => { - me.data = data; - done(); - }); - } } // BSoD diff --git a/tools/migration/node.2017-11-08..js b/tools/migration/node.2017-11-08..js new file mode 100644 index 000000000..e25b83b3f --- /dev/null +++ b/tools/migration/node.2017-11-08..js @@ -0,0 +1,89 @@ +const uuid = require('uuid'); +const { default: User } = require('../../built/api/models/user') +const { default: zip } = require('@prezzemolo/zip') + +const home = { + left: [ + 'profile', + 'calendar', + 'activity', + 'rss-reader', + 'trends', + 'photo-stream', + 'version' + ], + right: [ + 'broadcast', + 'notifications', + 'user-recommendation', + 'recommended-polls', + 'server', + 'donation', + 'nav', + 'tips' + ] +}; + + +const migrate = async (doc) => { + + //#region Construct home data + const homeData = []; + + home.left.forEach(widget => { + homeData.push({ + name: widget, + id: uuid(), + place: 'left', + data: {} + }); + }); + + home.right.forEach(widget => { + homeData.push({ + name: widget, + id: uuid(), + place: 'right', + data: {} + }); + }); + //#endregion + + const result = await User.update(doc._id, { + $unset: { + data: '' + }, + $set: { + 'settings': {}, + 'client_settings.home': homeData, + 'client_settings.show_donation': false + } + }) + + return added && result.ok === 1 +} + +async function main() { + const count = await db.get('users').count(); + + console.log(`there are ${count} users.`) + + const dop = Number.parseInt(process.argv[2]) || 5 + const idop = ((count - (count % dop)) / dop) + 1 + + return zip( + 1, + async (time) => { + console.log(`${time} / ${idop}`) + const docs = await db.get('users').find({}, { limit: dop, skip: time * dop }) + return Promise.all(docs.map(migrate)) + }, + idop + ).then(a => { + const rv = [] + a.forEach(e => rv.push(...e)) + return rv + }) +} + +main().then(console.dir).catch(console.error) From 20bde47e313d348264b77b83159efa70ed3d7e90 Mon Sep 17 00:00:00 2001 From: syuilo Date: Wed, 8 Nov 2017 23:44:22 +0900 Subject: [PATCH 109/327] v2974 --- CHANGELOG.md | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d387bff55..fbbb1acbd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,7 @@ ChangeLog (Release Notes) ========================= 主に notable な changes を書いていきます -unreleased +2974 (2017/11/08) ----------------- * ホームのカスタマイズを実装するなど diff --git a/package.json b/package.json index 62006e067..7eecfec57 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "misskey", "author": "syuilo ", - "version": "0.0.2971", + "version": "0.0.2974", "license": "MIT", "description": "A miniblog-based SNS", "bugs": "https://github.com/syuilo/misskey/issues", From db2df43c349233c55c3d0fd98a4ef0622f06cb38 Mon Sep 17 00:00:00 2001 From: syuilo Date: Wed, 8 Nov 2017 23:48:23 +0900 Subject: [PATCH 110/327] oops --- tools/migration/{node.2017-11-08..js => node.2017-11-08.js} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename tools/migration/{node.2017-11-08..js => node.2017-11-08.js} (100%) diff --git a/tools/migration/node.2017-11-08..js b/tools/migration/node.2017-11-08.js similarity index 100% rename from tools/migration/node.2017-11-08..js rename to tools/migration/node.2017-11-08.js From 777f9b2ae212c9b367a76dddcb0c54b1a5afb149 Mon Sep 17 00:00:00 2001 From: syuilo Date: Wed, 8 Nov 2017 23:54:02 +0900 Subject: [PATCH 111/327] Fix test --- test/api.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/test/api.js b/test/api.js index a2eaa4e62..49f1faa53 100644 --- a/test/api.js +++ b/test/api.js @@ -1138,7 +1138,9 @@ function insertSakurako(opts) { username: 'sakurako', username_lower: 'sakurako', password: '$2a$08$FnHXg3tP.M/kINWgQSXNqeoBsiVrkj.ecXX8mW9rfBzMRkibYfjYy', // HimawariDaisuki06160907 - profile: {} + profile: {}, + settings: {}, + client_settings: {} }, opts)); } @@ -1148,7 +1150,9 @@ function insertHimawari(opts) { username: 'himawari', username_lower: 'himawari', password: '$2a$08$OPESxR2RE/ZijjGanNKk6ezSqGFitqsbZqTjWUZPLhORMKxHCbc4O', // ilovesakurako - profile: {} + profile: {}, + settings: {}, + client_settings: {} }, opts)); } From 45352131f383f5ca49796004119a1b75478dd5f4 Mon Sep 17 00:00:00 2001 From: syuilo Date: Wed, 8 Nov 2017 23:55:17 +0900 Subject: [PATCH 112/327] Remove blank line --- tools/migration/node.2017-11-08.js | 1 - 1 file changed, 1 deletion(-) diff --git a/tools/migration/node.2017-11-08.js b/tools/migration/node.2017-11-08.js index e25b83b3f..097f94044 100644 --- a/tools/migration/node.2017-11-08.js +++ b/tools/migration/node.2017-11-08.js @@ -24,7 +24,6 @@ const home = { ] }; - const migrate = async (doc) => { //#region Construct home data From 7a10542335aedf2dab9f82d562ac347a7d7cb7ab Mon Sep 17 00:00:00 2001 From: syuilo Date: Thu, 9 Nov 2017 00:12:47 +0900 Subject: [PATCH 113/327] Fix --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 7eecfec57..a65e8de67 100644 --- a/package.json +++ b/package.json @@ -22,7 +22,6 @@ "format": "gulp format" }, "devDependencies": { - "@prezzemolo/zip": "0.0.3", "@types/bcryptjs": "2.4.1", "@types/body-parser": "1.16.7", "@types/chai": "4.0.4", @@ -93,6 +92,7 @@ "webpack": "3.8.1" }, "dependencies": { + "@prezzemolo/zip": "0.0.3", "@prezzemolo/rap": "0.1.2", "accesses": "2.5.0", "animejs": "2.2.0", From 24e862770a22e491c68004fd66c351dcbaa10552 Mon Sep 17 00:00:00 2001 From: syuilo Date: Thu, 9 Nov 2017 00:13:32 +0900 Subject: [PATCH 114/327] Fix bug --- tools/migration/node.2017-11-08.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/migration/node.2017-11-08.js b/tools/migration/node.2017-11-08.js index 097f94044..c5a5176fa 100644 --- a/tools/migration/node.2017-11-08.js +++ b/tools/migration/node.2017-11-08.js @@ -63,7 +63,7 @@ const migrate = async (doc) => { } async function main() { - const count = await db.get('users').count(); + const count = await User.count(); console.log(`there are ${count} users.`) @@ -74,7 +74,7 @@ async function main() { 1, async (time) => { console.log(`${time} / ${idop}`) - const docs = await db.get('users').find({}, { limit: dop, skip: time * dop }) + const docs = await User.find({}, { limit: dop, skip: time * dop }) return Promise.all(docs.map(migrate)) }, idop From 13a785d944d435207850232997fe818964fa47af Mon Sep 17 00:00:00 2001 From: syuilo Date: Thu, 9 Nov 2017 00:17:24 +0900 Subject: [PATCH 115/327] Fix --- tools/migration/node.2017-11-08.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/migration/node.2017-11-08.js b/tools/migration/node.2017-11-08.js index c5a5176fa..196a5a90c 100644 --- a/tools/migration/node.2017-11-08.js +++ b/tools/migration/node.2017-11-08.js @@ -59,7 +59,7 @@ const migrate = async (doc) => { } }) - return added && result.ok === 1 + return result.ok === 1 } async function main() { From ad181612e62b8361ee3b2c6a3142c97a340d6abf Mon Sep 17 00:00:00 2001 From: syuilo Date: Thu, 9 Nov 2017 02:28:01 +0900 Subject: [PATCH 116/327] Clean up --- locales/en.yml | 1 - locales/ja.yml | 1 - src/web/app/desktop/tags/drive/file.tag | 3 --- 3 files changed, 5 deletions(-) diff --git a/locales/en.yml b/locales/en.yml index 679651033..9e19728af 100644 --- a/locales/en.yml +++ b/locales/en.yml @@ -225,7 +225,6 @@ desktop: mk-drive-browser-file: avatar: "Avatar" banner: "Banner" - wallpaper: "Wallpaper" mk-drive-browser-folder-contextmenu: move-to-this-folder: "Move to this folder" diff --git a/locales/ja.yml b/locales/ja.yml index c146475b2..39cc41d0a 100644 --- a/locales/ja.yml +++ b/locales/ja.yml @@ -225,7 +225,6 @@ desktop: mk-drive-browser-file: avatar: "アバター" banner: "バナー" - wallpaper: "壁紙" mk-drive-browser-folder-contextmenu: move-to-this-folder: "このフォルダへ移動" diff --git a/src/web/app/desktop/tags/drive/file.tag b/src/web/app/desktop/tags/drive/file.tag index 64838d681..bf9d38bd2 100644 --- a/src/web/app/desktop/tags/drive/file.tag +++ b/src/web/app/desktop/tags/drive/file.tag @@ -5,9 +5,6 @@

%i18n:desktop.tags.mk-drive-browser-file.banner%

-
-

%i18n:desktop.tags.mk-drive-browser-file.wallpaper%

-

{ file.name.lastIndexOf('.') != -1 ? file.name.substr(0, file.name.lastIndexOf('.')) : file.name }{ file.name.substr(file.name.lastIndexOf('.')) }

+ + diff --git a/src/web/app/desktop/tags/home.tag b/src/web/app/desktop/tags/home.tag index f0c71a7ea..531adca4c 100644 --- a/src/web/app/desktop/tags/home.tag +++ b/src/web/app/desktop/tags/home.tag @@ -9,6 +9,7 @@ + diff --git a/src/web/app/desktop/tags/index.js b/src/web/app/desktop/tags/index.js index c36a06e49..75bbdae95 100644 --- a/src/web/app/desktop/tags/index.js +++ b/src/web/app/desktop/tags/index.js @@ -12,6 +12,7 @@ require('./drive/nav-folder.tag'); require('./drive/browser-window.tag'); require('./drive/browser.tag'); require('./select-file-from-drive-window.tag'); +require('./select-folder-from-drive-window.tag'); require('./crop-window.tag'); require('./settings.tag'); require('./settings-window.tag'); @@ -38,6 +39,7 @@ require('./home-widgets/recommended-polls.tag'); require('./home-widgets/trends.tag'); require('./home-widgets/activity.tag'); require('./home-widgets/server.tag'); +require('./home-widgets/slideshow.tag'); require('./timeline.tag'); require('./messaging/window.tag'); require('./messaging/room-window.tag'); diff --git a/src/web/app/desktop/tags/select-folder-from-drive-window.tag b/src/web/app/desktop/tags/select-folder-from-drive-window.tag new file mode 100644 index 000000000..375f428bf --- /dev/null +++ b/src/web/app/desktop/tags/select-folder-from-drive-window.tag @@ -0,0 +1,112 @@ + + + + + + + +
+ + +
+
+
+ + +
From d0d7e1f2179eebc547ae58c40917d02527ad1780 Mon Sep 17 00:00:00 2001 From: syuilo Date: Thu, 9 Nov 2017 02:58:04 +0900 Subject: [PATCH 119/327] v2984 --- CHANGELOG.md | 4 ++-- package.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index bbeac2d74..81b0246f0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,8 +2,8 @@ ChangeLog (Release Notes) ========================= 主に notable な changes を書いていきます -unreleased ----------- +2984 (2017/11/09) +----------------- * スライドショーウィジェットを追加 2974 (2017/11/08) diff --git a/package.json b/package.json index a65e8de67..7e621f782 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "misskey", "author": "syuilo ", - "version": "0.0.2974", + "version": "0.0.2984", "license": "MIT", "description": "A miniblog-based SNS", "bugs": "https://github.com/syuilo/misskey/issues", From c1a455a3eda3fa4d0679f4015f02022b096de5ae Mon Sep 17 00:00:00 2001 From: syuilo Date: Thu, 9 Nov 2017 03:05:26 +0900 Subject: [PATCH 120/327] Fix glitch --- src/web/app/desktop/tags/home-widgets/slideshow.tag | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/web/app/desktop/tags/home-widgets/slideshow.tag b/src/web/app/desktop/tags/home-widgets/slideshow.tag index da65bf91b..f70238860 100644 --- a/src/web/app/desktop/tags/home-widgets/slideshow.tag +++ b/src/web/app/desktop/tags/home-widgets/slideshow.tag @@ -1,7 +1,7 @@

クリックしてフォルダを指定してください

-

このフォルダには画像がありません

+

このフォルダには画像がありません

@@ -55,7 +55,7 @@ this.size = this.opts.data.hasOwnProperty('size') ? this.opts.data.size : 0; this.folder = this.opts.data.hasOwnProperty('folder') ? this.opts.data.folder : undefined; this.images = []; - this.fetching = false; + this.fetching = true; this.on('mount', () => { this.applySize(); From eb34ab6bd158aed8b5dc99ff5c42d678efdf0431 Mon Sep 17 00:00:00 2001 From: syuilo Date: Thu, 9 Nov 2017 13:33:41 +0900 Subject: [PATCH 121/327] =?UTF-8?q?=E3=82=B9=E3=83=A9=E3=82=A4=E3=83=89?= =?UTF-8?q?=E3=82=B7=E3=83=A7=E3=83=BC=E3=82=92=E3=83=A9=E3=83=B3=E3=83=80?= =?UTF-8?q?=E3=83=A0=E3=81=AB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/web/app/desktop/tags/home-widgets/slideshow.tag | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/src/web/app/desktop/tags/home-widgets/slideshow.tag b/src/web/app/desktop/tags/home-widgets/slideshow.tag index f70238860..aa1e45fad 100644 --- a/src/web/app/desktop/tags/home-widgets/slideshow.tag +++ b/src/web/app/desktop/tags/home-widgets/slideshow.tag @@ -100,14 +100,12 @@ this.change = () => { if (this.images.length == 0) return; - if (this.index >= this.images.length) this.index = 0; - const img = `url(${ this.images[this.index].url }?thumbnail&size=1024)`; + const index = Math.floor(Math.random() * this.images.length); + const img = `url(${ this.images[index].url }?thumbnail&size=1024)`; this.refs.slideB.style.backgroundImage = img; - this.index++; - anime({ targets: this.refs.slideB, opacity: 1, @@ -136,8 +134,7 @@ }).then(images => { this.update({ fetching: false, - images: images, - index: 0 + images: images }); this.refs.slideA.style.backgroundImage = ''; this.refs.slideB.style.backgroundImage = ''; From 062e5a70e87d9357b8a38ba60be8e5146d4719b3 Mon Sep 17 00:00:00 2001 From: syuilo Date: Thu, 9 Nov 2017 15:07:09 +0900 Subject: [PATCH 122/327] #886 --- CHANGELOG.md | 4 + locales/en.yml | 4 + locales/ja.yml | 4 + .../app/desktop/tags/home-widgets/channel.tag | 309 ++++++++++++++++++ src/web/app/desktop/tags/home.tag | 1 + src/web/app/desktop/tags/index.js | 1 + 6 files changed, 323 insertions(+) create mode 100644 src/web/app/desktop/tags/home-widgets/channel.tag diff --git a/CHANGELOG.md b/CHANGELOG.md index 81b0246f0..da2b187d1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ ChangeLog (Release Notes) ========================= 主に notable な changes を書いていきます +unlereased +----------------- +* チャンネルウィジェットを追加 + 2984 (2017/11/09) ----------------- * スライドショーウィジェットを追加 diff --git a/locales/en.yml b/locales/en.yml index 9e19728af..c69dc22b1 100644 --- a/locales/en.yml +++ b/locales/en.yml @@ -365,6 +365,10 @@ desktop: title: "Donation" text: "To manage Misskey we spend money for our domain server etc.. There's no incomes for us so we need your tip. If you're interested contact {}. Thank you for your contribution!" + mk-channel-home-widget: + title: "Channel" + settings: "Widget settings" + mk-repost-form: quote: "Quote..." cancel: "Cancel" diff --git a/locales/ja.yml b/locales/ja.yml index 39cc41d0a..782b87bd8 100644 --- a/locales/ja.yml +++ b/locales/ja.yml @@ -365,6 +365,10 @@ desktop: title: "寄付のお願い" text: "Misskeyの運営にはドメイン、サーバー等のコストが掛かります。Misskeyは広告を掲載したりしないため、収入を皆様からの寄付に頼っています。もしご興味があれば、{}までご連絡ください。ご協力ありがとうございます。" + mk-channel-home-widget: + title: "チャンネル" + settings: "ウィジェットの設定" + mk-repost-form: quote: "引用する..." cancel: "キャンセル" diff --git a/src/web/app/desktop/tags/home-widgets/channel.tag b/src/web/app/desktop/tags/home-widgets/channel.tag new file mode 100644 index 000000000..b85579045 --- /dev/null +++ b/src/web/app/desktop/tags/home-widgets/channel.tag @@ -0,0 +1,309 @@ + +

{ + channel ? channel.title : '%i18n:desktop.tags.mk-channel-home-widget.title%' + }

+ + + + +
+ + +

読み込み中

+
+

まだ投稿がありません

+ +
+ + + +
+ + +
+ { post.index }: + { post.user.name } + ID:{ post.user.username } +
+
+ >>{ post.reply.index } + { post.text } +
+ + + { + + +
+
+ + +
+ + +

>>{ reply.index } ({ reply.user.name }): [x]

+ + + +
diff --git a/src/web/app/desktop/tags/home.tag b/src/web/app/desktop/tags/home.tag index 531adca4c..5fc5e0d6a 100644 --- a/src/web/app/desktop/tags/home.tag +++ b/src/web/app/desktop/tags/home.tag @@ -15,6 +15,7 @@ + diff --git a/src/web/app/desktop/tags/index.js b/src/web/app/desktop/tags/index.js index 75bbdae95..ff513657a 100644 --- a/src/web/app/desktop/tags/index.js +++ b/src/web/app/desktop/tags/index.js @@ -40,6 +40,7 @@ require('./home-widgets/trends.tag'); require('./home-widgets/activity.tag'); require('./home-widgets/server.tag'); require('./home-widgets/slideshow.tag'); +require('./home-widgets/channel.tag'); require('./timeline.tag'); require('./messaging/window.tag'); require('./messaging/room-window.tag'); From bff671081ae4e72e955400aa15ef180eedb869ed Mon Sep 17 00:00:00 2001 From: syuilo Date: Thu, 9 Nov 2017 15:07:43 +0900 Subject: [PATCH 123/327] v2988 --- CHANGELOG.md | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index da2b187d1..c0d49f476 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,7 @@ ChangeLog (Release Notes) ========================= 主に notable な changes を書いていきます -unlereased +2988 (2017/11/09) ----------------- * チャンネルウィジェットを追加 diff --git a/package.json b/package.json index 7e621f782..d537af4f6 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "misskey", "author": "syuilo ", - "version": "0.0.2984", + "version": "0.0.2988", "license": "MIT", "description": "A miniblog-based SNS", "bugs": "https://github.com/syuilo/misskey/issues", From 3aa72171f59de6569851c1eabddbf558e5f50d5d Mon Sep 17 00:00:00 2001 From: syuilo Date: Thu, 9 Nov 2017 21:19:08 +0900 Subject: [PATCH 124/327] :art: --- .../app/desktop/tags/home-widgets/channel.tag | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/src/web/app/desktop/tags/home-widgets/channel.tag b/src/web/app/desktop/tags/home-widgets/channel.tag index b85579045..0434b6e88 100644 --- a/src/web/app/desktop/tags/home-widgets/channel.tag +++ b/src/web/app/desktop/tags/home-widgets/channel.tag @@ -103,11 +103,20 @@ -

>>{ reply.index } ({ reply.user.name }): [x]

+ + diff --git a/src/web/app/desktop/tags/home.tag b/src/web/app/desktop/tags/home.tag index ecfe23ade..452499d70 100644 --- a/src/web/app/desktop/tags/home.tag +++ b/src/web/app/desktop/tags/home.tag @@ -5,6 +5,7 @@ +
+

Tip: 一部のウィジェットは、クリックすることで表示を変更することができます。

@@ -213,11 +215,22 @@ break; } - this.home.push(riot.mount(el, { + const tag = riot.mount(el, { id: widget.id, data: widget.data, tl: this.refs.tl - })[0]); + })[0]; + + this.home.push(tag); + + if (this.opts.customize) { + actualEl.oncontextmenu = e => { + e.preventDefault(); + e.stopImmediatePropagation(); + if (tag.func) tag.func(); + return false; + }; + } }; this.addWidget = () => { From 10f7387eab737dc439b3de9c35fff0c3d6772a01 Mon Sep 17 00:00:00 2001 From: syuilo Date: Sun, 12 Nov 2017 05:25:51 +0900 Subject: [PATCH 161/327] v3028 --- CHANGELOG.md | 4 ++++ package.json | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index dbf993b9d..737c28536 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ ChangeLog (Release Notes) ========================= 主に notable な changes を書いていきます +3028 (2017/11/12) +----------------- +* ウィジェットの表示をコンパクトにできるように + 3026 (2017/11/12) ----------------- * バグ修正 diff --git a/package.json b/package.json index 1391264d3..a364822a0 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "misskey", "author": "syuilo ", - "version": "0.0.3026", + "version": "0.0.3028", "license": "MIT", "description": "A miniblog-based SNS", "bugs": "https://github.com/syuilo/misskey/issues", From af0bdb253fd102e4ad9724d26028f332cbff86b2 Mon Sep 17 00:00:00 2001 From: syuilo Date: Sun, 12 Nov 2017 05:38:48 +0900 Subject: [PATCH 162/327] :v: --- src/web/app/desktop/mixins/widget.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/web/app/desktop/mixins/widget.js b/src/web/app/desktop/mixins/widget.js index d21811fa2..2bf858ebe 100644 --- a/src/web/app/desktop/mixins/widget.js +++ b/src/web/app/desktop/mixins/widget.js @@ -16,6 +16,7 @@ riot.mixin('widget', { }, save: function() { + this.update(); this.api('i/update_home', { id: this.id, data: this.data From d36cdb0b365c09057e45e26dcfa745ce41188257 Mon Sep 17 00:00:00 2001 From: syuilo Date: Sun, 12 Nov 2017 05:52:35 +0900 Subject: [PATCH 163/327] Improve widgets --- .../app/desktop/tags/home-widgets/channel.tag | 18 +++++--- .../app/desktop/tags/home-widgets/profile.tag | 43 +++++++++++++++++-- .../tags/home-widgets/recommended-polls.tag | 17 ++++++-- .../desktop/tags/home-widgets/rss-reader.tag | 17 +++++++- .../app/desktop/tags/home-widgets/trends.tag | 17 ++++++-- 5 files changed, 96 insertions(+), 16 deletions(-) diff --git a/src/web/app/desktop/tags/home-widgets/channel.tag b/src/web/app/desktop/tags/home-widgets/channel.tag index c1a29f60b..b5a57277f 100644 --- a/src/web/app/desktop/tags/home-widgets/channel.tag +++ b/src/web/app/desktop/tags/home-widgets/channel.tag @@ -1,8 +1,10 @@ -

{ - channel ? channel.title : '%i18n:desktop.tags.mk-channel-home-widget.title%' - }

- + +

{ + channel ? channel.title : '%i18n:desktop.tags.mk-channel-home-widget.title%' + }

+ +

%i18n:desktop.tags.mk-channel-home-widget.get-started%

diff --git a/src/web/app/desktop/tags/home-widgets/profile.tag b/src/web/app/desktop/tags/home-widgets/profile.tag index e6a875211..3fdf4343e 100644 --- a/src/web/app/desktop/tags/home-widgets/profile.tag +++ b/src/web/app/desktop/tags/home-widgets/profile.tag @@ -1,5 +1,7 @@ - - avatar{ I.name } + + + avatar + { I.name }

@{ I.username }

diff --git a/src/web/app/desktop/tags/home-widgets/rss-reader.tag b/src/web/app/desktop/tags/home-widgets/rss-reader.tag index e9b740762..9c213cf79 100644 --- a/src/web/app/desktop/tags/home-widgets/rss-reader.tag +++ b/src/web/app/desktop/tags/home-widgets/rss-reader.tag @@ -1,6 +1,8 @@ -

RSS

- + +

RSS

+ +
@@ -62,6 +64,12 @@
diff --git a/src/web/app/desktop/tags/home-widgets/trends.tag b/src/web/app/desktop/tags/home-widgets/trends.tag index 021df3f72..f824d89cf 100644 --- a/src/web/app/desktop/tags/home-widgets/trends.tag +++ b/src/web/app/desktop/tags/home-widgets/trends.tag @@ -1,6 +1,8 @@ -

%i18n:desktop.tags.mk-trends-home-widget.title%

- + +

%i18n:desktop.tags.mk-trends-home-widget.title%

+ +

{ post.text }

@{ post.user.username }

@@ -72,7 +74,11 @@ From 6034d76b224467a7ac57341b408d96d95c8c03f6 Mon Sep 17 00:00:00 2001 From: syuilo Date: Sun, 12 Nov 2017 05:53:29 +0900 Subject: [PATCH 164/327] v3031 --- CHANGELOG.md | 4 ++++ package.json | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 737c28536..bb44e74af 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ ChangeLog (Release Notes) ========================= 主に notable な changes を書いていきます +3031 (2017/11/12) +----------------- +* ウィジェットの強化 + 3028 (2017/11/12) ----------------- * ウィジェットの表示をコンパクトにできるように diff --git a/package.json b/package.json index a364822a0..84589ec42 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "misskey", "author": "syuilo ", - "version": "0.0.3028", + "version": "0.0.3031", "license": "MIT", "description": "A miniblog-based SNS", "bugs": "https://github.com/syuilo/misskey/issues", From 007889eb5e11b7cd54b0155f151418919f949609 Mon Sep 17 00:00:00 2001 From: syuilo Date: Sun, 12 Nov 2017 06:06:09 +0900 Subject: [PATCH 165/327] :art: --- src/web/app/desktop/tags/home-widgets/channel.tag | 1 + src/web/app/desktop/tags/home-widgets/profile.tag | 4 +++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/web/app/desktop/tags/home-widgets/channel.tag b/src/web/app/desktop/tags/home-widgets/channel.tag index b5a57277f..8f3d39d0e 100644 --- a/src/web/app/desktop/tags/home-widgets/channel.tag +++ b/src/web/app/desktop/tags/home-widgets/channel.tag @@ -11,6 +11,7 @@ :scope display block background #fff + overflow hidden > .title z-index 2 diff --git a/src/web/app/desktop/tags/home-widgets/profile.tag b/src/web/app/desktop/tags/home-widgets/profile.tag index 3fdf4343e..1439a423b 100644 --- a/src/web/app/desktop/tags/home-widgets/profile.tag +++ b/src/web/app/desktop/tags/home-widgets/profile.tag @@ -1,6 +1,6 @@ - avatar + avatar { I.name }

@{ I.username }

diff --git a/src/web/app/desktop/tags/home-widgets/photo-stream.tag b/src/web/app/desktop/tags/home-widgets/photo-stream.tag index 7f8dd8563..84d0020a6 100644 --- a/src/web/app/desktop/tags/home-widgets/photo-stream.tag +++ b/src/web/app/desktop/tags/home-widgets/photo-stream.tag @@ -1,5 +1,5 @@ - - + +

%i18n:desktop.tags.mk-photo-stream-home-widget.title%

%i18n:common.loading%

@@ -14,6 +14,17 @@ display block background #fff + &[data-melt] + background transparent !important + border none !important + + > .stream + padding 0 + + > .img + border solid 4px transparent + border-radius 8px + > .title z-index 1 margin 0 @@ -58,7 +69,7 @@ diff --git a/src/web/app/desktop/tags/home-widgets/profile.tag b/src/web/app/desktop/tags/home-widgets/profile.tag index 1439a423b..7d4cf862f 100644 --- a/src/web/app/desktop/tags/home-widgets/profile.tag +++ b/src/web/app/desktop/tags/home-widgets/profile.tag @@ -1,4 +1,4 @@ - + avatar { I.name } @@ -36,6 +36,20 @@ > .username display none + &[data-melt] + background transparent !important + border none !important + + > .banner + visibility hidden + + > .avatar + box-shadow none + + > .name + color #666 + text-shadow none + > .banner height 100px background-color #f5f5f5 @@ -77,7 +91,7 @@ import updateBanner from '../../scripts/update-banner'; this.data = { - compact: false + design: 0 }; this.mixin('widget'); @@ -93,7 +107,7 @@ }; this.func = () => { - this.data.compact = !this.data.compact; + if (++this.data.design == 3) this.data.design = 0; this.save(); }; diff --git a/src/web/app/desktop/tags/home-widgets/server.tag b/src/web/app/desktop/tags/home-widgets/server.tag index b2e3b9d90..094af8759 100644 --- a/src/web/app/desktop/tags/home-widgets/server.tag +++ b/src/web/app/desktop/tags/home-widgets/server.tag @@ -1,5 +1,5 @@ - - + +

%i18n:desktop.tags.mk-server-home-widget.title%

@@ -15,6 +15,10 @@ display block background #fff + &[data-melt] + background transparent !important + border none !important + > .title z-index 1 margin 0 @@ -60,7 +64,7 @@ this.data = { view: 0, - compact: false + design: 0 }; this.mixin('widget'); @@ -90,7 +94,7 @@ }; this.func = () => { - this.data.compact = !this.data.compact; + if (++this.data.design == 3) this.data.design = 0; this.save(); }; diff --git a/src/web/app/desktop/tags/home-widgets/timemachine.tag b/src/web/app/desktop/tags/home-widgets/timemachine.tag index 75e9f3a33..984258d2b 100644 --- a/src/web/app/desktop/tags/home-widgets/timemachine.tag +++ b/src/web/app/desktop/tags/home-widgets/timemachine.tag @@ -1,10 +1,12 @@ - - -

{ '%i18n:desktop.tags.mk-timemachine-home-widget.title%'.replace('{1}', year).replace('{2}', month) }

- + + + +

{ '%i18n:desktop.tags.mk-timemachine-home-widget.title%'.replace('{1}', year).replace('{2}', month) }

+ +
-
{ weekdayText[i] }
@@ -22,6 +24,10 @@ color #777 background #fff + &[data-melt] + background transparent !important + border none !important + > .title z-index 1 margin 0 @@ -130,6 +136,12 @@ From ea07146c7752370da794cff4e7f5ba5a922fa0c9 Mon Sep 17 00:00:00 2001 From: syuilo Date: Sun, 12 Nov 2017 07:01:04 +0900 Subject: [PATCH 168/327] v3035 --- CHANGELOG.md | 4 ++++ package.json | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5eb5a57ba..a7a7fa9b4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ ChangeLog (Release Notes) ========================= 主に notable な changes を書いていきます +3035 (2017/11/12) +----------------- +* ウィジェットの強化 + 3033 (2017/11/12) ----------------- * デザインの調整 diff --git a/package.json b/package.json index c874ba911..c89f89bc1 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "misskey", "author": "syuilo ", - "version": "0.0.3033", + "version": "0.0.3035", "license": "MIT", "description": "A miniblog-based SNS", "bugs": "https://github.com/syuilo/misskey/issues", From 25962c3f8404acea65dd98989ddaf5197337abe2 Mon Sep 17 00:00:00 2001 From: syuilo Date: Sun, 12 Nov 2017 16:26:09 +0900 Subject: [PATCH 169/327] Refactor --- src/web/app/desktop/tags/home-widgets/profile.tag | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/web/app/desktop/tags/home-widgets/profile.tag b/src/web/app/desktop/tags/home-widgets/profile.tag index 7d4cf862f..ddb6472a8 100644 --- a/src/web/app/desktop/tags/home-widgets/profile.tag +++ b/src/web/app/desktop/tags/home-widgets/profile.tag @@ -18,8 +18,8 @@ background rgba(0, 0, 0, 0.5) > .avatar - top 21px - left 21px + top ((100px - 58px) / 2) + left ((100px - 58px) / 2) border none border-radius 100% box-shadow 0 0 16px rgba(0, 0, 0, 0.5) From b3ef16d1cf8f250fdbdc144ad1a5431745e9f385 Mon Sep 17 00:00:00 2001 From: syuilo Date: Sun, 12 Nov 2017 18:23:33 +0900 Subject: [PATCH 170/327] :v: --- locales/en.yml | 5 + locales/ja.yml | 5 + src/web/app/desktop/mixins/widget.js | 9 +- .../desktop/tags/home-widgets/broadcast.tag | 7 +- .../desktop/tags/home-widgets/donation.tag | 5 +- src/web/app/desktop/tags/home-widgets/nav.tag | 3 + .../desktop/tags/home-widgets/post-form.tag | 101 ++++++++++++++++++ .../app/desktop/tags/home-widgets/tips.tag | 2 + .../app/desktop/tags/home-widgets/version.tag | 2 + src/web/app/desktop/tags/home.tag | 55 ++++++++-- src/web/app/desktop/tags/index.js | 1 + 11 files changed, 179 insertions(+), 16 deletions(-) create mode 100644 src/web/app/desktop/tags/home-widgets/post-form.tag diff --git a/locales/en.yml b/locales/en.yml index 2845eec6a..574af26a6 100644 --- a/locales/en.yml +++ b/locales/en.yml @@ -385,6 +385,11 @@ desktop: next: "Next month" go: "Click to travel" + mk-post-form-home-widget: + title: "Post" + post: "Post" + placeholder: "What's happening?" + mk-repost-form: quote: "Quote..." cancel: "Cancel" diff --git a/locales/ja.yml b/locales/ja.yml index 2d9aceb2d..9e6251d0d 100644 --- a/locales/ja.yml +++ b/locales/ja.yml @@ -385,6 +385,11 @@ desktop: next: "来月" go: "クリックして時間遡行" + mk-post-form-home-widget: + title: "投稿" + post: "投稿" + placeholder: "いまどうしてる?" + mk-repost-form: quote: "引用する..." cancel: "キャンセル" diff --git a/src/web/app/desktop/mixins/widget.js b/src/web/app/desktop/mixins/widget.js index 2bf858ebe..cb04295fc 100644 --- a/src/web/app/desktop/mixins/widget.js +++ b/src/web/app/desktop/mixins/widget.js @@ -9,10 +9,13 @@ riot.mixin('widget', { this.mixin('api'); this.id = this.opts.id; + this.place = this.opts.place; - Object.keys(this.data).forEach(prop => { - this.data[prop] = this.opts.data.hasOwnProperty(prop) ? this.opts.data[prop] : this.data[prop]; - }); + if (this.data) { + Object.keys(this.data).forEach(prop => { + this.data[prop] = this.opts.data.hasOwnProperty(prop) ? this.opts.data[prop] : this.data[prop]; + }); + } }, save: function() { diff --git a/src/web/app/desktop/tags/home-widgets/broadcast.tag b/src/web/app/desktop/tags/home-widgets/broadcast.tag index 1102e22c7..c33c5f367 100644 --- a/src/web/app/desktop/tags/home-widgets/broadcast.tag +++ b/src/web/app/desktop/tags/home-widgets/broadcast.tag @@ -75,9 +75,8 @@ a color #555 - - - - + diff --git a/src/web/app/desktop/tags/home-widgets/donation.tag b/src/web/app/desktop/tags/home-widgets/donation.tag index d533e8283..9d56d12f0 100644 --- a/src/web/app/desktop/tags/home-widgets/donation.tag +++ b/src/web/app/desktop/tags/home-widgets/donation.tag @@ -28,5 +28,8 @@ color #999 - + diff --git a/src/web/app/desktop/tags/home-widgets/nav.tag b/src/web/app/desktop/tags/home-widgets/nav.tag index 54bfb87a1..1061b36f4 100644 --- a/src/web/app/desktop/tags/home-widgets/nav.tag +++ b/src/web/app/desktop/tags/home-widgets/nav.tag @@ -14,4 +14,7 @@ color #ccc + diff --git a/src/web/app/desktop/tags/home-widgets/post-form.tag b/src/web/app/desktop/tags/home-widgets/post-form.tag new file mode 100644 index 000000000..2aa3cda50 --- /dev/null +++ b/src/web/app/desktop/tags/home-widgets/post-form.tag @@ -0,0 +1,101 @@ + + + + +

%i18n:desktop.tags.mk-post-form-home-widget.title%

+
+ + +
+ + +
diff --git a/src/web/app/desktop/tags/home-widgets/tips.tag b/src/web/app/desktop/tags/home-widgets/tips.tag index 5a535099a..fd5ec801f 100644 --- a/src/web/app/desktop/tags/home-widgets/tips.tag +++ b/src/web/app/desktop/tags/home-widgets/tips.tag @@ -31,6 +31,8 @@ diff --git a/src/web/app/desktop/tags/home.tag b/src/web/app/desktop/tags/home.tag index 60625bde6..8da58eb51 100644 --- a/src/web/app/desktop/tags/home.tag +++ b/src/web/app/desktop/tags/home.tag @@ -16,6 +16,7 @@ + @@ -32,12 +33,13 @@
-
-
+
+
+
-
+
+ diff --git a/src/web/app/desktop/tags/window.tag b/src/web/app/desktop/tags/window.tag index aefb6499b..cc8dc4c1a 100644 --- a/src/web/app/desktop/tags/window.tag +++ b/src/web/app/desktop/tags/window.tag @@ -4,7 +4,10 @@

- +
+ + +
@@ -117,8 +120,12 @@ box-shadow 0 2px 6px 0 rgba(0, 0, 0, 0.2) > header + $header-height = 40px + z-index 128 + height $header-height overflow hidden + white-space nowrap cursor move background #fff border-radius 6px 6px 0 0 @@ -130,39 +137,45 @@ > h1 pointer-events none display block - margin 0 - height 40px + margin 0 auto + width s('calc(100% - (%s * 2))', $header-height) + overflow hidden + text-overflow ellipsis text-align center font-size 1em - line-height 40px + line-height $header-height font-weight normal color #666 - > .close - cursor pointer - display block + > div:last-child position absolute top 0 right 0 + display block z-index 1 - margin 0 - padding 0 - font-size 1.2em - color rgba(#000, 0.4) - border none - outline none - background transparent - &:hover - color rgba(#000, 0.6) - - &:active - color darken(#000, 30%) - - > i + > * + display inline-block + margin 0 padding 0 - width 40px - line-height 40px + cursor pointer + font-size 1.2em + color rgba(#000, 0.4) + border none + outline none + background transparent + + &:hover + color rgba(#000, 0.6) + + &:active + color darken(#000, 30%) + + > i + padding 0 + width $header-height + line-height $header-height + text-align center > .content height 100% @@ -181,6 +194,8 @@ this.isModal = this.opts.isModal != null ? this.opts.isModal : false; this.canClose = this.opts.canClose != null ? this.opts.canClose : true; + this.popoutOption = this.opts.popoutOption; + console.log(this.popoutOption); this.isFlexible = this.opts.height == null; this.canResize = !this.isFlexible; @@ -247,6 +262,19 @@ }, 300); }; + this.popout = () => { + const position = this.refs.main.getBoundingClientRect(); + + const x = window.screenX + position.left; + const y = window.screenY + position.top; + + window.open(this.popoutOption.url, + this.popoutOption.url, + `height=${this.popoutOption.height},width=${this.popoutOption.width},left=${x},top=${y}`); + + this.close(); + }; + this.close = () => { this.trigger('closing'); From cfbdad98ac4bb63a52e05163b5cb98989d5d8fa6 Mon Sep 17 00:00:00 2001 From: syuilo Date: Mon, 13 Nov 2017 07:33:47 +0900 Subject: [PATCH 186/327] v3055 --- CHANGELOG.md | 4 ++++ package.json | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5697e3773..ae39bc076 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ ChangeLog (Release Notes) ========================= 主に notable な changes を書いていきます +3055 (2017/11/13) +----------------- +* メッセージのウィンドウのポップアウト (#911) + 3050 (2017/11/13) ----------------- * 通信の最適化 diff --git a/package.json b/package.json index 9f8a744b4..5b21dc25b 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "misskey", "author": "syuilo ", - "version": "0.0.3050", + "version": "0.0.3055", "license": "MIT", "description": "A miniblog-based SNS", "bugs": "https://github.com/syuilo/misskey/issues", From b2b88523edebc463d5b57761b787eacfe5835c40 Mon Sep 17 00:00:00 2001 From: syuilo Date: Mon, 13 Nov 2017 07:46:33 +0900 Subject: [PATCH 187/327] Fix glitch --- src/web/app/desktop/tags/pages/messaging-room.tag | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/web/app/desktop/tags/pages/messaging-room.tag b/src/web/app/desktop/tags/pages/messaging-room.tag index 9aba6c95d..9747b4b83 100644 --- a/src/web/app/desktop/tags/pages/messaging-room.tag +++ b/src/web/app/desktop/tags/pages/messaging-room.tag @@ -4,9 +4,6 @@ @@ -21,6 +18,8 @@ this.on('mount', () => { Progress.start(); + document.documentElement.style.background = '#fff'; + this.api('users/show', { username: this.opts.user }).then(user => { From c31aad36236eb8f522b066f518363c5b35c7aa79 Mon Sep 17 00:00:00 2001 From: syuilo Date: Mon, 13 Nov 2017 07:47:14 +0900 Subject: [PATCH 188/327] v3057 --- CHANGELOG.md | 4 ++++ package.json | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ae39bc076..c8f43f0c7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ ChangeLog (Release Notes) ========================= 主に notable な changes を書いていきます +3057 (2017/11/13) +----------------- +* グリッチ修正 + 3055 (2017/11/13) ----------------- * メッセージのウィンドウのポップアウト (#911) diff --git a/package.json b/package.json index 5b21dc25b..2861fd9f0 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "misskey", "author": "syuilo ", - "version": "0.0.3055", + "version": "0.0.3057", "license": "MIT", "description": "A miniblog-based SNS", "bugs": "https://github.com/syuilo/misskey/issues", From 338cac395d0943d7061ccb60a6b620b18b641cfa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=81=93=E3=81=B4=E3=81=AA=E3=81=9F=E3=81=BF=E3=81=BD?= Date: Mon, 13 Nov 2017 08:53:38 +0900 Subject: [PATCH 189/327] :v: --- src/web/app/desktop/tags/messaging/room-window.tag | 8 ++------ src/web/app/desktop/tags/window.tag | 13 +++++++------ 2 files changed, 9 insertions(+), 12 deletions(-) diff --git a/src/web/app/desktop/tags/messaging/room-window.tag b/src/web/app/desktop/tags/messaging/room-window.tag index 4d4f5c626..dca0172be 100644 --- a/src/web/app/desktop/tags/messaging/room-window.tag +++ b/src/web/app/desktop/tags/messaging/room-window.tag @@ -1,5 +1,5 @@ - + メッセージ: { parent.user.name } @@ -23,11 +23,7 @@ this.user = this.opts.user; - this.popout = { - url: `${CONFIG.url}/i/messaging/${this.user.username}`, - width: 420, - height: 540 - }; + this.popout = `${CONFIG.url}/i/messaging/${this.user.username}`; this.on('mount', () => { this.refs.window.on('closed', () => { diff --git a/src/web/app/desktop/tags/window.tag b/src/web/app/desktop/tags/window.tag index cc8dc4c1a..f0e1a3fdd 100644 --- a/src/web/app/desktop/tags/window.tag +++ b/src/web/app/desktop/tags/window.tag @@ -5,7 +5,7 @@

- +
@@ -194,8 +194,7 @@ this.isModal = this.opts.isModal != null ? this.opts.isModal : false; this.canClose = this.opts.canClose != null ? this.opts.canClose : true; - this.popoutOption = this.opts.popoutOption; - console.log(this.popoutOption); + this.popoutUrl = this.opts.popout; this.isFlexible = this.opts.height == null; this.canResize = !this.isFlexible; @@ -265,12 +264,14 @@ this.popout = () => { const position = this.refs.main.getBoundingClientRect(); + const width = parseInt(getComputedStyle(this.refs.main, '').width, 10); + const left = parseInt(getComputedStyle(this.refs.main, '').left, 10); const x = window.screenX + position.left; const y = window.screenY + position.top; - window.open(this.popoutOption.url, - this.popoutOption.url, - `height=${this.popoutOption.height},width=${this.popoutOption.width},left=${x},top=${y}`); + window.open(this.popoutUrl, + this.popoutUrl, + `height=${height},width=${width},left=${x},top=${y}`); this.close(); }; From d9a05e962ddcf1c105b7cd2603b45501bb93faec Mon Sep 17 00:00:00 2001 From: syuilo Date: Mon, 13 Nov 2017 15:04:20 +0900 Subject: [PATCH 190/327] :v: --- src/server.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/server.ts b/src/server.ts index 240800c1e..3e9bd44ee 100644 --- a/src/server.ts +++ b/src/server.ts @@ -35,7 +35,7 @@ app.use(morgan(process.env.NODE_ENV == 'production' ? 'combined' : 'dev', { stream: config.accesslog ? fs.createWriteStream(config.accesslog) : null })); -// Drop request that without 'Host' header +// Drop request when without 'Host' header app.use((req, res, next) => { if (!req.headers['host']) { res.sendStatus(400); From f497ab8a92970c1f41eb6579dc09991b5050dba5 Mon Sep 17 00:00:00 2001 From: syuilo Date: Mon, 13 Nov 2017 18:05:35 +0900 Subject: [PATCH 191/327] =?UTF-8?q?=E3=81=AA=E3=82=93=E3=81=8B=E3=82=82?= =?UTF-8?q?=E3=81=86=E3=82=81=E3=81=A3=E3=81=A1=E3=82=83=E5=A4=89=E3=81=88?= =?UTF-8?q?=E3=81=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 7 +++- src/web/app/auth/{script.js => script.ts} | 0 src/web/app/auth/tags/{index.js => index.ts} | 0 src/web/app/ch/{router.js => router.ts} | 4 +-- src/web/app/ch/{script.js => script.ts} | 0 src/web/app/ch/tags/channel.tag | 4 +-- src/web/app/ch/tags/{index.js => index.ts} | 0 src/web/app/common/mixins/{api.js => api.ts} | 2 +- src/web/app/common/mixins/{i.js => i.ts} | 2 +- src/web/app/common/mixins/index.js | 13 -------- src/web/app/common/mixins/index.ts | 14 ++++++++ src/web/app/common/scripts/{api.js => api.ts} | 4 +-- .../{bytes-to-size.js => bytes-to-size.ts} | 4 +-- .../{channel-stream.js => channel-stream.ts} | 0 ...heck-for-update.js => check-for-update.ts} | 4 ++- .../common/scripts/{config.js => config.ts} | 0 .../scripts/{contains.js => contains.ts} | 0 ...y-to-clipboard.js => copy-to-clipboard.ts} | 0 .../{date-stringify.js => date-stringify.ts} | 0 src/web/app/common/scripts/{gcd.js => gcd.ts} | 0 .../common/scripts/{get-kao.js => get-kao.ts} | 2 +- .../{home-stream.js => home-stream.ts} | 4 +-- .../scripts/{is-promise.js => is-promise.ts} | 0 .../common/scripts/{loading.js => loading.ts} | 0 ...essaging-stream.js => messaging-stream.ts} | 2 +- .../common/scripts/server-stream-manager.ts | 31 ++--------------- .../{server-stream.js => server-stream.ts} | 0 .../common/scripts/{signout.js => signout.ts} | 0 src/web/app/common/scripts/stream-manager.ts | 33 +++++++++++++++++++ .../common/scripts/{stream.js => stream.ts} | 31 +++++++++-------- .../{text-compiler.js => text-compiler.ts} | 4 +-- .../app/common/tags/{index.js => index.ts} | 0 src/web/app/common/tags/messaging/message.tag | 2 +- .../app/desktop/mixins/{index.js => index.ts} | 0 .../{user-preview.js => user-preview.ts} | 2 +- .../desktop/mixins/{widget.js => widget.ts} | 2 +- src/web/app/desktop/{router.js => router.ts} | 6 ++-- src/web/app/desktop/{script.js => script.ts} | 8 ++--- .../{autocomplete.js => autocomplete.ts} | 26 ++++++++------- .../desktop/scripts/{dialog.js => dialog.ts} | 4 +-- .../{fuck-ad-block.js => fuck-ad-block.ts} | 2 ++ .../{input-dialog.js => input-dialog.ts} | 2 +- ...eption.js => not-implemented-exception.ts} | 0 .../desktop/scripts/{notify.js => notify.ts} | 2 +- ...{password-dialog.js => password-dialog.ts} | 2 +- .../{update-avatar.js => update-avatar.ts} | 8 ++--- .../{update-banner.js => update-banner.ts} | 8 ++--- .../desktop/tags/autocomplete-suggestion.tag | 2 +- src/web/app/desktop/tags/drive/browser.tag | 4 +-- src/web/app/desktop/tags/drive/folder.tag | 2 +- src/web/app/desktop/tags/drive/nav-folder.tag | 2 +- .../app/desktop/tags/{index.js => index.ts} | 0 src/web/app/desktop/tags/post-detail-sub.tag | 2 +- src/web/app/desktop/tags/post-detail.tag | 2 +- src/web/app/desktop/tags/post-form.tag | 6 ++-- src/web/app/desktop/tags/sub-post-content.tag | 2 +- src/web/app/desktop/tags/timeline.tag | 2 +- src/web/app/dev/{router.js => router.ts} | 4 +-- src/web/app/dev/{script.js => script.ts} | 0 src/web/app/dev/tags/{index.js => index.ts} | 0 src/web/app/{init.js => init.ts} | 28 +++------------- src/web/app/mobile/{router.js => router.ts} | 6 ++-- src/web/app/mobile/{script.js => script.ts} | 0 .../{open-post-form.js => open-post-form.ts} | 0 .../scripts/{ui-event.js => ui-event.ts} | 0 src/web/app/mobile/tags/drive.tag | 2 +- .../app/mobile/tags/{index.js => index.ts} | 0 src/web/app/mobile/tags/post-detail.tag | 2 +- src/web/app/mobile/tags/post-form.tag | 4 +-- src/web/app/mobile/tags/sub-post-content.tag | 2 +- src/web/app/mobile/tags/timeline.tag | 2 +- src/web/app/stats/{script.js => script.ts} | 0 src/web/app/stats/tags/{index.js => index.ts} | 0 src/web/app/status/{script.js => script.ts} | 0 .../app/status/tags/{index.js => index.ts} | 0 tslint.json | 1 + webpack/webpack.config.ts | 21 +++++++----- 77 files changed, 170 insertions(+), 165 deletions(-) rename src/web/app/auth/{script.js => script.ts} (100%) rename src/web/app/auth/tags/{index.js => index.ts} (100%) rename src/web/app/ch/{router.js => router.ts} (92%) rename src/web/app/ch/{script.js => script.ts} (100%) rename src/web/app/ch/tags/{index.js => index.ts} (100%) rename src/web/app/common/mixins/{api.js => api.ts} (82%) rename src/web/app/common/mixins/{i.js => i.ts} (91%) delete mode 100644 src/web/app/common/mixins/index.js create mode 100644 src/web/app/common/mixins/index.ts rename src/web/app/common/scripts/{api.js => api.ts} (88%) rename src/web/app/common/scripts/{bytes-to-size.js => bytes-to-size.ts} (58%) rename src/web/app/common/scripts/{channel-stream.js => channel-stream.ts} (100%) rename src/web/app/common/scripts/{check-for-update.js => check-for-update.ts} (91%) rename src/web/app/common/scripts/{config.js => config.ts} (100%) rename src/web/app/common/scripts/{contains.js => contains.ts} (100%) rename src/web/app/common/scripts/{copy-to-clipboard.js => copy-to-clipboard.ts} (100%) rename src/web/app/common/scripts/{date-stringify.js => date-stringify.ts} (100%) rename src/web/app/common/scripts/{gcd.js => gcd.ts} (100%) rename src/web/app/common/scripts/{get-kao.js => get-kao.ts} (65%) rename src/web/app/common/scripts/{home-stream.js => home-stream.ts} (83%) rename src/web/app/common/scripts/{is-promise.js => is-promise.ts} (100%) rename src/web/app/common/scripts/{loading.js => loading.ts} (100%) rename src/web/app/common/scripts/{messaging-stream.js => messaging-stream.ts} (87%) rename src/web/app/common/scripts/{server-stream.js => server-stream.ts} (100%) rename src/web/app/common/scripts/{signout.js => signout.ts} (100%) create mode 100644 src/web/app/common/scripts/stream-manager.ts rename src/web/app/common/scripts/{stream.js => stream.ts} (83%) rename src/web/app/common/scripts/{text-compiler.js => text-compiler.ts} (94%) rename src/web/app/common/tags/{index.js => index.ts} (100%) rename src/web/app/desktop/mixins/{index.js => index.ts} (100%) rename src/web/app/desktop/mixins/{user-preview.js => user-preview.ts} (95%) rename src/web/app/desktop/mixins/{widget.js => widget.ts} (95%) rename src/web/app/desktop/{router.js => router.ts} (96%) rename src/web/app/desktop/{script.js => script.ts} (87%) rename src/web/app/desktop/scripts/{autocomplete.js => autocomplete.ts} (86%) rename src/web/app/desktop/scripts/{dialog.js => dialog.ts} (77%) rename src/web/app/desktop/scripts/{fuck-ad-block.js => fuck-ad-block.ts} (94%) rename src/web/app/desktop/scripts/{input-dialog.js => input-dialog.ts} (88%) rename src/web/app/desktop/scripts/{not-implemented-exception.js => not-implemented-exception.ts} (100%) rename src/web/app/desktop/scripts/{notify.js => notify.ts} (83%) rename src/web/app/desktop/scripts/{password-dialog.js => password-dialog.ts} (86%) rename src/web/app/desktop/scripts/{update-avatar.js => update-avatar.ts} (82%) rename src/web/app/desktop/scripts/{update-banner.js => update-banner.ts} (82%) rename src/web/app/desktop/tags/{index.js => index.ts} (100%) rename src/web/app/dev/{router.js => router.ts} (94%) rename src/web/app/dev/{script.js => script.ts} (100%) rename src/web/app/dev/tags/{index.js => index.ts} (100%) rename src/web/app/{init.js => init.ts} (81%) rename src/web/app/mobile/{router.js => router.ts} (97%) rename src/web/app/mobile/{script.js => script.ts} (100%) rename src/web/app/mobile/scripts/{open-post-form.js => open-post-form.ts} (100%) rename src/web/app/mobile/scripts/{ui-event.js => ui-event.ts} (100%) rename src/web/app/mobile/tags/{index.js => index.ts} (100%) rename src/web/app/stats/{script.js => script.ts} (100%) rename src/web/app/stats/tags/{index.js => index.ts} (100%) rename src/web/app/status/{script.js => script.ts} (100%) rename src/web/app/status/tags/{index.js => index.ts} (100%) diff --git a/package.json b/package.json index 2861fd9f0..879f4af92 100644 --- a/package.json +++ b/package.json @@ -52,6 +52,9 @@ "@types/ms": "0.7.30", "@types/multer": "1.3.5", "@types/node": "8.0.49", + "@types/page": "1.5.32", + "@types/proxy-addr": "2.0.0", + "@types/seedrandom": "2.4.27", "@types/ratelimiter": "2.1.28", "@types/redis": "2.8.1", "@types/request": "2.0.7", @@ -92,8 +95,8 @@ "webpack": "3.8.1" }, "dependencies": { - "@prezzemolo/zip": "0.0.3", "@prezzemolo/rap": "0.1.2", + "@prezzemolo/zip": "0.0.3", "accesses": "2.5.0", "animejs": "2.2.0", "autwh": "0.0.1", @@ -131,6 +134,7 @@ "page": "1.7.1", "pictograph": "2.0.4", "prominence": "0.2.0", + "proxy-addr": "^2.0.2", "pug": "2.0.0-rc.4", "ratelimiter": "3.0.3", "recaptcha-promise": "0.1.3", @@ -141,6 +145,7 @@ "riot": "3.7.4", "rndstr": "1.0.0", "s-age": "1.1.0", + "seedrandom": "^2.4.3", "serve-favicon": "2.4.5", "sortablejs": "1.7.0", "summaly": "2.0.3", diff --git a/src/web/app/auth/script.js b/src/web/app/auth/script.ts similarity index 100% rename from src/web/app/auth/script.js rename to src/web/app/auth/script.ts diff --git a/src/web/app/auth/tags/index.js b/src/web/app/auth/tags/index.ts similarity index 100% rename from src/web/app/auth/tags/index.js rename to src/web/app/auth/tags/index.ts diff --git a/src/web/app/ch/router.js b/src/web/app/ch/router.ts similarity index 92% rename from src/web/app/ch/router.js rename to src/web/app/ch/router.ts index 424158f40..fe014d4e3 100644 --- a/src/web/app/ch/router.js +++ b/src/web/app/ch/router.ts @@ -1,5 +1,5 @@ import * as riot from 'riot'; -const route = require('page'); +import * as route from 'page'; let page = null; export default me => { @@ -22,7 +22,7 @@ export default me => { } // EXEC - route(); + (route as any)(); }; function mount(content) { diff --git a/src/web/app/ch/script.js b/src/web/app/ch/script.ts similarity index 100% rename from src/web/app/ch/script.js rename to src/web/app/ch/script.ts diff --git a/src/web/app/ch/tags/channel.tag b/src/web/app/ch/tags/channel.tag index 4ae62e7b3..48c5c705d 100644 --- a/src/web/app/ch/tags/channel.tag +++ b/src/web/app/ch/tags/channel.tag @@ -343,7 +343,7 @@ }; this.changeFile = () => { - this.refs.file.files.forEach(this.upload); + Array.from(this.refs.file.files).forEach(this.upload); }; this.selectFile = () => { @@ -367,7 +367,7 @@ }; this.onpaste = e => { - e.clipboardData.items.forEach(item => { + Array.from(e.clipboardData.items).forEach(item => { if (item.kind == 'file') { this.upload(item.getAsFile()); } diff --git a/src/web/app/ch/tags/index.js b/src/web/app/ch/tags/index.ts similarity index 100% rename from src/web/app/ch/tags/index.js rename to src/web/app/ch/tags/index.ts diff --git a/src/web/app/common/mixins/api.js b/src/web/app/common/mixins/api.ts similarity index 82% rename from src/web/app/common/mixins/api.js rename to src/web/app/common/mixins/api.ts index 42d96db55..9726caf51 100644 --- a/src/web/app/common/mixins/api.js +++ b/src/web/app/common/mixins/api.ts @@ -2,7 +2,7 @@ import * as riot from 'riot'; import api from '../scripts/api'; export default me => { - riot.mixin('api', { + (riot as any).mixin('api', { api: api.bind(null, me ? me.token : null) }); }; diff --git a/src/web/app/common/mixins/i.js b/src/web/app/common/mixins/i.ts similarity index 91% rename from src/web/app/common/mixins/i.js rename to src/web/app/common/mixins/i.ts index 522514776..0879d02d3 100644 --- a/src/web/app/common/mixins/i.js +++ b/src/web/app/common/mixins/i.ts @@ -1,7 +1,7 @@ import * as riot from 'riot'; export default me => { - riot.mixin('i', { + (riot as any).mixin('i', { init: function() { this.I = me; this.SIGNIN = me != null; diff --git a/src/web/app/common/mixins/index.js b/src/web/app/common/mixins/index.js deleted file mode 100644 index 19e0690d7..000000000 --- a/src/web/app/common/mixins/index.js +++ /dev/null @@ -1,13 +0,0 @@ -import * as riot from 'riot'; - -import activateMe from './i'; -import activateApi from './api'; - -export default (me, stream, serverStreamManager) => { - activateMe(me); - activateApi(me); - - riot.mixin('stream', { stream }); - - riot.mixin('server-stream', { serverStream: serverStreamManager }); -}; diff --git a/src/web/app/common/mixins/index.ts b/src/web/app/common/mixins/index.ts new file mode 100644 index 000000000..45427fb9d --- /dev/null +++ b/src/web/app/common/mixins/index.ts @@ -0,0 +1,14 @@ +import * as riot from 'riot'; + +import activateMe from './i'; +import activateApi from './api'; +import ServerStreamManager from '../scripts/server-stream-manager'; + +export default (me, stream) => { + activateMe(me); + activateApi(me); + + (riot as any).mixin('stream', { stream }); + + (riot as any).mixin('server-stream', { serverStream: new ServerStreamManager() }); +}; diff --git a/src/web/app/common/scripts/api.js b/src/web/app/common/scripts/api.ts similarity index 88% rename from src/web/app/common/scripts/api.js rename to src/web/app/common/scripts/api.ts index 4855f736c..2a9d78e87 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} Response */ -export default (i, endpoint, data = {}) => { +export default (i, endpoint, data = {}): Promise => { 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 similarity index 58% rename from src/web/app/common/scripts/bytes-to-size.js rename to src/web/app/common/scripts/bytes-to-size.ts index af0268dbd..1d2b1e7ce 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 similarity index 100% rename from src/web/app/common/scripts/channel-stream.js rename to 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 similarity index 91% rename from src/web/app/common/scripts/check-for-update.js rename to src/web/app/common/scripts/check-for-update.ts index 7cb7839d2..99d8b5d05 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 similarity index 100% rename from src/web/app/common/scripts/config.js rename to 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 similarity index 100% rename from src/web/app/common/scripts/contains.js rename to 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 similarity index 100% rename from src/web/app/common/scripts/copy-to-clipboard.js rename to 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 similarity index 100% rename from src/web/app/common/scripts/date-stringify.js rename to 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 similarity index 100% rename from src/web/app/common/scripts/gcd.js rename to 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 similarity index 65% rename from src/web/app/common/scripts/get-kao.js rename to src/web/app/common/scripts/get-kao.ts index 0b77ee285..2168c5be8 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 similarity index 83% rename from src/web/app/common/scripts/home-stream.js rename to src/web/app/common/scripts/home-stream.ts index de9ceb3b5..c549f2b93 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 similarity index 100% rename from src/web/app/common/scripts/is-promise.js rename to 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 similarity index 100% rename from src/web/app/common/scripts/loading.js rename to 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 similarity index 87% rename from src/web/app/common/scripts/messaging-stream.js rename to src/web/app/common/scripts/messaging-stream.ts index 261525d5f..63830f7b1 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 54333c8cf..a170daebb 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 { 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 similarity index 100% rename from src/web/app/common/scripts/server-stream.js rename to 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 similarity index 100% rename from src/web/app/common/scripts/signout.js rename to 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 000000000..4eaf0f9a4 --- /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 { + 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 similarity index 83% rename from src/web/app/common/scripts/stream.js rename to src/web/app/common/scripts/stream.ts index a03b7bf20..959524687 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 similarity index 94% rename from src/web/app/common/scripts/text-compiler.js rename to src/web/app/common/scripts/text-compiler.ts index 0a9b8022d..8c65d6a06 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) { diff --git a/src/web/app/common/tags/index.js b/src/web/app/common/tags/index.ts similarity index 100% rename from src/web/app/common/tags/index.js rename to src/web/app/common/tags/index.ts diff --git a/src/web/app/common/tags/messaging/message.tag b/src/web/app/common/tags/messaging/message.tag index d6db9070e..ea1ea2310 100644 --- a/src/web/app/common/tags/messaging/message.tag +++ b/src/web/app/common/tags/messaging/message.tag @@ -219,7 +219,7 @@ this.refs.text.innerHTML = compile(tokens); - this.refs.text.children.forEach(e => { + Array.from(this.refs.text.children).forEach(e => { if (e.tagName == 'MK-URL') riot.mount(e); }); diff --git a/src/web/app/desktop/mixins/index.js b/src/web/app/desktop/mixins/index.ts similarity index 100% rename from src/web/app/desktop/mixins/index.js rename to src/web/app/desktop/mixins/index.ts diff --git a/src/web/app/desktop/mixins/user-preview.js b/src/web/app/desktop/mixins/user-preview.ts similarity index 95% rename from src/web/app/desktop/mixins/user-preview.js rename to src/web/app/desktop/mixins/user-preview.ts index 3f483beb3..614de72be 100644 --- a/src/web/app/desktop/mixins/user-preview.js +++ b/src/web/app/desktop/mixins/user-preview.ts @@ -52,7 +52,7 @@ function attach(el) { clearTimeout(showTimer); hideTimer = setTimeout(close, 500); }); - tag = riot.mount(document.body.appendChild(preview), { + tag = (riot as any).mount(document.body.appendChild(preview), { user: user })[0]; }; diff --git a/src/web/app/desktop/mixins/widget.js b/src/web/app/desktop/mixins/widget.ts similarity index 95% rename from src/web/app/desktop/mixins/widget.js rename to src/web/app/desktop/mixins/widget.ts index cb04295fc..04131cd8f 100644 --- a/src/web/app/desktop/mixins/widget.js +++ b/src/web/app/desktop/mixins/widget.ts @@ -3,7 +3,7 @@ import * as riot from 'riot'; // ミックスインにオプションを渡せないのアレ // SEE: https://github.com/riot/riot/issues/2434 -riot.mixin('widget', { +(riot as any).mixin('widget', { init: function() { this.mixin('i'); this.mixin('api'); diff --git a/src/web/app/desktop/router.js b/src/web/app/desktop/router.ts similarity index 96% rename from src/web/app/desktop/router.js rename to src/web/app/desktop/router.ts index 4675b967d..a74299b28 100644 --- a/src/web/app/desktop/router.js +++ b/src/web/app/desktop/router.ts @@ -3,7 +3,7 @@ */ import * as riot from 'riot'; -const route = require('page'); +import * as route from 'page'; let page = null; export default me => { @@ -83,12 +83,12 @@ export default me => { mount(document.createElement('mk-not-found')); } - riot.mixin('page', { + (riot as any).mixin('page', { page: route }); // EXEC - route(); + (route as any)(); }; function mount(content) { diff --git a/src/web/app/desktop/script.js b/src/web/app/desktop/script.ts similarity index 87% rename from src/web/app/desktop/script.js rename to src/web/app/desktop/script.ts index 46a7fce70..a0453865e 100644 --- a/src/web/app/desktop/script.js +++ b/src/web/app/desktop/script.ts @@ -11,7 +11,7 @@ import * as riot from 'riot'; import init from '../init'; import route from './router'; import fuckAdBlock from './scripts/fuck-ad-block'; -import getPostSummary from '../../../common/get-post-summary.ts'; +import getPostSummary from '../../../common/get-post-summary'; /** * init @@ -27,11 +27,11 @@ init(async (me, stream) => { */ if ('Notification' in window) { // 許可を得ていなかったらリクエスト - if (Notification.permission == 'default') { + if ((Notification as any).permission == 'default') { await Notification.requestPermission(); } - if (Notification.permission == 'granted') { + if ((Notification as any).permission == 'granted') { registerNotifications(stream); } } @@ -82,7 +82,7 @@ function registerNotifications(stream) { }); n.onclick = () => { n.close(); - riot.mount(document.body.appendChild(document.createElement('mk-messaging-room-window')), { + (riot as any).mount(document.body.appendChild(document.createElement('mk-messaging-room-window')), { user: message.user }); }; diff --git a/src/web/app/desktop/scripts/autocomplete.js b/src/web/app/desktop/scripts/autocomplete.ts similarity index 86% rename from src/web/app/desktop/scripts/autocomplete.js rename to src/web/app/desktop/scripts/autocomplete.ts index 8ca516e2a..9df7aae08 100644 --- a/src/web/app/desktop/scripts/autocomplete.js +++ b/src/web/app/desktop/scripts/autocomplete.ts @@ -1,10 +1,12 @@ -const getCaretCoordinates = require('textarea-caret'); +import getCaretCoordinates = require('textarea-caret'); import * as riot from 'riot'; /** * オートコンプリートを管理するクラス。 */ class Autocomplete { + private suggestion: any; + private textarea: any; /** * 対象のテキストエリアを与えてインスタンスを初期化します。 @@ -23,22 +25,22 @@ class Autocomplete { /** * このインスタンスにあるテキストエリアの入力のキャプチャを開始します。 */ - attach() { + public attach() { this.textarea.addEventListener('input', this.onInput); } /** * このインスタンスにあるテキストエリアの入力のキャプチャを解除します。 */ - detach() { + public detach() { this.textarea.removeEventListener('input', this.onInput); this.close(); } /** - * [Private] テキスト入力時 + * テキスト入力時 */ - onInput() { + private onInput() { this.close(); const caret = this.textarea.selectionStart; @@ -56,9 +58,9 @@ class Autocomplete { } /** - * [Private] サジェストを提示します。 + * サジェストを提示します。 */ - open(type, q) { + private open(type, q) { // 既に開いているサジェストは閉じる this.close(); @@ -81,7 +83,7 @@ class Autocomplete { const el = document.body.appendChild(tag); // マウント - this.suggestion = riot.mount(el, { + this.suggestion = (riot as any).mount(el, { textarea: this.textarea, complete: this.complete, close: this.close, @@ -91,9 +93,9 @@ class Autocomplete { } /** - * [Private] サジェストを閉じます。 + * サジェストを閉じます。 */ - close() { + private close() { if (this.suggestion == null) return; this.suggestion.unmount(); @@ -103,9 +105,9 @@ class Autocomplete { } /** - * [Private] オートコンプリートする + * オートコンプリートする */ - complete(user) { + private complete(user) { this.close(); const value = user.username; diff --git a/src/web/app/desktop/scripts/dialog.js b/src/web/app/desktop/scripts/dialog.ts similarity index 77% rename from src/web/app/desktop/scripts/dialog.js rename to src/web/app/desktop/scripts/dialog.ts index c502d3fcb..816ba4b5f 100644 --- a/src/web/app/desktop/scripts/dialog.js +++ b/src/web/app/desktop/scripts/dialog.ts @@ -1,9 +1,9 @@ import * as riot from 'riot'; -export default (title, text, buttons, canThrough, onThrough) => { +export default (title, text, buttons, canThrough?, onThrough?) => { const dialog = document.body.appendChild(document.createElement('mk-dialog')); const controller = riot.observable(); - riot.mount(dialog, { + (riot as any).mount(dialog, { controller: controller, title: title, text: text, diff --git a/src/web/app/desktop/scripts/fuck-ad-block.js b/src/web/app/desktop/scripts/fuck-ad-block.ts similarity index 94% rename from src/web/app/desktop/scripts/fuck-ad-block.js rename to src/web/app/desktop/scripts/fuck-ad-block.ts index ccfc43ce6..3307ba2f3 100644 --- a/src/web/app/desktop/scripts/fuck-ad-block.js +++ b/src/web/app/desktop/scripts/fuck-ad-block.ts @@ -1,6 +1,8 @@ require('fuckadblock'); import dialog from './dialog'; +declare var fuckAdBlock: any; + export default () => { if (fuckAdBlock === undefined) { adBlockDetected(); diff --git a/src/web/app/desktop/scripts/input-dialog.js b/src/web/app/desktop/scripts/input-dialog.ts similarity index 88% rename from src/web/app/desktop/scripts/input-dialog.js rename to src/web/app/desktop/scripts/input-dialog.ts index 954fabfb6..b06d011c6 100644 --- a/src/web/app/desktop/scripts/input-dialog.js +++ b/src/web/app/desktop/scripts/input-dialog.ts @@ -2,7 +2,7 @@ import * as riot from 'riot'; export default (title, placeholder, defaultValue, onOk, onCancel) => { const dialog = document.body.appendChild(document.createElement('mk-input-dialog')); - return riot.mount(dialog, { + return (riot as any).mount(dialog, { title: title, placeholder: placeholder, 'default': defaultValue, diff --git a/src/web/app/desktop/scripts/not-implemented-exception.js b/src/web/app/desktop/scripts/not-implemented-exception.ts similarity index 100% rename from src/web/app/desktop/scripts/not-implemented-exception.js rename to src/web/app/desktop/scripts/not-implemented-exception.ts diff --git a/src/web/app/desktop/scripts/notify.js b/src/web/app/desktop/scripts/notify.ts similarity index 83% rename from src/web/app/desktop/scripts/notify.js rename to src/web/app/desktop/scripts/notify.ts index e58a8e4d3..2e6cbdeed 100644 --- a/src/web/app/desktop/scripts/notify.js +++ b/src/web/app/desktop/scripts/notify.ts @@ -2,7 +2,7 @@ import * as riot from 'riot'; export default message => { const notification = document.body.appendChild(document.createElement('mk-ui-notification')); - riot.mount(notification, { + (riot as any).mount(notification, { message: message }); }; diff --git a/src/web/app/desktop/scripts/password-dialog.js b/src/web/app/desktop/scripts/password-dialog.ts similarity index 86% rename from src/web/app/desktop/scripts/password-dialog.js rename to src/web/app/desktop/scripts/password-dialog.ts index 2bdc93e42..39d7f3db7 100644 --- a/src/web/app/desktop/scripts/password-dialog.js +++ b/src/web/app/desktop/scripts/password-dialog.ts @@ -2,7 +2,7 @@ import * as riot from 'riot'; export default (title, onOk, onCancel) => { const dialog = document.body.appendChild(document.createElement('mk-input-dialog')); - return riot.mount(dialog, { + return (riot as any).mount(dialog, { title: title, type: 'password', onOk: onOk, diff --git a/src/web/app/desktop/scripts/update-avatar.js b/src/web/app/desktop/scripts/update-avatar.ts similarity index 82% rename from src/web/app/desktop/scripts/update-avatar.js rename to src/web/app/desktop/scripts/update-avatar.ts index 165c90567..5fd7f2d3d 100644 --- a/src/web/app/desktop/scripts/update-avatar.js +++ b/src/web/app/desktop/scripts/update-avatar.ts @@ -5,7 +5,7 @@ import api from '../../common/scripts/api'; export default (I, cb, file = null) => { const fileSelected = file => { - const cropper = riot.mount(document.body.appendChild(document.createElement('mk-crop-window')), { + const cropper = (riot as any).mount(document.body.appendChild(document.createElement('mk-crop-window')), { file: file, title: 'アバターとして表示する部分を選択', aspectRatio: 1 / 1 @@ -37,7 +37,7 @@ export default (I, cb, file = null) => { }; const upload = (data, folder) => { - const progress = riot.mount(document.body.appendChild(document.createElement('mk-progress-dialog')), { + const progress = (riot as any).mount(document.body.appendChild(document.createElement('mk-progress-dialog')), { title: '新しいアバターをアップロードしています' })[0]; @@ -46,7 +46,7 @@ export default (I, cb, file = null) => { const xhr = new XMLHttpRequest(); xhr.open('POST', CONFIG.apiUrl + '/drive/files/create', true); xhr.onload = e => { - const file = JSON.parse(e.target.response); + const file = JSON.parse((e.target as any).response); progress.close(); set(file); }; @@ -75,7 +75,7 @@ export default (I, cb, file = null) => { if (file) { fileSelected(file); } else { - const browser = riot.mount(document.body.appendChild(document.createElement('mk-select-file-from-drive-window')), { + const browser = (riot as any).mount(document.body.appendChild(document.createElement('mk-select-file-from-drive-window')), { multiple: false, title: 'アバターにする画像を選択' })[0]; diff --git a/src/web/app/desktop/scripts/update-banner.js b/src/web/app/desktop/scripts/update-banner.ts similarity index 82% rename from src/web/app/desktop/scripts/update-banner.js rename to src/web/app/desktop/scripts/update-banner.ts index d83b2bf1b..23a671c44 100644 --- a/src/web/app/desktop/scripts/update-banner.js +++ b/src/web/app/desktop/scripts/update-banner.ts @@ -5,7 +5,7 @@ import api from '../../common/scripts/api'; export default (I, cb, file = null) => { const fileSelected = file => { - const cropper = riot.mount(document.body.appendChild(document.createElement('mk-crop-window')), { + const cropper = (riot as any).mount(document.body.appendChild(document.createElement('mk-crop-window')), { file: file, title: 'バナーとして表示する部分を選択', aspectRatio: 16 / 9 @@ -37,7 +37,7 @@ export default (I, cb, file = null) => { }; const upload = (data, folder) => { - const progress = riot.mount(document.body.appendChild(document.createElement('mk-progress-dialog')), { + const progress = (riot as any).mount(document.body.appendChild(document.createElement('mk-progress-dialog')), { title: '新しいバナーをアップロードしています' })[0]; @@ -46,7 +46,7 @@ export default (I, cb, file = null) => { const xhr = new XMLHttpRequest(); xhr.open('POST', CONFIG.apiUrl + '/drive/files/create', true); xhr.onload = e => { - const file = JSON.parse(e.target.response); + const file = JSON.parse((e.target as any).response); progress.close(); set(file); }; @@ -75,7 +75,7 @@ export default (I, cb, file = null) => { if (file) { fileSelected(file); } else { - const browser = riot.mount(document.body.appendChild(document.createElement('mk-select-file-from-drive-window')), { + const browser = (riot as any).mount(document.body.appendChild(document.createElement('mk-select-file-from-drive-window')), { multiple: false, title: 'バナーにする画像を選択' })[0]; diff --git a/src/web/app/desktop/tags/autocomplete-suggestion.tag b/src/web/app/desktop/tags/autocomplete-suggestion.tag index b93636040..731160669 100644 --- a/src/web/app/desktop/tags/autocomplete-suggestion.tag +++ b/src/web/app/desktop/tags/autocomplete-suggestion.tag @@ -177,7 +177,7 @@ }; this.applySelect = () => { - this.refs.users.children.forEach(el => { + Array.from(this.refs.users.children).forEach(el => { el.removeAttribute('data-selected'); }); diff --git a/src/web/app/desktop/tags/drive/browser.tag b/src/web/app/desktop/tags/drive/browser.tag index be16a782d..18e27f24b 100644 --- a/src/web/app/desktop/tags/drive/browser.tag +++ b/src/web/app/desktop/tags/drive/browser.tag @@ -408,7 +408,7 @@ // ドロップされてきたものがファイルだったら if (e.dataTransfer.files.length > 0) { - e.dataTransfer.files.forEach(file => { + Array.from(e.dataTransfer.files).forEach(file => { this.upload(file, this.folder); }); return false; @@ -510,7 +510,7 @@ }; this.changeFileInput = () => { - this.refs.fileInput.files.forEach(file => { + Array.from(this.refs.fileInput.files).forEach(file => { this.upload(file, this.folder); }); }; diff --git a/src/web/app/desktop/tags/drive/folder.tag b/src/web/app/desktop/tags/drive/folder.tag index e03c4e353..1c361c8e4 100644 --- a/src/web/app/desktop/tags/drive/folder.tag +++ b/src/web/app/desktop/tags/drive/folder.tag @@ -109,7 +109,7 @@ // ファイルだったら if (e.dataTransfer.files.length > 0) { - e.dataTransfer.files.forEach(file => { + Array.from(e.dataTransfer.files).forEach(file => { this.browser.upload(file, this.folder); }); return false; diff --git a/src/web/app/desktop/tags/drive/nav-folder.tag b/src/web/app/desktop/tags/drive/nav-folder.tag index c89d9edc1..0a9421353 100644 --- a/src/web/app/desktop/tags/drive/nav-folder.tag +++ b/src/web/app/desktop/tags/drive/nav-folder.tag @@ -55,7 +55,7 @@ // ファイルだったら if (e.dataTransfer.files.length > 0) { - e.dataTransfer.files.forEach(file => { + Array.from(e.dataTransfer.files).forEach(file => { this.browser.upload(file, this.folder); }); return false; diff --git a/src/web/app/desktop/tags/index.js b/src/web/app/desktop/tags/index.ts similarity index 100% rename from src/web/app/desktop/tags/index.js rename to src/web/app/desktop/tags/index.ts diff --git a/src/web/app/desktop/tags/post-detail-sub.tag b/src/web/app/desktop/tags/post-detail-sub.tag index 8a0ada5f2..e22386df9 100644 --- a/src/web/app/desktop/tags/post-detail-sub.tag +++ b/src/web/app/desktop/tags/post-detail-sub.tag @@ -129,7 +129,7 @@ this.refs.text.innerHTML = compile(tokens); - this.refs.text.children.forEach(e => { + Array.from(this.refs.text.children).forEach(e => { if (e.tagName == 'MK-URL') riot.mount(e); }); } diff --git a/src/web/app/desktop/tags/post-detail.tag b/src/web/app/desktop/tags/post-detail.tag index ce7f81e32..1a0eefe13 100644 --- a/src/web/app/desktop/tags/post-detail.tag +++ b/src/web/app/desktop/tags/post-detail.tag @@ -273,7 +273,7 @@ this.refs.text.innerHTML = compile(tokens); - this.refs.text.children.forEach(e => { + Array.from(this.refs.text.children).forEach(e => { if (e.tagName == 'MK-URL') riot.mount(e); }); diff --git a/src/web/app/desktop/tags/post-form.tag b/src/web/app/desktop/tags/post-form.tag index 5041078be..e49beeedb 100644 --- a/src/web/app/desktop/tags/post-form.tag +++ b/src/web/app/desktop/tags/post-form.tag @@ -405,7 +405,7 @@ // ファイルだったら if (e.dataTransfer.files.length > 0) { - e.dataTransfer.files.forEach(this.upload); + Array.from(e.dataTransfer.files).forEach(this.upload); } }; @@ -414,7 +414,7 @@ }; this.onpaste = e => { - e.clipboardData.items.forEach(item => { + Array.from(e.clipboardData.items).forEach(item => { if (item.kind == 'file') { this.upload(item.getAsFile()); } @@ -435,7 +435,7 @@ }; this.changeFile = () => { - this.refs.file.files.forEach(this.upload); + Array.from(this.refs.file.files).forEach(this.upload); }; this.upload = file => { diff --git a/src/web/app/desktop/tags/sub-post-content.tag b/src/web/app/desktop/tags/sub-post-content.tag index c75ae2911..86269fdbe 100644 --- a/src/web/app/desktop/tags/sub-post-content.tag +++ b/src/web/app/desktop/tags/sub-post-content.tag @@ -45,7 +45,7 @@ const tokens = this.post.ast; this.refs.text.innerHTML = compile(tokens, false); - this.refs.text.children.forEach(e => { + Array.from(this.refs.text.children).forEach(e => { if (e.tagName == 'MK-URL') riot.mount(e); }); } diff --git a/src/web/app/desktop/tags/timeline.tag b/src/web/app/desktop/tags/timeline.tag index 44f3d5d8e..5e3b883b4 100644 --- a/src/web/app/desktop/tags/timeline.tag +++ b/src/web/app/desktop/tags/timeline.tag @@ -498,7 +498,7 @@ this.refs.text.innerHTML = this.refs.text.innerHTML.replace('

', compile(tokens)); - this.refs.text.children.forEach(e => { + Array.from(this.refs.text.children).forEach(e => { if (e.tagName == 'MK-URL') riot.mount(e); }); diff --git a/src/web/app/dev/router.js b/src/web/app/dev/router.ts similarity index 94% rename from src/web/app/dev/router.js rename to src/web/app/dev/router.ts index 7fde30fa5..532ec23c7 100644 --- a/src/web/app/dev/router.js +++ b/src/web/app/dev/router.ts @@ -1,5 +1,5 @@ import * as riot from 'riot'; -const route = require('page'); +import * as route from 'page'; let page = null; export default me => { @@ -32,7 +32,7 @@ export default me => { } // EXEC - route(); + (route as any)(); }; function mount(content) { diff --git a/src/web/app/dev/script.js b/src/web/app/dev/script.ts similarity index 100% rename from src/web/app/dev/script.js rename to src/web/app/dev/script.ts diff --git a/src/web/app/dev/tags/index.js b/src/web/app/dev/tags/index.ts similarity index 100% rename from src/web/app/dev/tags/index.js rename to src/web/app/dev/tags/index.ts diff --git a/src/web/app/init.js b/src/web/app/init.ts similarity index 81% rename from src/web/app/init.js rename to src/web/app/init.ts index d3817fe97..e68a7c915 100644 --- a/src/web/app/init.js +++ b/src/web/app/init.ts @@ -2,14 +2,13 @@ * App initializer */ -'use strict'; +declare var VERSION: string; +declare var LANG: string; import * as riot from 'riot'; -import api from './common/scripts/api'; import signout from './common/scripts/signout'; import checkForUpdate from './common/scripts/check-for-update'; import Connection from './common/scripts/home-stream'; -import ServerStreamManager from './common/scripts/server-stream-manager.ts'; import Progress from './common/scripts/loading'; import mixin from './common/mixins'; import CONFIG from './common/scripts/config'; @@ -37,21 +36,7 @@ console.info(`Misskey v${VERSION} (葵 aoi)`); document.domain = CONFIG.host; // Set global configuration -riot.mixin({ CONFIG }); - -// ↓ NodeList、HTMLCollection、FileList、DataTransferItemListで forEach を使えるようにする -if (NodeList.prototype.forEach === undefined) { - NodeList.prototype.forEach = Array.prototype.forEach; -} -if (HTMLCollection.prototype.forEach === undefined) { - HTMLCollection.prototype.forEach = Array.prototype.forEach; -} -if (FileList.prototype.forEach === undefined) { - FileList.prototype.forEach = Array.prototype.forEach; -} -if (window.DataTransferItemList && DataTransferItemList.prototype.forEach === undefined) { - DataTransferItemList.prototype.forEach = Array.prototype.forEach; -} +(riot as any).mixin({ CONFIG }); // iOSでプライベートモードだとlocalStorageが使えないので既存のメソッドを上書きする try { @@ -72,7 +57,7 @@ setTimeout(checkForUpdate, 3000); // ユーザーをフェッチしてコールバックする export default callback => { // Get cached account data - let cachedMe = JSON.parse(localStorage.getItem('me')); + const cachedMe = JSON.parse(localStorage.getItem('me')); if (cachedMe) { fetched(cachedMe); @@ -112,11 +97,8 @@ export default callback => { // Init home stream connection const stream = me ? new Connection(me) : null; - // Init server stream connection manager - const serverStreamManager = new ServerStreamManager(); - // ミックスイン初期化 - mixin(me, stream, serverStreamManager); + mixin(me, stream); // ローディング画面クリア const ini = document.getElementById('ini'); diff --git a/src/web/app/mobile/router.js b/src/web/app/mobile/router.ts similarity index 97% rename from src/web/app/mobile/router.js rename to src/web/app/mobile/router.ts index 01eb3c814..7fae9db54 100644 --- a/src/web/app/mobile/router.js +++ b/src/web/app/mobile/router.ts @@ -3,7 +3,7 @@ */ import * as riot from 'riot'; -const route = require('page'); +import * as route from 'page'; let page = null; export default me => { @@ -131,12 +131,12 @@ export default me => { mount(document.createElement('mk-not-found')); } - riot.mixin('page', { + (riot as any).mixin('page', { page: route }); // EXEC - route(); + (route as any)(); }; function mount(content) { diff --git a/src/web/app/mobile/script.js b/src/web/app/mobile/script.ts similarity index 100% rename from src/web/app/mobile/script.js rename to src/web/app/mobile/script.ts diff --git a/src/web/app/mobile/scripts/open-post-form.js b/src/web/app/mobile/scripts/open-post-form.ts similarity index 100% rename from src/web/app/mobile/scripts/open-post-form.js rename to src/web/app/mobile/scripts/open-post-form.ts diff --git a/src/web/app/mobile/scripts/ui-event.js b/src/web/app/mobile/scripts/ui-event.ts similarity index 100% rename from src/web/app/mobile/scripts/ui-event.js rename to src/web/app/mobile/scripts/ui-event.ts diff --git a/src/web/app/mobile/tags/drive.tag b/src/web/app/mobile/tags/drive.tag index 6929c50ab..870a451ac 100644 --- a/src/web/app/mobile/tags/drive.tag +++ b/src/web/app/mobile/tags/drive.tag @@ -561,7 +561,7 @@ }; this.changeLocalFile = () => { - this.refs.file.files.forEach(f => this.refs.uploader.upload(f, this.folder)); + Array.from(this.refs.file.files).forEach(f => this.refs.uploader.upload(f, this.folder)); }; diff --git a/src/web/app/mobile/tags/index.js b/src/web/app/mobile/tags/index.ts similarity index 100% rename from src/web/app/mobile/tags/index.js rename to src/web/app/mobile/tags/index.ts diff --git a/src/web/app/mobile/tags/post-detail.tag b/src/web/app/mobile/tags/post-detail.tag index 8a3210103..28071a5ca 100644 --- a/src/web/app/mobile/tags/post-detail.tag +++ b/src/web/app/mobile/tags/post-detail.tag @@ -285,7 +285,7 @@ this.refs.text.innerHTML = compile(tokens); - this.refs.text.children.forEach(e => { + Array.from(this.refs.text.children).forEach(e => { if (e.tagName == 'MK-URL') riot.mount(e); }); diff --git a/src/web/app/mobile/tags/post-form.tag b/src/web/app/mobile/tags/post-form.tag index d7d382c9e..2912bfdfa 100644 --- a/src/web/app/mobile/tags/post-form.tag +++ b/src/web/app/mobile/tags/post-form.tag @@ -207,7 +207,7 @@ }; this.onpaste = e => { - e.clipboardData.items.forEach(item => { + Array.from(e.clipboardData.items).forEach(item => { if (item.kind == 'file') { this.upload(item.getAsFile()); } @@ -228,7 +228,7 @@ }; this.changeFile = () => { - this.refs.file.files.forEach(this.upload); + Array.from(this.refs.file.files).forEach(this.upload); }; this.upload = file => { diff --git a/src/web/app/mobile/tags/sub-post-content.tag b/src/web/app/mobile/tags/sub-post-content.tag index e32e24518..c14233d3b 100644 --- a/src/web/app/mobile/tags/sub-post-content.tag +++ b/src/web/app/mobile/tags/sub-post-content.tag @@ -37,7 +37,7 @@ const tokens = this.post.ast; this.refs.text.innerHTML = compile(tokens, false); - this.refs.text.children.forEach(e => { + Array.from(this.refs.text.children).forEach(e => { if (e.tagName == 'MK-URL') riot.mount(e); }); } diff --git a/src/web/app/mobile/tags/timeline.tag b/src/web/app/mobile/tags/timeline.tag index f9ec2cca6..52f6f27ea 100644 --- a/src/web/app/mobile/tags/timeline.tag +++ b/src/web/app/mobile/tags/timeline.tag @@ -538,7 +538,7 @@ this.refs.text.innerHTML = this.refs.text.innerHTML.replace('

', compile(tokens)); - this.refs.text.children.forEach(e => { + Array.from(this.refs.text.children).forEach(e => { if (e.tagName == 'MK-URL') riot.mount(e); }); diff --git a/src/web/app/stats/script.js b/src/web/app/stats/script.ts similarity index 100% rename from src/web/app/stats/script.js rename to src/web/app/stats/script.ts diff --git a/src/web/app/stats/tags/index.js b/src/web/app/stats/tags/index.ts similarity index 100% rename from src/web/app/stats/tags/index.js rename to src/web/app/stats/tags/index.ts diff --git a/src/web/app/status/script.js b/src/web/app/status/script.ts similarity index 100% rename from src/web/app/status/script.js rename to src/web/app/status/script.ts diff --git a/src/web/app/status/tags/index.js b/src/web/app/status/tags/index.ts similarity index 100% rename from src/web/app/status/tags/index.js rename to src/web/app/status/tags/index.ts diff --git a/tslint.json b/tslint.json index 1c4457951..d3f96000b 100644 --- a/tslint.json +++ b/tslint.json @@ -13,6 +13,7 @@ "object-literal-sort-keys": false, "curly": false, "no-console": [false], + "no-empty":false, "ordered-imports": [false], "arrow-parens": false, "object-literal-shorthand": false, diff --git a/webpack/webpack.config.ts b/webpack/webpack.config.ts index 97782a410..f2bcf48f3 100644 --- a/webpack/webpack.config.ts +++ b/webpack/webpack.config.ts @@ -14,13 +14,13 @@ module.exports = langs.map(([lang, locale]) => { // Entries const entry = { - desktop: './src/web/app/desktop/script.js', - mobile: './src/web/app/mobile/script.js', - ch: './src/web/app/ch/script.js', - stats: './src/web/app/stats/script.js', - status: './src/web/app/status/script.js', - dev: './src/web/app/dev/script.js', - auth: './src/web/app/auth/script.js' + desktop: './src/web/app/desktop/script.ts', + mobile: './src/web/app/mobile/script.ts', + ch: './src/web/app/ch/script.ts', + stats: './src/web/app/stats/script.ts', + status: './src/web/app/status/script.ts', + dev: './src/web/app/dev/script.ts', + auth: './src/web/app/auth/script.ts' }; const output = { @@ -33,6 +33,11 @@ module.exports = langs.map(([lang, locale]) => { entry, module: module_(lang, locale), plugins: plugins(version, lang), - output + output, + resolve: { + extensions: [ + '.js', '.ts' + ] + } }; }); From b42e6a9655b128c2d3621aac4c1ec999bbbcaf00 Mon Sep 17 00:00:00 2001 From: syuilo Date: Mon, 13 Nov 2017 19:58:29 +0900 Subject: [PATCH 192/327] Add access log widget --- locales/en.yml | 3 + locales/ja.yml | 3 + src/api/stream/requests.ts | 19 ++++ src/api/streaming.ts | 6 ++ src/log-request.ts | 21 +++++ src/server.ts | 6 ++ src/web/app/common/mixins/index.ts | 2 + .../common/scripts/requests-stream-manager.ts | 12 +++ src/web/app/common/scripts/requests-stream.ts | 14 +++ .../desktop/tags/home-widgets/access-log.tag | 93 +++++++++++++++++++ src/web/app/desktop/tags/home.tag | 1 + src/web/app/desktop/tags/index.ts | 1 + 12 files changed, 181 insertions(+) create mode 100644 src/api/stream/requests.ts create mode 100644 src/log-request.ts create mode 100644 src/web/app/common/scripts/requests-stream-manager.ts create mode 100644 src/web/app/common/scripts/requests-stream.ts create mode 100644 src/web/app/desktop/tags/home-widgets/access-log.tag diff --git a/locales/en.yml b/locales/en.yml index 574af26a6..d464b2fe2 100644 --- a/locales/en.yml +++ b/locales/en.yml @@ -390,6 +390,9 @@ desktop: post: "Post" placeholder: "What's happening?" + mk-access-log-home-widget: + title: "Access log" + mk-repost-form: quote: "Quote..." cancel: "Cancel" diff --git a/locales/ja.yml b/locales/ja.yml index 9e6251d0d..5c6f8e38e 100644 --- a/locales/ja.yml +++ b/locales/ja.yml @@ -390,6 +390,9 @@ desktop: post: "投稿" placeholder: "いまどうしてる?" + mk-access-log-home-widget: + title: "アクセスログ" + mk-repost-form: quote: "引用する..." cancel: "キャンセル" diff --git a/src/api/stream/requests.ts b/src/api/stream/requests.ts new file mode 100644 index 000000000..2c36e58b6 --- /dev/null +++ b/src/api/stream/requests.ts @@ -0,0 +1,19 @@ +import * as websocket from 'websocket'; +import Xev from 'xev'; + +const ev = new Xev(); + +export default function homeStream(request: websocket.request, connection: websocket.connection): void { + const onRequest = request => { + connection.send(JSON.stringify({ + type: 'request', + body: request + })); + }; + + ev.addListener('request', onRequest); + + connection.on('close', () => { + ev.removeListener('request', onRequest); + }); +} diff --git a/src/api/streaming.ts b/src/api/streaming.ts index 0e512fb21..6caf7db3e 100644 --- a/src/api/streaming.ts +++ b/src/api/streaming.ts @@ -9,6 +9,7 @@ import isNativeToken from './common/is-native-token'; import homeStream from './stream/home'; import messagingStream from './stream/messaging'; import serverStream from './stream/server'; +import requestsStream from './stream/requests'; import channelStream from './stream/channel'; module.exports = (server: http.Server) => { @@ -27,6 +28,11 @@ module.exports = (server: http.Server) => { return; } + if (request.resourceURL.pathname === '/requests') { + requestsStream(request, connection); + return; + } + // Connect to Redis const subscriber = redis.createClient( config.redis.port, config.redis.host); diff --git a/src/log-request.ts b/src/log-request.ts new file mode 100644 index 000000000..e431aa271 --- /dev/null +++ b/src/log-request.ts @@ -0,0 +1,21 @@ +import * as crypto from 'crypto'; +import * as express from 'express'; +import * as proxyAddr from 'proxy-addr'; +import Xev from 'xev'; + +const ev = new Xev(); + +export default function(req: express.Request) { + const ip = proxyAddr(req, () => true); + + const md5 = crypto.createHash('md5'); + md5.update(ip); + const hashedIp = md5.digest('hex').substr(0, 3); + + ev.emit('request', { + ip: hashedIp, + method: req.method, + hostname: req.hostname, + path: req.originalUrl + }); +} diff --git a/src/server.ts b/src/server.ts index 3e9bd44ee..9cf44eb0d 100644 --- a/src/server.ts +++ b/src/server.ts @@ -11,6 +11,7 @@ import * as morgan from 'morgan'; import Accesses from 'accesses'; import vhost = require('vhost'); +import log from './log-request'; import config from './conf'; /** @@ -35,6 +36,11 @@ app.use(morgan(process.env.NODE_ENV == 'production' ? 'combined' : 'dev', { stream: config.accesslog ? fs.createWriteStream(config.accesslog) : null })); +app.use((req, res, next) => { + log(req); + next(); +}); + // Drop request when without 'Host' header app.use((req, res, next) => { if (!req.headers['host']) { diff --git a/src/web/app/common/mixins/index.ts b/src/web/app/common/mixins/index.ts index 45427fb9d..a11bfa7b6 100644 --- a/src/web/app/common/mixins/index.ts +++ b/src/web/app/common/mixins/index.ts @@ -3,6 +3,7 @@ import * as riot from 'riot'; import activateMe from './i'; import activateApi from './api'; import ServerStreamManager from '../scripts/server-stream-manager'; +import RequestsStreamManager from '../scripts/requests-stream-manager'; export default (me, stream) => { activateMe(me); @@ -11,4 +12,5 @@ export default (me, stream) => { (riot as any).mixin('stream', { stream }); (riot as any).mixin('server-stream', { serverStream: new ServerStreamManager() }); + (riot as any).mixin('requests-stream', { requestsStream: new RequestsStreamManager() }); }; diff --git a/src/web/app/common/scripts/requests-stream-manager.ts b/src/web/app/common/scripts/requests-stream-manager.ts new file mode 100644 index 000000000..44db913e7 --- /dev/null +++ b/src/web/app/common/scripts/requests-stream-manager.ts @@ -0,0 +1,12 @@ +import StreamManager from './stream-manager'; +import Connection from './requests-stream'; + +export default class RequestsStreamManager extends StreamManager { + public getConnection() { + if (this.connection == null) { + this.connection = new Connection(); + } + + return this.connection; + } +} diff --git a/src/web/app/common/scripts/requests-stream.ts b/src/web/app/common/scripts/requests-stream.ts new file mode 100644 index 000000000..325224587 --- /dev/null +++ b/src/web/app/common/scripts/requests-stream.ts @@ -0,0 +1,14 @@ +'use strict'; + +import Stream from './stream'; + +/** + * Requests stream connection + */ +class Connection extends Stream { + constructor() { + super('requests'); + } +} + +export default Connection; diff --git a/src/web/app/desktop/tags/home-widgets/access-log.tag b/src/web/app/desktop/tags/home-widgets/access-log.tag new file mode 100644 index 000000000..a14857756 --- /dev/null +++ b/src/web/app/desktop/tags/home-widgets/access-log.tag @@ -0,0 +1,93 @@ + + +

%i18n:desktop.tags.mk-access-log-home-widget.title%

+
+
+

+ { ip } + { method } + { path } +

+
+ + +
diff --git a/src/web/app/desktop/tags/home.tag b/src/web/app/desktop/tags/home.tag index fd286851d..88d06d2ba 100644 --- a/src/web/app/desktop/tags/home.tag +++ b/src/web/app/desktop/tags/home.tag @@ -20,6 +20,7 @@ + diff --git a/src/web/app/desktop/tags/index.ts b/src/web/app/desktop/tags/index.ts index 15677471c..8b5a52d67 100644 --- a/src/web/app/desktop/tags/index.ts +++ b/src/web/app/desktop/tags/index.ts @@ -43,6 +43,7 @@ require('./home-widgets/slideshow.tag'); require('./home-widgets/channel.tag'); require('./home-widgets/timemachine.tag'); require('./home-widgets/post-form.tag'); +require('./home-widgets/access-log.tag'); require('./timeline.tag'); require('./messaging/window.tag'); require('./messaging/room-window.tag'); From a01767d3e50d5a030e11ac4951b5b969633aba08 Mon Sep 17 00:00:00 2001 From: syuilo Date: Tue, 14 Nov 2017 00:54:16 +0900 Subject: [PATCH 193/327] Add messaging widget --- locales/en.yml | 3 + locales/ja.yml | 3 + src/api/common/read-messaging-message.ts | 2 + .../endpoints/messaging/messages/create.ts | 3 + src/api/event.ts | 6 ++ src/api/stream/messaging-index.ts | 10 +++ src/api/streaming.ts | 2 + src/web/app/common/mixins/index.ts | 2 + .../scripts/messaging-index-stream-manager.ts | 20 +++++ .../common/scripts/messaging-index-stream.ts | 14 ++++ src/web/app/common/tags/messaging/index.tag | 76 +++++++++++++++++-- .../desktop/tags/home-widgets/messaging.tag | 50 ++++++++++++ src/web/app/desktop/tags/home.tag | 1 + src/web/app/desktop/tags/index.ts | 1 + 14 files changed, 186 insertions(+), 7 deletions(-) create mode 100644 src/api/stream/messaging-index.ts create mode 100644 src/web/app/common/scripts/messaging-index-stream-manager.ts create mode 100644 src/web/app/common/scripts/messaging-index-stream.ts create mode 100644 src/web/app/desktop/tags/home-widgets/messaging.tag diff --git a/locales/en.yml b/locales/en.yml index d464b2fe2..d6fcd1e6d 100644 --- a/locales/en.yml +++ b/locales/en.yml @@ -393,6 +393,9 @@ desktop: mk-access-log-home-widget: title: "Access log" + mk-messaging-home-widget: + title: "Messaging" + mk-repost-form: quote: "Quote..." cancel: "Cancel" diff --git a/locales/ja.yml b/locales/ja.yml index 5c6f8e38e..478afac13 100644 --- a/locales/ja.yml +++ b/locales/ja.yml @@ -393,6 +393,9 @@ desktop: mk-access-log-home-widget: title: "アクセスログ" + mk-messaging-home-widget: + title: "メッセージ" + mk-repost-form: quote: "引用する..." cancel: "キャンセル" diff --git a/src/api/common/read-messaging-message.ts b/src/api/common/read-messaging-message.ts index 3257ec8b0..8e5e5b2b6 100644 --- a/src/api/common/read-messaging-message.ts +++ b/src/api/common/read-messaging-message.ts @@ -3,6 +3,7 @@ import Message from '../models/messaging-message'; import { IMessagingMessage as IMessage } from '../models/messaging-message'; import publishUserStream from '../event'; import { publishMessagingStream } from '../event'; +import { publishMessagingIndexStream } from '../event'; /** * Mark as read message(s) @@ -49,6 +50,7 @@ export default ( // Publish event publishMessagingStream(otherpartyId, userId, 'read', ids.map(id => id.toString())); + publishMessagingIndexStream(userId, 'read', ids.map(id => id.toString())); // Calc count of my unread messages const count = await Message diff --git a/src/api/endpoints/messaging/messages/create.ts b/src/api/endpoints/messaging/messages/create.ts index 149852c09..29a4671f8 100644 --- a/src/api/endpoints/messaging/messages/create.ts +++ b/src/api/endpoints/messaging/messages/create.ts @@ -10,6 +10,7 @@ import DriveFile from '../../../models/drive-file'; import serialize from '../../../serializers/messaging-message'; import publishUserStream from '../../../event'; import { publishMessagingStream } from '../../../event'; +import { publishMessagingIndexStream } from '../../../event'; import config from '../../../../conf'; /** @@ -85,10 +86,12 @@ module.exports = (params, user) => new Promise(async (res, rej) => { // 自分のストリーム publishMessagingStream(message.user_id, message.recipient_id, 'message', messageObj); + publishMessagingIndexStream(message.user_id, 'message', messageObj); publishUserStream(message.user_id, 'messaging_message', messageObj); // 相手のストリーム publishMessagingStream(message.recipient_id, message.user_id, 'message', messageObj); + publishMessagingIndexStream(message.recipient_id, 'message', messageObj); publishUserStream(message.recipient_id, 'messaging_message', messageObj); // 3秒経っても(今回作成した)メッセージが既読にならなかったら「未読のメッセージがありますよ」イベントを発行する diff --git a/src/api/event.ts b/src/api/event.ts index 909b0d255..927883737 100644 --- a/src/api/event.ts +++ b/src/api/event.ts @@ -25,6 +25,10 @@ class MisskeyEvent { this.publish(`messaging-stream:${userId}-${otherpartyId}`, type, typeof value === 'undefined' ? null : value); } + public publishMessagingIndexStream(userId: ID, type: string, value?: any): void { + this.publish(`messaging-index-stream:${userId}`, type, typeof value === 'undefined' ? null : value); + } + public publishChannelStream(channelId: ID, type: string, value?: any): void { this.publish(`channel-stream:${channelId}`, type, typeof value === 'undefined' ? null : value); } @@ -46,4 +50,6 @@ export const publishPostStream = ev.publishPostStream.bind(ev); export const publishMessagingStream = ev.publishMessagingStream.bind(ev); +export const publishMessagingIndexStream = ev.publishMessagingIndexStream.bind(ev); + export const publishChannelStream = ev.publishChannelStream.bind(ev); diff --git a/src/api/stream/messaging-index.ts b/src/api/stream/messaging-index.ts new file mode 100644 index 000000000..c1b2fbc80 --- /dev/null +++ b/src/api/stream/messaging-index.ts @@ -0,0 +1,10 @@ +import * as websocket from 'websocket'; +import * as redis from 'redis'; + +export default function(request: websocket.request, connection: websocket.connection, subscriber: redis.RedisClient, user: any): void { + // Subscribe messaging index stream + subscriber.subscribe(`misskey:messaging-index-stream:${user._id}`); + subscriber.on('message', (_, data) => { + connection.send(data); + }); +} diff --git a/src/api/streaming.ts b/src/api/streaming.ts index 6caf7db3e..1f0ba848c 100644 --- a/src/api/streaming.ts +++ b/src/api/streaming.ts @@ -8,6 +8,7 @@ import isNativeToken from './common/is-native-token'; import homeStream from './stream/home'; import messagingStream from './stream/messaging'; +import messagingIndexStream from './stream/messaging-index'; import serverStream from './stream/server'; import requestsStream from './stream/requests'; import channelStream from './stream/channel'; @@ -58,6 +59,7 @@ module.exports = (server: http.Server) => { const channel = request.resourceURL.pathname === '/' ? homeStream : request.resourceURL.pathname === '/messaging' ? messagingStream : + request.resourceURL.pathname === '/messaging-index' ? messagingIndexStream : null; if (channel !== null) { diff --git a/src/web/app/common/mixins/index.ts b/src/web/app/common/mixins/index.ts index a11bfa7b6..c0c1c0555 100644 --- a/src/web/app/common/mixins/index.ts +++ b/src/web/app/common/mixins/index.ts @@ -4,6 +4,7 @@ import activateMe from './i'; import activateApi from './api'; import ServerStreamManager from '../scripts/server-stream-manager'; import RequestsStreamManager from '../scripts/requests-stream-manager'; +import MessagingIndexStream from '../scripts/messaging-index-stream-manager'; export default (me, stream) => { activateMe(me); @@ -13,4 +14,5 @@ export default (me, stream) => { (riot as any).mixin('server-stream', { serverStream: new ServerStreamManager() }); (riot as any).mixin('requests-stream', { requestsStream: new RequestsStreamManager() }); + (riot as any).mixin('messaging-index-stream', { messagingIndexStream: new MessagingIndexStream(me) }); }; diff --git a/src/web/app/common/scripts/messaging-index-stream-manager.ts b/src/web/app/common/scripts/messaging-index-stream-manager.ts new file mode 100644 index 000000000..dc386204c --- /dev/null +++ b/src/web/app/common/scripts/messaging-index-stream-manager.ts @@ -0,0 +1,20 @@ +import StreamManager from './stream-manager'; +import Connection from './messaging-index-stream'; + +export default class ServerStreamManager extends StreamManager { + private me; + + constructor(me) { + super(); + + this.me = me; + } + + public getConnection() { + if (this.connection == null) { + this.connection = new Connection(this.me); + } + + return this.connection; + } +} diff --git a/src/web/app/common/scripts/messaging-index-stream.ts b/src/web/app/common/scripts/messaging-index-stream.ts new file mode 100644 index 000000000..c194e663c --- /dev/null +++ b/src/web/app/common/scripts/messaging-index-stream.ts @@ -0,0 +1,14 @@ +import Stream from './stream'; + +/** + * Messaging index stream connection + */ +class Connection extends Stream { + constructor(me) { + super('messaging-index', { + i: me.token + }); + } +} + +export default Connection; diff --git a/src/web/app/common/tags/messaging/index.tag b/src/web/app/common/tags/messaging/index.tag index 731c9da2c..4c1bf0c6e 100644 --- a/src/web/app/common/tags/messaging/index.tag +++ b/src/web/app/common/tags/messaging/index.tag @@ -1,5 +1,5 @@ - - + +

%i18n:desktop.tags.mk-user.frequently-replied-users.title%

+

%i18n:desktop.tags.mk-user.frequently-replied-users.loading%

+
+ + + +
+ { _user.name } +

@{ _user.username }

+
+ +
+

%i18n:desktop.tags.mk-user.frequently-replied-users.no-users%

+ + +
+ + +

%i18n:desktop.tags.mk-user.followers-you-know.title%

+

%i18n:desktop.tags.mk-user.followers-you-know.loading%

+
0 }> + + { + +
+

%i18n:desktop.tags.mk-user.followers-you-know.no-users%

+ + +
+
+
@@ -405,6 +591,7 @@
+
From da51161eb9fae030914f2906b5cc71198e7189bf Mon Sep 17 00:00:00 2001 From: syuilo Date: Wed, 15 Nov 2017 06:45:54 +0900 Subject: [PATCH 237/327] nanka iroiro --- locales/en.yml | 20 +- locales/ja.yml | 20 +- src/web/app/common/tags/index.ts | 1 + src/web/app/common/tags/nav-links.tag | 7 + src/web/app/desktop/assets/index.jpg | 3 + src/web/app/desktop/tags/home-widgets/nav.tag | 3 +- src/web/app/desktop/tags/index.ts | 2 - src/web/app/desktop/tags/pages/entrance.tag | 326 +++++++++++++++--- .../desktop/tags/pages/entrance/signin.tag | 134 ------- .../desktop/tags/pages/entrance/signup.tag | 47 --- src/web/app/desktop/tags/user.tag | 24 ++ 11 files changed, 339 insertions(+), 248 deletions(-) create mode 100644 src/web/app/common/tags/nav-links.tag create mode 100644 src/web/app/desktop/assets/index.jpg delete mode 100644 src/web/app/desktop/tags/pages/entrance/signin.tag delete mode 100644 src/web/app/desktop/tags/pages/entrance/signup.tag diff --git a/locales/en.yml b/locales/en.yml index e7d878f20..a2bd9aa1b 100644 --- a/locales/en.yml +++ b/locales/en.yml @@ -50,6 +50,15 @@ common: my-token-regenerated: "Your token is just regenerated, so you will signout." tags: + mk-nav-links: + about: "About" + stats: "Stats" + status: "Status" + wiki: "Wiki" + donors: "Donors" + repository: "Repository" + develop: "Developers" + mk-messaging-form: attach-from-local: "Attach file from your pc" attach-from-drive: "Attach file from the drive" @@ -256,15 +265,6 @@ desktop: cancel: "Cancel" upload: "Upload a file(s) from you PC" - mk-nav-home-widget: - about: "About" - stats: "Stats" - status: "Status" - wiki: "Wiki" - donors: "Donors" - repository: "Repository" - develop: "Developers" - mk-ui-header-nav: home: "Home" messaging: "Messages" @@ -408,6 +408,8 @@ desktop: title: "Are you sure you want to repost this post?" mk-user: + last-used-at: "Last used at" + photos: title: "Photos" loading: "Loading" diff --git a/locales/ja.yml b/locales/ja.yml index f386a3824..d0292e8c4 100644 --- a/locales/ja.yml +++ b/locales/ja.yml @@ -50,6 +50,15 @@ common: my-token-regenerated: "あなたのトークンが更新されたのでサインアウトします。" tags: + mk-nav-links: + about: "Misskeyについて" + stats: "統計" + status: "ステータス" + wiki: "Wiki" + donors: "ドナー" + repository: "リポジトリ" + develop: "開発者" + mk-messaging-form: attach-from-local: "PCからファイルを添付する" attach-from-drive: "ドライブからファイルを添付する" @@ -256,15 +265,6 @@ desktop: cancel: "キャンセル" upload: "PCからドライブにファイルをアップロード" - mk-nav-home-widget: - about: "Misskeyについて" - stats: "統計" - status: "ステータス" - wiki: "Wiki" - donors: "ドナー" - repository: "リポジトリ" - develop: "開発者" - mk-ui-header-nav: home: "ホーム" messaging: "メッセージ" @@ -408,6 +408,8 @@ desktop: title: "この投稿をRepostしますか?" mk-user: + last-used-at: "最終アクセス" + photos: title: "フォト" loading: "読み込み中" diff --git a/src/web/app/common/tags/index.ts b/src/web/app/common/tags/index.ts index 35a9f4586..2f4e1181d 100644 --- a/src/web/app/common/tags/index.ts +++ b/src/web/app/common/tags/index.ts @@ -28,3 +28,4 @@ require('./reaction-picker.tag'); require('./reactions-viewer.tag'); require('./reaction-icon.tag'); require('./post-menu.tag'); +require('./nav-links.tag'); diff --git a/src/web/app/common/tags/nav-links.tag b/src/web/app/common/tags/nav-links.tag new file mode 100644 index 000000000..b09e376b3 --- /dev/null +++ b/src/web/app/common/tags/nav-links.tag @@ -0,0 +1,7 @@ + + %i18n:common.tags.mk-nav-links.about%%i18n:common.tags.mk-nav-links.stats%%i18n:common.tags.mk-nav-links.status%%i18n:common.tags.mk-nav-links.wiki%%i18n:common.tags.mk-nav-links.donors%%i18n:common.tags.mk-nav-links.repository%%i18n:common.tags.mk-nav-links.develop%Follow us on + + diff --git a/src/web/app/desktop/assets/index.jpg b/src/web/app/desktop/assets/index.jpg new file mode 100644 index 000000000..ebf0496a4 --- /dev/null +++ b/src/web/app/desktop/assets/index.jpg @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:0e8f1670fe0544be7531a5e0c3fd13d2383b9bcec27865eb9f9511c76aa7ed0b +size 410409 diff --git a/src/web/app/desktop/tags/home-widgets/nav.tag b/src/web/app/desktop/tags/home-widgets/nav.tag index f17900573..61c0b4cb5 100644 --- a/src/web/app/desktop/tags/home-widgets/nav.tag +++ b/src/web/app/desktop/tags/home-widgets/nav.tag @@ -1,4 +1,5 @@ -%i18n:desktop.tags.mk-nav-home-widget.about%%i18n:desktop.tags.mk-nav-home-widget.stats%%i18n:desktop.tags.mk-nav-home-widget.status%%i18n:desktop.tags.mk-nav-home-widget.wiki%%i18n:desktop.tags.mk-nav-home-widget.donors%%i18n:desktop.tags.mk-nav-home-widget.repository%%i18n:desktop.tags.mk-nav-home-widget.develop%Follow us on + + + + + +
+

+

{ user ? user.name : 'アカウント' }

+

+ +
+
or
+ Misskeyについて + + +
+ + + + + + diff --git a/src/web/app/desktop/tags/pages/entrance/signin.tag b/src/web/app/desktop/tags/pages/entrance/signin.tag deleted file mode 100644 index 0b3341249..000000000 --- a/src/web/app/desktop/tags/pages/entrance/signin.tag +++ /dev/null @@ -1,134 +0,0 @@ - -
-

-

{ user ? user.name : 'アカウント' }

-

- -
-
or
- Misskeyについて - - -
diff --git a/src/web/app/desktop/tags/pages/entrance/signup.tag b/src/web/app/desktop/tags/pages/entrance/signup.tag deleted file mode 100644 index 0722d82a6..000000000 --- a/src/web/app/desktop/tags/pages/entrance/signup.tag +++ /dev/null @@ -1,47 +0,0 @@ - - - - - diff --git a/src/web/app/desktop/tags/user.tag b/src/web/app/desktop/tags/user.tag index f01d2a039..d944bb33a 100644 --- a/src/web/app/desktop/tags/user.tag +++ b/src/web/app/desktop/tags/user.tag @@ -610,6 +610,7 @@ +

%i18n:desktop.tags.mk-user.last-used-at%:

@@ -619,6 +620,7 @@ + diff --git a/src/web/app/desktop/tags/home-widgets/broadcast.tag b/src/web/app/desktop/tags/home-widgets/broadcast.tag index 7caf4dcdd..00fef8374 100644 --- a/src/web/app/desktop/tags/home-widgets/broadcast.tag +++ b/src/web/app/desktop/tags/home-widgets/broadcast.tag @@ -1,4 +1,4 @@ - +
@@ -8,22 +8,35 @@
-

開発者募集中!

-

Misskeyはオープンソースで開発されています。リポジトリはこちら。

+

%i18n:desktop.tags.mk-broadcast-home-widget.fetching%

+

{ + broadcasts.length == 0 ? '%i18n:desktop.tags.mk-broadcast-home-widget.no-broadcasts%' : broadcasts[i].title + }

+

%i18n:desktop.tags.mk-broadcast-home-widget.have-a-nice-day%

+ 1 } onclick={ next }>%i18n:desktop.tags.mk-broadcast-home-widget.next% >>
From 816306d1524f3d28345c0a16a740fa68995f42d4 Mon Sep 17 00:00:00 2001 From: syuilo Date: Thu, 16 Nov 2017 14:21:08 +0900 Subject: [PATCH 248/327] v3121 --- CHANGELOG.md | 6 ++++++ package.json | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 396108552..ec522bbfa 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,12 @@ ChangeLog (Release Notes) ========================= 主に notable な changes を書いていきます +3121 (2017/11/16) +----------------- +* ブロードキャストウィジェットの強化 +* デザインのグリッチの修正 +* 通信の最適化 + 3113 (2017/11/15) ----------------- * アクティビティのレンダリングの問題の修正など diff --git a/package.json b/package.json index 4535ebcb1..68c558ec2 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "misskey", "author": "syuilo ", - "version": "0.0.3113", + "version": "0.0.3121", "license": "MIT", "description": "A miniblog-based SNS", "bugs": "https://github.com/syuilo/misskey/issues", From de6d679e207991aed322583d20de6badf915e637 Mon Sep 17 00:00:00 2001 From: syuilo Date: Thu, 16 Nov 2017 22:49:58 +0900 Subject: [PATCH 249/327] Fix #924 and some readability improvements --- src/api/common/add-file-to-drive.ts | 116 +++++++++++++++------------- 1 file changed, 64 insertions(+), 52 deletions(-) diff --git a/src/api/common/add-file-to-drive.ts b/src/api/common/add-file-to-drive.ts index 9ed5e8874..f96f58cb6 100644 --- a/src/api/common/add-file-to-drive.ts +++ b/src/api/common/add-file-to-drive.ts @@ -1,18 +1,20 @@ +import { Buffer } from 'buffer'; +import * as fs from 'fs'; +import * as tmp from 'tmp'; +import * as stream from 'stream'; + import * as mongodb from 'mongodb'; import * as crypto from 'crypto'; import * as gm from 'gm'; import * as debug from 'debug'; import fileType = require('file-type'); import prominence = require('prominence'); + import DriveFile, { getGridFSBucket } from '../models/drive-file'; import DriveFolder from '../models/drive-folder'; import serialize from '../serializers/drive-file'; import event from '../event'; import config from '../../conf'; -import { Buffer } from 'buffer'; -import * as fs from 'fs'; -import * as tmp from 'tmp'; -import * as stream from 'stream'; const log = debug('misskey:register-drive-file'); @@ -67,10 +69,12 @@ const addFile = async ( .once('data', (buffer: Buffer) => { readable.destroy(); const type = fileType(buffer); - if (!type) { + if (type) { + return res([type.mime, type.ext]); + } else { + // 種類が同定できなかったら application/octet-stream にする return res(['application/octet-stream', null]); } - return res([type.mime, type.ext]); }); }))(), // size @@ -105,9 +109,18 @@ const addFile = async ( const [properties, folder] = await Promise.all([ // properties (async () => { + // 画像かどうか if (!/^image\/.*$/.test(mime)) { return null; } + + const imageType = mime.split('/')[1]; + + // 画像でもPNGかJPEGでないならスキップ + if (imageType != 'png' && imageType != 'jpeg') { + return null; + } + // If the file is an image, calculate width and height to save in property const g = gm(fs.createReadStream(path), name); const size = await prominence(g).size(); @@ -115,7 +128,9 @@ const addFile = async ( width: size.width, height: size.height }; + log('image width and height is calculated'); + return properties; })(), // folder @@ -136,20 +151,18 @@ const addFile = async ( (async () => { // Calculate drive usage const usage = await DriveFile - .aggregate([ - { $match: { 'metadata.user_id': user._id } }, - { - $project: { - length: true - } - }, - { - $group: { - _id: null, - usage: { $sum: '$length' } - } + .aggregate([{ + $match: { 'metadata.user_id': user._id } + }, { + $project: { + length: true } - ]) + }, { + $group: { + _id: null, + usage: { $sum: '$length' } + } + }]) .then((aggregates: any[]) => { if (aggregates.length > 0) { return aggregates[0].usage; @@ -211,41 +224,40 @@ export default (user: any, file: string | stream.Readable, ...args) => new Promi } rej(new Error('un-compatible file.')); }) - .then(([path, remove]): Promise => new Promise((res, rej) => { - addFile(user, path, ...args) - .then(file => { - res(file); - if (remove) { - fs.unlink(path, (e) => { - if (e) log(e.stack); - }); - } - }) - .catch(rej); - })) - .then(file => { - log(`drive file has been created ${file._id}`); - resolve(file); + .then(([path, remove]): Promise => new Promise((res, rej) => { + addFile(user, path, ...args) + .then(file => { + res(file); + if (remove) { + fs.unlink(path, (e) => { + if (e) log(e.stack); + }); + } + }) + .catch(rej); + })) + .then(file => { + log(`drive file has been created ${file._id}`); + resolve(file); - serialize(file) - .then(serializedFile => { - // Publish drive_file_created event - event(user._id, 'drive_file_created', serializedFile); + serialize(file).then(serializedFile => { + // Publish drive_file_created event + event(user._id, 'drive_file_created', serializedFile); - // Register to search database - if (config.elasticsearch.enable) { - const es = require('../../db/elasticsearch'); - es.index({ - index: 'misskey', - type: 'drive_file', - id: file._id.toString(), - body: { - name: file.name, - user_id: user._id.toString() - } - }); + // Register to search database + if (config.elasticsearch.enable) { + const es = require('../../db/elasticsearch'); + es.index({ + index: 'misskey', + type: 'drive_file', + id: file._id.toString(), + body: { + name: file.name, + user_id: user._id.toString() } }); - }) - .catch(reject); + } + }); + }) + .catch(reject); }); From 59a687b7c0c948f06e46b128ff1d12d222d25978 Mon Sep 17 00:00:00 2001 From: syuilo Date: Thu, 16 Nov 2017 22:51:28 +0900 Subject: [PATCH 250/327] Fix bug --- src/web/app/mobile/tags/drive/file-viewer.tag | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/web/app/mobile/tags/drive/file-viewer.tag b/src/web/app/mobile/tags/drive/file-viewer.tag index 8dc49a086..2cec4f329 100644 --- a/src/web/app/mobile/tags/drive/file-viewer.tag +++ b/src/web/app/mobile/tags/drive/file-viewer.tag @@ -2,7 +2,7 @@
{ -
+
{ file.properties.width } × From fe5b7ef2d2495f276d8dacb8dd7771fe61608a28 Mon Sep 17 00:00:00 2001 From: syuilo Date: Thu, 16 Nov 2017 22:52:10 +0900 Subject: [PATCH 251/327] v3124 --- CHANGELOG.md | 4 ++++ package.json | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ec522bbfa..5bc0e6d01 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ ChangeLog (Release Notes) ========================= 主に notable な changes を書いていきます +3124 (2017/11/16) +----------------- +* バグ修正 + 3121 (2017/11/16) ----------------- * ブロードキャストウィジェットの強化 diff --git a/package.json b/package.json index 68c558ec2..017c9edfc 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "misskey", "author": "syuilo ", - "version": "0.0.3121", + "version": "0.0.3124", "license": "MIT", "description": "A miniblog-based SNS", "bugs": "https://github.com/syuilo/misskey/issues", From e4f392e2892f5690181a9e377d29a408d65af607 Mon Sep 17 00:00:00 2001 From: syuilo Date: Thu, 16 Nov 2017 23:05:12 +0900 Subject: [PATCH 252/327] Fix thumbnail --- src/file/assets/thumbnail-not-available.png | 3 +++ src/file/server.ts | 11 +++++++++++ 2 files changed, 14 insertions(+) create mode 100644 src/file/assets/thumbnail-not-available.png diff --git a/src/file/assets/thumbnail-not-available.png b/src/file/assets/thumbnail-not-available.png new file mode 100644 index 000000000..c593c0c5f --- /dev/null +++ b/src/file/assets/thumbnail-not-available.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:5583e353d1a248875145b8148c4ff7312589801fc3d97ad22ebdc5ffd0ba5251 +size 8822 diff --git a/src/file/server.ts b/src/file/server.ts index fa03fb777..844b3d736 100644 --- a/src/file/server.ts +++ b/src/file/server.ts @@ -50,11 +50,22 @@ interface ISend { function thumbnail(data: stream.Readable, type: string, resize: number): ISend { const readable: stream.Readable = (() => { + // 画像ではない場合 if (!/^image\/.*$/.test(type)) { // 使わないことにしたストリームはしっかり取り壊しておく data.destroy(); return fs.createReadStream(`${__dirname}/assets/not-an-image.png`); } + + const imageType = type.split('/')[1]; + + // 画像でもPNGかJPEGでないならダメ + if (imageType != 'png' && imageType != 'jpeg') { + // 使わないことにしたストリームはしっかり取り壊しておく + data.destroy(); + return fs.createReadStream(`${__dirname}/assets/thumbnail-not-available.png`); + } + return data; })(); From b4942b54f6163fb33e12961ca7d5f6c4f47e2243 Mon Sep 17 00:00:00 2001 From: syuilo Date: Thu, 16 Nov 2017 23:14:19 +0900 Subject: [PATCH 253/327] Fix indentation --- src/file/server.ts | 64 +++++++++++++++++++++++----------------------- 1 file changed, 32 insertions(+), 32 deletions(-) diff --git a/src/file/server.ts b/src/file/server.ts index 844b3d736..1f8d21b80 100644 --- a/src/file/server.ts +++ b/src/file/server.ts @@ -49,41 +49,41 @@ interface ISend { } function thumbnail(data: stream.Readable, type: string, resize: number): ISend { - const readable: stream.Readable = (() => { - // 画像ではない場合 - if (!/^image\/.*$/.test(type)) { - // 使わないことにしたストリームはしっかり取り壊しておく - data.destroy(); - return fs.createReadStream(`${__dirname}/assets/not-an-image.png`); - } - - const imageType = type.split('/')[1]; - - // 画像でもPNGかJPEGでないならダメ - if (imageType != 'png' && imageType != 'jpeg') { - // 使わないことにしたストリームはしっかり取り壊しておく - data.destroy(); - return fs.createReadStream(`${__dirname}/assets/thumbnail-not-available.png`); - } - - return data; - })(); - - let g = gm(readable); - - if (resize) { - g = g.resize(resize, resize); + const readable: stream.Readable = (() => { + // 画像ではない場合 + if (!/^image\/.*$/.test(type)) { + // 使わないことにしたストリームはしっかり取り壊しておく + data.destroy(); + return fs.createReadStream(`${__dirname}/assets/not-an-image.png`); } - const stream = g - .compress('jpeg') - .quality(80) - .stream(); + const imageType = type.split('/')[1]; - return { - contentType: 'image/jpeg', - stream - }; + // 画像でもPNGかJPEGでないならダメ + if (imageType != 'png' && imageType != 'jpeg') { + // 使わないことにしたストリームはしっかり取り壊しておく + data.destroy(); + return fs.createReadStream(`${__dirname}/assets/thumbnail-not-available.png`); + } + + return data; + })(); + + let g = gm(readable); + + if (resize) { + g = g.resize(resize, resize); + } + + const stream = g + .compress('jpeg') + .quality(80) + .stream(); + + return { + contentType: 'image/jpeg', + stream + }; } const commonReadableHandlerGenerator = (req: express.Request, res: express.Response) => (e: Error): void => { From d06631feb1fd66344c100764de6c62c47bd19724 Mon Sep 17 00:00:00 2001 From: syuilo Date: Thu, 16 Nov 2017 23:46:36 +0900 Subject: [PATCH 254/327] #465 --- src/api/common/add-file-to-drive.ts | 3 ++- src/api/endpoints/drive/files/update.ts | 6 ++--- src/api/endpoints/drive/folders/create.ts | 6 ++--- src/api/endpoints/drive/folders/update.ts | 6 ++--- src/api/event.ts | 6 +++++ src/api/stream/drive.ts | 10 +++++++++ src/api/streaming.ts | 2 ++ src/web/app/common/mixins.ts | 3 ++- .../common/scripts/drive-stream-manager.ts | 20 +++++++++++++++++ src/web/app/common/scripts/drive-stream.ts | 14 ++++++++++++ src/web/app/desktop/tags/drive/browser.tag | 22 +++++++++++-------- src/web/app/mobile/tags/drive.tag | 22 +++++++++++-------- 12 files changed, 91 insertions(+), 29 deletions(-) create mode 100644 src/api/stream/drive.ts create mode 100644 src/web/app/common/scripts/drive-stream-manager.ts create mode 100644 src/web/app/common/scripts/drive-stream.ts diff --git a/src/api/common/add-file-to-drive.ts b/src/api/common/add-file-to-drive.ts index f96f58cb6..2a649788a 100644 --- a/src/api/common/add-file-to-drive.ts +++ b/src/api/common/add-file-to-drive.ts @@ -13,7 +13,7 @@ import prominence = require('prominence'); import DriveFile, { getGridFSBucket } from '../models/drive-file'; import DriveFolder from '../models/drive-folder'; import serialize from '../serializers/drive-file'; -import event from '../event'; +import event, { publishDriveStream } from '../event'; import config from '../../conf'; const log = debug('misskey:register-drive-file'); @@ -243,6 +243,7 @@ export default (user: any, file: string | stream.Readable, ...args) => new Promi serialize(file).then(serializedFile => { // Publish drive_file_created event event(user._id, 'drive_file_created', serializedFile); + publishDriveStream(user._id, 'file_created', serializedFile); // Register to search database if (config.elasticsearch.enable) { diff --git a/src/api/endpoints/drive/files/update.ts b/src/api/endpoints/drive/files/update.ts index f265142c4..f39a420d6 100644 --- a/src/api/endpoints/drive/files/update.ts +++ b/src/api/endpoints/drive/files/update.ts @@ -6,7 +6,7 @@ import DriveFolder from '../../../models/drive-folder'; import DriveFile from '../../../models/drive-file'; import { validateFileName } from '../../../models/drive-file'; import serialize from '../../../serializers/drive-file'; -import event from '../../../event'; +import { publishDriveStream } from '../../../event'; /** * Update a file @@ -72,6 +72,6 @@ module.exports = (params, user) => new Promise(async (res, rej) => { // Response res(fileObj); - // Publish drive_file_updated event - event(user._id, 'drive_file_updated', fileObj); + // Publish file_updated event + publishDriveStream(user._id, 'file_updated', fileObj); }); diff --git a/src/api/endpoints/drive/folders/create.ts b/src/api/endpoints/drive/folders/create.ts index 8c875db16..be847b215 100644 --- a/src/api/endpoints/drive/folders/create.ts +++ b/src/api/endpoints/drive/folders/create.ts @@ -5,7 +5,7 @@ import $ from 'cafy'; import DriveFolder from '../../../models/drive-folder'; import { isValidFolderName } from '../../../models/drive-folder'; import serialize from '../../../serializers/drive-folder'; -import event from '../../../event'; +import { publishDriveStream } from '../../../event'; /** * Create drive folder @@ -52,6 +52,6 @@ module.exports = (params, user) => new Promise(async (res, rej) => { // Response res(folderObj); - // Publish drive_folder_created event - event(user._id, 'drive_folder_created', folderObj); + // Publish folder_created event + publishDriveStream(user._id, 'folder_created', folderObj); }); diff --git a/src/api/endpoints/drive/folders/update.ts b/src/api/endpoints/drive/folders/update.ts index 4f2e3d2a7..ff673402a 100644 --- a/src/api/endpoints/drive/folders/update.ts +++ b/src/api/endpoints/drive/folders/update.ts @@ -5,7 +5,7 @@ import $ from 'cafy'; import DriveFolder from '../../../models/drive-folder'; import { isValidFolderName } from '../../../models/drive-folder'; import serialize from '../../../serializers/drive-folder'; -import event from '../../../event'; +import { publishDriveStream } from '../../../event'; /** * Update a folder @@ -96,6 +96,6 @@ module.exports = (params, user) => new Promise(async (res, rej) => { // Response res(folderObj); - // Publish drive_folder_updated event - event(user._id, 'drive_folder_updated', folderObj); + // Publish folder_updated event + publishDriveStream(user._id, 'folder_updated', folderObj); }); diff --git a/src/api/event.ts b/src/api/event.ts index 927883737..8605a0f1e 100644 --- a/src/api/event.ts +++ b/src/api/event.ts @@ -17,6 +17,10 @@ class MisskeyEvent { this.publish(`user-stream:${userId}`, type, typeof value === 'undefined' ? null : value); } + public publishDriveStream(userId: ID, type: string, value?: any): void { + this.publish(`drive-stream:${userId}`, type, typeof value === 'undefined' ? null : value); + } + public publishPostStream(postId: ID, type: string, value?: any): void { this.publish(`post-stream:${postId}`, type, typeof value === 'undefined' ? null : value); } @@ -46,6 +50,8 @@ const ev = new MisskeyEvent(); export default ev.publishUserStream.bind(ev); +export const publishDriveStream = ev.publishDriveStream.bind(ev); + export const publishPostStream = ev.publishPostStream.bind(ev); export const publishMessagingStream = ev.publishMessagingStream.bind(ev); diff --git a/src/api/stream/drive.ts b/src/api/stream/drive.ts new file mode 100644 index 000000000..c97ab80dc --- /dev/null +++ b/src/api/stream/drive.ts @@ -0,0 +1,10 @@ +import * as websocket from 'websocket'; +import * as redis from 'redis'; + +export default function(request: websocket.request, connection: websocket.connection, subscriber: redis.RedisClient, user: any): void { + // Subscribe drive stream + subscriber.subscribe(`misskey:drive-stream:${user._id}`); + subscriber.on('message', (_, data) => { + connection.send(data); + }); +} diff --git a/src/api/streaming.ts b/src/api/streaming.ts index 1f0ba848c..c06d64c24 100644 --- a/src/api/streaming.ts +++ b/src/api/streaming.ts @@ -7,6 +7,7 @@ import AccessToken from './models/access-token'; import isNativeToken from './common/is-native-token'; import homeStream from './stream/home'; +import driveStream from './stream/drive'; import messagingStream from './stream/messaging'; import messagingIndexStream from './stream/messaging-index'; import serverStream from './stream/server'; @@ -58,6 +59,7 @@ module.exports = (server: http.Server) => { const channel = request.resourceURL.pathname === '/' ? homeStream : + request.resourceURL.pathname === '/drive' ? driveStream : request.resourceURL.pathname === '/messaging' ? messagingStream : request.resourceURL.pathname === '/messaging-index' ? messagingIndexStream : null; diff --git a/src/web/app/common/mixins.ts b/src/web/app/common/mixins.ts index b5eb1acc7..594906962 100644 --- a/src/web/app/common/mixins.ts +++ b/src/web/app/common/mixins.ts @@ -4,6 +4,7 @@ import MiOS from './mios'; import ServerStreamManager from './scripts/server-stream-manager'; import RequestsStreamManager from './scripts/requests-stream-manager'; import MessagingIndexStream from './scripts/messaging-index-stream-manager'; +import DriveStreamManager from './scripts/drive-stream-manager'; export default (mios: MiOS) => { (riot as any).mixin('os', { @@ -30,7 +31,7 @@ export default (mios: MiOS) => { (riot as any).mixin('api', { api: mios.api }); - + (riot as any).mixin('drive-stream', { driveStream: new DriveStreamManager(mios.i) }); (riot as any).mixin('stream', { stream: mios.stream }); (riot as any).mixin('server-stream', { serverStream: new ServerStreamManager() }); diff --git a/src/web/app/common/scripts/drive-stream-manager.ts b/src/web/app/common/scripts/drive-stream-manager.ts new file mode 100644 index 000000000..8acdd7cbb --- /dev/null +++ b/src/web/app/common/scripts/drive-stream-manager.ts @@ -0,0 +1,20 @@ +import StreamManager from './stream-manager'; +import Connection from './drive-stream'; + +export default class DriveStreamManager extends StreamManager { + private me; + + constructor(me) { + super(); + + this.me = me; + } + + public getConnection() { + if (this.connection == null) { + this.connection = new Connection(this.me); + } + + return this.connection; + } +} diff --git a/src/web/app/common/scripts/drive-stream.ts b/src/web/app/common/scripts/drive-stream.ts new file mode 100644 index 000000000..1b3343557 --- /dev/null +++ b/src/web/app/common/scripts/drive-stream.ts @@ -0,0 +1,14 @@ +import Stream from './stream'; + +/** + * Drive stream connection + */ +class Connection extends Stream { + constructor(me) { + super('drive', { + i: me.token + }); + } +} + +export default Connection; diff --git a/src/web/app/desktop/tags/drive/browser.tag b/src/web/app/desktop/tags/drive/browser.tag index 18e27f24b..311209fcb 100644 --- a/src/web/app/desktop/tags/drive/browser.tag +++ b/src/web/app/desktop/tags/drive/browser.tag @@ -247,7 +247,10 @@ this.mixin('i'); this.mixin('api'); - this.mixin('stream'); + + this.mixin('drive-stream'); + this.connection = this.driveStream.getConnection(); + this.connectionId = this.driveStream.use(); this.files = []; this.folders = []; @@ -280,10 +283,10 @@ }); }); - this.stream.on('drive_file_created', this.onStreamDriveFileCreated); - this.stream.on('drive_file_updated', this.onStreamDriveFileUpdated); - this.stream.on('drive_folder_created', this.onStreamDriveFolderCreated); - this.stream.on('drive_folder_updated', this.onStreamDriveFolderUpdated); + this.connection.on('file_created', this.onStreamDriveFileCreated); + this.connection.on('file_updated', this.onStreamDriveFileUpdated); + this.connection.on('folder_created', this.onStreamDriveFolderCreated); + this.connection.on('folder_updated', this.onStreamDriveFolderUpdated); if (this.opts.folder) { this.move(this.opts.folder); @@ -293,10 +296,11 @@ }); this.on('unmount', () => { - this.stream.off('drive_file_created', this.onStreamDriveFileCreated); - this.stream.off('drive_file_updated', this.onStreamDriveFileUpdated); - this.stream.off('drive_folder_created', this.onStreamDriveFolderCreated); - this.stream.off('drive_folder_updated', this.onStreamDriveFolderUpdated); + this.connection.off('file_created', this.onStreamDriveFileCreated); + this.connection.off('file_updated', this.onStreamDriveFileUpdated); + this.connection.off('folder_created', this.onStreamDriveFolderCreated); + this.connection.off('folder_updated', this.onStreamDriveFolderUpdated); + this.driveStream.dispose(this.connectionId); }); this.onStreamDriveFileCreated = file => { diff --git a/src/web/app/mobile/tags/drive.tag b/src/web/app/mobile/tags/drive.tag index 870a451ac..2c36c43ac 100644 --- a/src/web/app/mobile/tags/drive.tag +++ b/src/web/app/mobile/tags/drive.tag @@ -172,7 +172,10 @@ diff --git a/src/web/app/desktop/script.ts b/src/web/app/desktop/script.ts index b4a8d829d..bc0fc8dfe 100644 --- a/src/web/app/desktop/script.ts +++ b/src/web/app/desktop/script.ts @@ -13,6 +13,7 @@ import route from './router'; import fuckAdBlock from './scripts/fuck-ad-block'; import getPostSummary from '../../../common/get-post-summary'; import MiOS from '../common/mios'; +import HomeStreamManager from '../common/scripts/streaming/home-stream-manager'; /** * init @@ -41,52 +42,62 @@ init(async (mios: MiOS) => { route(mios); }); -function registerNotifications(stream) { +function registerNotifications(stream: HomeStreamManager) { if (stream == null) return; - stream.on('drive_file_created', file => { - const n = new Notification('ファイルがアップロードされました', { - body: file.name, - icon: file.url + '?thumbnail&size=64' - }); - setTimeout(n.close.bind(n), 5000); + if (stream.hasConnection) { + attach(stream.borrow()); + } + + stream.on('connected', connection => { + attach(connection); }); - stream.on('mention', post => { - const n = new Notification(`${post.user.name}さんから:`, { - body: getPostSummary(post), - icon: post.user.avatar_url + '?thumbnail&size=64' - }); - setTimeout(n.close.bind(n), 6000); - }); - - stream.on('reply', post => { - const n = new Notification(`${post.user.name}さんから返信:`, { - body: getPostSummary(post), - icon: post.user.avatar_url + '?thumbnail&size=64' - }); - setTimeout(n.close.bind(n), 6000); - }); - - stream.on('quote', post => { - const n = new Notification(`${post.user.name}さんが引用:`, { - body: getPostSummary(post), - icon: post.user.avatar_url + '?thumbnail&size=64' - }); - setTimeout(n.close.bind(n), 6000); - }); - - stream.on('unread_messaging_message', message => { - const n = new Notification(`${message.user.name}さんからメッセージ:`, { - body: message.text, // TODO: getMessagingMessageSummary(message), - icon: message.user.avatar_url + '?thumbnail&size=64' - }); - n.onclick = () => { - n.close(); - (riot as any).mount(document.body.appendChild(document.createElement('mk-messaging-room-window')), { - user: message.user + function attach(connection) { + connection.on('drive_file_created', file => { + const n = new Notification('ファイルがアップロードされました', { + body: file.name, + icon: file.url + '?thumbnail&size=64' }); - }; - setTimeout(n.close.bind(n), 7000); - }); + setTimeout(n.close.bind(n), 5000); + }); + + connection.on('mention', post => { + const n = new Notification(`${post.user.name}さんから:`, { + body: getPostSummary(post), + icon: post.user.avatar_url + '?thumbnail&size=64' + }); + setTimeout(n.close.bind(n), 6000); + }); + + connection.on('reply', post => { + const n = new Notification(`${post.user.name}さんから返信:`, { + body: getPostSummary(post), + icon: post.user.avatar_url + '?thumbnail&size=64' + }); + setTimeout(n.close.bind(n), 6000); + }); + + connection.on('quote', post => { + const n = new Notification(`${post.user.name}さんが引用:`, { + body: getPostSummary(post), + icon: post.user.avatar_url + '?thumbnail&size=64' + }); + setTimeout(n.close.bind(n), 6000); + }); + + connection.on('unread_messaging_message', message => { + const n = new Notification(`${message.user.name}さんからメッセージ:`, { + body: message.text, // TODO: getMessagingMessageSummary(message), + icon: message.user.avatar_url + '?thumbnail&size=64' + }); + n.onclick = () => { + n.close(); + (riot as any).mount(document.body.appendChild(document.createElement('mk-messaging-room-window')), { + user: message.user + }); + }; + setTimeout(n.close.bind(n), 7000); + }); + } } diff --git a/src/web/app/desktop/tags/big-follow-button.tag b/src/web/app/desktop/tags/big-follow-button.tag index 86df2d492..8897748ae 100644 --- a/src/web/app/desktop/tags/big-follow-button.tag +++ b/src/web/app/desktop/tags/big-follow-button.tag @@ -74,7 +74,10 @@ this.mixin('i'); this.mixin('api'); + this.mixin('stream'); + this.connection = this.stream.getConnection(); + this.connectionId = this.stream.use(); this.user = null; this.userPromise = isPromise(this.opts.user) @@ -89,14 +92,15 @@ init: false, user: user }); - this.stream.on('follow', this.onStreamFollow); - this.stream.on('unfollow', this.onStreamUnfollow); + this.connection.on('follow', this.onStreamFollow); + this.connection.on('unfollow', this.onStreamUnfollow); }); }); this.on('unmount', () => { - this.stream.off('follow', this.onStreamFollow); - this.stream.off('unfollow', this.onStreamUnfollow); + this.connection.off('follow', this.onStreamFollow); + this.connection.off('unfollow', this.onStreamUnfollow); + this.stream.dispose(this.connectionId); }); this.onStreamFollow = user => { diff --git a/src/web/app/desktop/tags/follow-button.tag b/src/web/app/desktop/tags/follow-button.tag index 00ff686f6..a1cbc191d 100644 --- a/src/web/app/desktop/tags/follow-button.tag +++ b/src/web/app/desktop/tags/follow-button.tag @@ -71,7 +71,10 @@ this.mixin('i'); this.mixin('api'); + this.mixin('stream'); + this.connection = this.stream.getConnection(); + this.connectionId = this.stream.use(); this.user = null; this.userPromise = isPromise(this.opts.user) @@ -86,14 +89,15 @@ init: false, user: user }); - this.stream.on('follow', this.onStreamFollow); - this.stream.on('unfollow', this.onStreamUnfollow); + this.connection.on('follow', this.onStreamFollow); + this.connection.on('unfollow', this.onStreamUnfollow); }); }); this.on('unmount', () => { - this.stream.off('follow', this.onStreamFollow); - this.stream.off('unfollow', this.onStreamUnfollow); + this.connection.off('follow', this.onStreamFollow); + this.connection.off('unfollow', this.onStreamUnfollow); + this.stream.dispose(this.connectionId); }); this.onStreamFollow = user => { diff --git a/src/web/app/desktop/tags/home-widgets/channel.tag b/src/web/app/desktop/tags/home-widgets/channel.tag index 28c66df5c..fc4a27e4f 100644 --- a/src/web/app/desktop/tags/home-widgets/channel.tag +++ b/src/web/app/desktop/tags/home-widgets/channel.tag @@ -138,7 +138,7 @@ + + + + + + + + + +

直近1年間分の統計です。一番右が現在で、一番左が1年前です。青は通常の投稿、赤は返信、緑はRepostをそれぞれ表しています。

+

+ だいたい*1日に{ averageOfAllTypePostsEachDays }回投稿(返信、Repost含む)しています。
+ だいたい*1日に{ averageOfPostsEachDays }回投稿(通常の)しています。
+ だいたい*1日に{ averageOfRepliesEachDays }回返信しています。
+ だいたい*1日に{ averageOfRepostsEachDays }回Repostしています。
+

+

* 中央値

+ + + +
From db5c347d0be04f32a5d3cd7ece33e45eff8343b2 Mon Sep 17 00:00:00 2001 From: syuilo Date: Mon, 20 Nov 2017 02:38:00 +0900 Subject: [PATCH 278/327] v3155 --- CHANGELOG.md | 4 ++++ package.json | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c8a0171ac..dc1c66ce9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ ChangeLog (Release Notes) ========================= 主に notable な changes を書いていきます +3155 (2017/11/20) +----------------- +* デスクトップ版でユーザーの投稿グラフを見れるように + 3142 (2017/11/18) ----------------- * バグ修正 diff --git a/package.json b/package.json index 50754f334..410635f03 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "misskey", "author": "syuilo ", - "version": "0.0.3142", + "version": "0.0.3155", "license": "MIT", "description": "A miniblog-based SNS", "bugs": "https://github.com/syuilo/misskey/issues", From 30e22418ad828afc0a2068aaf01eff1daab25504 Mon Sep 17 00:00:00 2001 From: syuilo Date: Mon, 20 Nov 2017 04:30:24 +0900 Subject: [PATCH 279/327] Check Edge --- src/web/app/safe.js | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/web/app/safe.js b/src/web/app/safe.js index 327a034d1..b37b89024 100644 --- a/src/web/app/safe.js +++ b/src/web/app/safe.js @@ -1,6 +1,5 @@ /** - * 古いブラウザの検知を行う - * ブートローダーとは隔離されているため互いに影響を及ぼすことはない + * ブラウザの検証 */ // Detect an old browser @@ -12,3 +11,13 @@ if (!('fetch' in window)) { 'Your browser seems outdated. ' + 'To run Misskey, please update your browser to latest version or try other browsers.'); } + +// Detect Edge +if (navigator.userAgent.indexOf('Edge')) { + alert( + '現在、お使いのブラウザ(Microsoft Edge)ではMisskeyは正しく動作しません。' + + 'サポートしているブラウザ: Google Chrome, Mozilla Firefox, Apple Safari など' + + '\n\n' + + 'Currently, Misskey cannot run correctly on your browser (Microsoft Edge).' + + 'Supported browsers: Google Chrome, Mozilla Firefox, Apple Safari, etc'); +} From 27f3ffefd0bb753fff67ded13d6fd9fdd73b7f70 Mon Sep 17 00:00:00 2001 From: syuilo Date: Mon, 20 Nov 2017 04:32:49 +0900 Subject: [PATCH 280/327] Insert missing whitespace --- src/web/app/safe.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/web/app/safe.js b/src/web/app/safe.js index b37b89024..a29ba4d87 100644 --- a/src/web/app/safe.js +++ b/src/web/app/safe.js @@ -18,6 +18,6 @@ if (navigator.userAgent.indexOf('Edge')) { '現在、お使いのブラウザ(Microsoft Edge)ではMisskeyは正しく動作しません。' + 'サポートしているブラウザ: Google Chrome, Mozilla Firefox, Apple Safari など' + '\n\n' + - 'Currently, Misskey cannot run correctly on your browser (Microsoft Edge).' + + 'Currently, Misskey cannot run correctly on your browser (Microsoft Edge). ' + 'Supported browsers: Google Chrome, Mozilla Firefox, Apple Safari, etc'); } From 09902eb7ef0ac053a92a1332c273757049590210 Mon Sep 17 00:00:00 2001 From: syuilo Date: Mon, 20 Nov 2017 04:42:42 +0900 Subject: [PATCH 281/327] :v: --- src/web/app/safe.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/web/app/safe.js b/src/web/app/safe.js index a29ba4d87..6a0f22fe6 100644 --- a/src/web/app/safe.js +++ b/src/web/app/safe.js @@ -13,7 +13,7 @@ if (!('fetch' in window)) { } // Detect Edge -if (navigator.userAgent.indexOf('Edge')) { +if (navigator.userAgent.indexOf('Edge') != -1) { alert( '現在、お使いのブラウザ(Microsoft Edge)ではMisskeyは正しく動作しません。' + 'サポートしているブラウザ: Google Chrome, Mozilla Firefox, Apple Safari など' + From c639a18ec86c55cb73cedac9faa97d307639155d Mon Sep 17 00:00:00 2001 From: syuilo Date: Mon, 20 Nov 2017 05:47:09 +0900 Subject: [PATCH 282/327] Check Cookie --- src/web/app/safe.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/web/app/safe.js b/src/web/app/safe.js index 6a0f22fe6..e8482b057 100644 --- a/src/web/app/safe.js +++ b/src/web/app/safe.js @@ -21,3 +21,11 @@ if (navigator.userAgent.indexOf('Edge') != -1) { 'Currently, Misskey cannot run correctly on your browser (Microsoft Edge). ' + 'Supported browsers: Google Chrome, Mozilla Firefox, Apple Safari, etc'); } + +// Check whether cookie enabled +if (!navigator.cookieEnabled) { + alert( + 'Misskeyを利用するにはCookieを有効にしてください。' + + '\n\n' + + 'To use Misskey, please enable Cookie.'); +} From 397e38e4ef96d2e326ed489282837814b2e0dde5 Mon Sep 17 00:00:00 2001 From: syuilo Date: Mon, 20 Nov 2017 05:47:34 +0900 Subject: [PATCH 283/327] Better detection --- src/web/app/safe.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/web/app/safe.js b/src/web/app/safe.js index e8482b057..2fd536172 100644 --- a/src/web/app/safe.js +++ b/src/web/app/safe.js @@ -13,7 +13,7 @@ if (!('fetch' in window)) { } // Detect Edge -if (navigator.userAgent.indexOf('Edge') != -1) { +if (navigator.userAgent.toLowerCase().indexOf('edge') != -1) { alert( '現在、お使いのブラウザ(Microsoft Edge)ではMisskeyは正しく動作しません。' + 'サポートしているブラウザ: Google Chrome, Mozilla Firefox, Apple Safari など' + From e4f52d9a41de061a609679696a5066cbf139b949 Mon Sep 17 00:00:00 2001 From: syuilo Date: Mon, 20 Nov 2017 08:47:03 +0900 Subject: [PATCH 284/327] :art: --- src/web/app/desktop/tags/drive/browser.tag | 26 +++++++++++----------- src/web/app/desktop/tags/drive/file.tag | 4 +--- src/web/app/desktop/tags/drive/folder.tag | 2 -- 3 files changed, 14 insertions(+), 18 deletions(-) diff --git a/src/web/app/desktop/tags/drive/browser.tag b/src/web/app/desktop/tags/drive/browser.tag index 311209fcb..6b756b995 100644 --- a/src/web/app/desktop/tags/drive/browser.tag +++ b/src/web/app/desktop/tags/drive/browser.tag @@ -18,12 +18,14 @@ +
0 }> +
@@ -161,22 +163,20 @@ > .contents > .folders - &:after - content "" - display block - clear both + > .files + display flex + flex-wrap wrap > .folder - float left - - > .files - &:after - content "" - display block - clear both - > .file - float left + flex-grow 1 + width 144px + margin 4px + + > .padding + flex-grow 1 + pointer-events none + width 144px + 8px // 8px is margin > .empty padding 16px diff --git a/src/web/app/desktop/tags/drive/file.tag b/src/web/app/desktop/tags/drive/file.tag index bf9d38bd2..0f019d95b 100644 --- a/src/web/app/desktop/tags/drive/file.tag +++ b/src/web/app/desktop/tags/drive/file.tag @@ -10,9 +10,7 @@ diff --git a/src/web/app/desktop/tags/messaging/room-window.tag b/src/web/app/desktop/tags/messaging/room-window.tag index dca0172be..1c6ff7c4b 100644 --- a/src/web/app/desktop/tags/messaging/room-window.tag +++ b/src/web/app/desktop/tags/messaging/room-window.tag @@ -19,11 +19,9 @@ diff --git a/src/web/app/mobile/tags/timeline.tag b/src/web/app/mobile/tags/timeline.tag index 1d6ce2359..074422a20 100644 --- a/src/web/app/mobile/tags/timeline.tag +++ b/src/web/app/mobile/tags/timeline.tag @@ -164,7 +164,7 @@
-

{ p.channel.title }:

+

{ p.channel.title }:

diff --git a/src/web/app/mobile/tags/ui.tag b/src/web/app/mobile/tags/ui.tag index 0c969d390..bad6bf73f 100644 --- a/src/web/app/mobile/tags/ui.tag +++ b/src/web/app/mobile/tags/ui.tag @@ -239,7 +239,7 @@
  • %i18n:mobile.tags.mk-ui-nav.messaging%
  • -

    %i18n:mobile.tags.mk-ui-nav.about%

    +

    %i18n:mobile.tags.mk-ui-nav.about%