From 190a5e175bb12a86773940d44748ed0b159b8c31 Mon Sep 17 00:00:00 2001 From: syuilo Date: Mon, 15 Apr 2019 16:37:54 +0900 Subject: [PATCH 1/7] Fix bug --- src/server/api/endpoints/sw/register.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/server/api/endpoints/sw/register.ts b/src/server/api/endpoints/sw/register.ts index 79bc18bf21..559937ca2f 100644 --- a/src/server/api/endpoints/sw/register.ts +++ b/src/server/api/endpoints/sw/register.ts @@ -27,7 +27,6 @@ export const meta = { export default define(meta, async (ps, user) => { // if already subscribed const exist = await SwSubscriptions.findOne({ - createdAt: new Date(), userId: user.id, endpoint: ps.endpoint, auth: ps.auth, @@ -45,6 +44,7 @@ export default define(meta, async (ps, user) => { await SwSubscriptions.save({ id: genId(), + createdAt: new Date(), userId: user.id, endpoint: ps.endpoint, auth: ps.auth, From d2d991ff34fad61f4dc266bc44839532c77c4e2c Mon Sep 17 00:00:00 2001 From: syuilo Date: Mon, 15 Apr 2019 18:08:57 +0900 Subject: [PATCH 2/7] Fix error --- src/server/api/endpoints/blocking/create.ts | 4 ++-- src/server/api/endpoints/blocking/delete.ts | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/server/api/endpoints/blocking/create.ts b/src/server/api/endpoints/blocking/create.ts index 0d6626b2d5..045be6aef3 100644 --- a/src/server/api/endpoints/blocking/create.ts +++ b/src/server/api/endpoints/blocking/create.ts @@ -5,7 +5,7 @@ import create from '../../../../services/blocking/create'; import define from '../../define'; import { ApiError } from '../../error'; import { getUser } from '../../common/getters'; -import { Blockings, NoteWatchings } from '../../../../models'; +import { Blockings, NoteWatchings, Users } from '../../../../models'; export const meta = { stability: 'stable', @@ -89,5 +89,5 @@ export default define(meta, async (ps, user) => { noteUserId: blockee.id }); - return await Blockings.pack(blockee.id, user); + return await Users.pack(blockee.id, user); }); diff --git a/src/server/api/endpoints/blocking/delete.ts b/src/server/api/endpoints/blocking/delete.ts index e304dca811..ecb5d1109e 100644 --- a/src/server/api/endpoints/blocking/delete.ts +++ b/src/server/api/endpoints/blocking/delete.ts @@ -5,7 +5,7 @@ import deleteBlocking from '../../../../services/blocking/delete'; import define from '../../define'; import { ApiError } from '../../error'; import { getUser } from '../../common/getters'; -import { Blockings } from '../../../../models'; +import { Blockings, Users } from '../../../../models'; export const meta = { stability: 'stable', @@ -84,5 +84,5 @@ export default define(meta, async (ps, user) => { // Delete blocking await deleteBlocking(blocker, blockee); - return await Blockings.pack(blockee.id, user); + return await Users.pack(blockee.id, user); }); From f90b6dbed47f8246c5cf37d5d3a87dbab1234c2a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Acid=20Chicken=20=28=E7=A1=AB=E9=85=B8=E9=B6=8F=29?= Date: Mon, 15 Apr 2019 19:05:35 +0900 Subject: [PATCH 3/7] Follow lint --- src/services/drive/add-file.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/services/drive/add-file.ts b/src/services/drive/add-file.ts index 54d7f2d13a..c79dfee103 100644 --- a/src/services/drive/add-file.ts +++ b/src/services/drive/add-file.ts @@ -209,7 +209,7 @@ async function deleteOldFile(user: IRemoteUser) { } if (user.bannerId) { - q.andWhere('file.id != :bannerId', { bannerId: user.bannerId }) + q.andWhere('file.id != :bannerId', { bannerId: user.bannerId }); } q.orderBy('file.id', 'DESC'); From 18bc4a49e8f9e660672452e0833937d41873531e Mon Sep 17 00:00:00 2001 From: syuilo Date: Mon, 15 Apr 2019 20:37:21 +0900 Subject: [PATCH 4/7] =?UTF-8?q?=E3=83=A9=E3=83=B3=E3=83=80=E3=83=A0?= =?UTF-8?q?=E3=81=AB=E3=82=A2=E3=83=90=E3=82=BF=E3=83=BC=E3=82=92=E7=94=9F?= =?UTF-8?q?=E6=88=90=E3=81=99=E3=82=8B=E3=82=88=E3=81=86=E3=81=AB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 3 + src/misc/gen-avatar.ts | 89 ++++++++++++++++++++++++++++++ src/models/repositories/user.ts | 3 +- src/server/file/assets/avatar.jpg | Bin 1261 -> 0 bytes src/server/file/index.ts | 6 -- src/server/index.ts | 7 +++ 6 files changed, 101 insertions(+), 7 deletions(-) create mode 100644 src/misc/gen-avatar.ts delete mode 100644 src/server/file/assets/avatar.jpg diff --git a/package.json b/package.json index 5526fdab77..315c9ffcc9 100644 --- a/package.json +++ b/package.json @@ -75,6 +75,7 @@ "@types/portscanner": "2.1.0", "@types/pug": "2.0.4", "@types/qrcode": "1.3.2", + "@types/random-seed": "0.3.3", "@types/ratelimiter": "2.1.28", "@types/redis": "2.8.12", "@types/rename": "1.0.1", @@ -103,6 +104,7 @@ "bootstrap-vue": "2.0.0-rc.13", "bull": "3.7.0", "cafy": "15.1.1", + "canvas": "2.4.1", "chai": "4.2.0", "chalk": "2.4.2", "cli-highlight": "2.1.0", @@ -188,6 +190,7 @@ "pug": "2.0.3", "punycode": "2.1.1", "qrcode": "1.3.3", + "random-seed": "0.3.0", "randomcolor": "0.5.4", "ratelimiter": "3.3.0", "recaptcha-promise": "0.1.3", diff --git a/src/misc/gen-avatar.ts b/src/misc/gen-avatar.ts new file mode 100644 index 0000000000..7d22ee98e2 --- /dev/null +++ b/src/misc/gen-avatar.ts @@ -0,0 +1,89 @@ +/** + * Random avatar generator + */ + +import { createCanvas } from 'canvas'; +import * as gen from 'random-seed'; + +const size = 512; // px +const n = 5; // resolution +const margin = (size / n) / 1.5; +const colors = [ + '#e57373', + '#F06292', + '#BA68C8', + '#9575CD', + '#7986CB', + '#64B5F6', + '#4FC3F7', + '#4DD0E1', + '#4DB6AC', + '#81C784', + '#8BC34A', + '#AFB42B', + '#F57F17', + '#FF5722', + '#795548', + '#455A64', +]; +const bg = '#e9e9e9'; + +const actualSize = size - (margin * 2); +const cellSize = actualSize / n; +const sideN = Math.floor(n / 2); + +/** + * Generate buffer of random avatar by seed + */ +export function genAvatar(seed: string) { + const rand = gen.create(seed); + const canvas = createCanvas(size, size); + const ctx = canvas.getContext('2d'); + + ctx.fillStyle = bg; + ctx.beginPath(); + ctx.fillRect(0, 0, size, size); + + ctx.fillStyle = colors[rand(colors.length)]; + + // side bitmap (filled by false) + const side: boolean[][] = new Array(sideN); + for (let i = 0; i < side.length; i++) { + side[i] = new Array(n).fill(false); + } + + // 1*n (filled by false) + const center: boolean[] = new Array(n).fill(false); + + // tslint:disable-next-line:prefer-for-of + for (let x = 0; x < side.length; x++) { + for (let y = 0; y < side[x].length; y++) { + side[x][y] = rand(3) === 0; + } + } + + for (let i = 0; i < center.length; i++) { + center[i] = rand(3) === 0; + } + + // Draw + for (let x = 0; x < n; x++) { + for (let y = 0; y < n; y++) { + const isXCenter = x === ((n - 1) / 2); + if (isXCenter && !center[y]) continue; + + const isLeftSide = x < ((n - 1) / 2); + if (isLeftSide && !side[x][y]) continue; + + const isRightSide = x > ((n - 1) / 2); + if (isRightSide && !side[sideN - (x - sideN)][y]) continue; + + const actualX = margin + (cellSize * x); + const actualY = margin + (cellSize * y); + ctx.beginPath(); + ctx.fillRect(actualX, actualY, cellSize, cellSize); + } + } + + return canvas.toBuffer(); +} diff --git a/src/models/repositories/user.ts b/src/models/repositories/user.ts index 83cca2f883..9e4247545a 100644 --- a/src/models/repositories/user.ts +++ b/src/models/repositories/user.ts @@ -3,6 +3,7 @@ import { User, ILocalUser, IRemoteUser } from '../entities/user'; import { Emojis, Notes, NoteUnreads, FollowRequests, Notifications, MessagingMessages, UserNotePinings, Followings, Blockings, Mutings, UserProfiles } from '..'; import rap from '@prezzemolo/rap'; import { ensure } from '../../prelude/ensure'; +import config from '../../config'; @EntityRepository(User) export class UserRepository extends Repository { @@ -88,7 +89,7 @@ export class UserRepository extends Repository { name: user.name, username: user.username, host: user.host, - avatarUrl: user.avatarUrl, + avatarUrl: user.avatarUrl ? user.avatarUrl : config.url + '/avatar/' + user.id, avatarColor: user.avatarColor, isAdmin: user.isAdmin || undefined, isBot: user.isBot || undefined, diff --git a/src/server/file/assets/avatar.jpg b/src/server/file/assets/avatar.jpg deleted file mode 100644 index be0c3ca82956fbac1b00b9ebb9e10a87d6ff8d53..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1261 zcmex=7#K0uT$SlbC{|JLL(5Vc}Am_pXJ2ML#D-#D$(n5fNiHVVkiJgU$ znH3_>$i&RTD#)hDE+lN|7?@btIB}tfsFG38#)A((C>w8bN^Y8T5vWrH*+7U+kfb*f$F$3CNF2QX;X2dB5Yb<| z-{xf39TK`F_-*Ui{ptFd*Af#F6OXz}3v~tk5na(J!n)mR||DjV?_8U)o zWXF2=MDuR1=@-|%f3xKFy7*Op_A<V6|R+PQGpC z@-=5V^q0kLuU=Q``rWna=N}tB<;D%k^N;+vayCCk^_Krt_j&ieZ~8v<0!X9fKg$c* z*Gyjetx%om6TK?VD8BKRJ-_;U)k%Ivg_8<1-&}t0dS+_L^hOyy&8>&5oz=9SOrL$% z``PU8jSpZJzxt)%`O)_F(p^WU-T&U`sVXazdR(}BHGqj8&G5US3TE=lsx2T)a_>! z`|{`1bAnf2T`TGOWOaI5Q{X=BzsCO=j^Ep#VOf;JWZHd?B#n)NA@ zF_~@N#EE%vBKo_9?nIt`ADVYJ^>>YJ+XDvPT5qL_9mV@3u08S6o*KI3se~ zF1!d%=*(3h>aFOHG(wUZKDY1H6r=2}j^f~w4dH3$pSm%%{OLbm&O^tgc z@z!K@-0{cH&TBy3%kFwW#_DU&@rjdW9bV+U{@;`RTz~5e>@1vHH+@~H{U)!+-BhRb+>(xOw=BE%Y5Lax41zmD3s!B7EevcC3hatjncidsGMI7U znwM5}tKCy)_i~%Xr^R0G-xT{|?#Fhnrx|ab1l|2n{hy&Ye{1}b>92o^8q01ybn9-J ztCz5^mr?Yx`OQpneEm!KWPUByOienv$9n0e*uPWubAS2tFaI3a?2Stk@25m2Djy} zex821{pj2eP`@)s?OG>m`9tjCeUaC@Y{Q@Jnf29wrrb4ywU@VAe^~$f%h}_#`#ycB z`?^^-o&7S~oGBZ(dOhAA{mX3Y$L{|O`V(X3^BDjD diff --git a/src/server/file/index.ts b/src/server/file/index.ts index e3487a2636..1cdf5207e4 100644 --- a/src/server/file/index.ts +++ b/src/server/file/index.ts @@ -21,12 +21,6 @@ app.use(async (ctx, next) => { // Init router const router = new Router(); -router.get('/default-avatar.jpg', ctx => { - const file = fs.createReadStream(`${__dirname}/assets/avatar.jpg`); - ctx.set('Content-Type', 'image/jpeg'); - ctx.body = file; -}); - router.get('/app-default.jpg', ctx => { const file = fs.createReadStream(`${__dirname}/assets/dummy.png`); ctx.set('Content-Type', 'image/jpeg'); diff --git a/src/server/index.ts b/src/server/index.ts index 601e288f3b..7d8938d584 100644 --- a/src/server/index.ts +++ b/src/server/index.ts @@ -25,6 +25,7 @@ import Logger from '../services/logger'; import { program } from '../argv'; import { UserProfiles } from '../models'; import { networkChart } from '../services/chart'; +import { genAvatar } from '../misc/gen-avatar'; export const serverLogger = new Logger('server', 'gray', false); @@ -72,6 +73,12 @@ router.use(activityPub.routes()); router.use(nodeinfo.routes()); router.use(wellKnown.routes()); +router.get('/avatar/:x', ctx => { + const avatar = genAvatar(ctx.params.x); + ctx.set('Content-Type', 'image/png'); + ctx.body = avatar; +}); + router.get('/verify-email/:code', async ctx => { const profile = await UserProfiles.findOne({ emailVerifyCode: ctx.params.code From 08221fdda75b657b006d24d8d630d10010cb2bda Mon Sep 17 00:00:00 2001 From: syuilo Date: Mon, 15 Apr 2019 20:41:56 +0900 Subject: [PATCH 5/7] Fix bug --- src/client/app/common/views/components/mention.vue | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/client/app/common/views/components/mention.vue b/src/client/app/common/views/components/mention.vue index e1f67282b6..f212fd3ca5 100644 --- a/src/client/app/common/views/components/mention.vue +++ b/src/client/app/common/views/components/mention.vue @@ -36,7 +36,9 @@ export default Vue.extend({ return this.host === localHost ? `@${this.username}` : `@${this.username}@${toUnicode(this.host)}`; }, isMe(): boolean { - return this.$store.getters.isSignedIn && this.canonical.toLowerCase() === `@${this.$store.state.i.username}@${toUnicode(localHost)}`.toLowerCase(); + return this.$store.getters.isSignedIn && ( + `@${this.username}@${toUnicode(this.host)}` === `@${this.$store.state.i.username}@${toUnicode(localHost)}`.toLowerCase() + ); } }, methods: { From 4d2e98af7b55a93d5107d38be05a3996d4cc4ff0 Mon Sep 17 00:00:00 2001 From: syuilo Date: Mon, 15 Apr 2019 20:52:08 +0900 Subject: [PATCH 6/7] =?UTF-8?q?=E7=AE=A1=E7=90=86=E8=80=85=E3=82=84?= =?UTF-8?q?=E3=83=A2=E3=83=87=E3=83=AC=E3=83=BC=E3=82=BF=E3=83=BC=E3=81=AF?= =?UTF-8?q?=E3=83=AC=E3=83=BC=E3=83=88=E3=83=AA=E3=83=9F=E3=83=83=E3=83=88?= =?UTF-8?q?=E7=84=A1=E5=8A=B9=E3=81=AB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/server/api/call.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/server/api/call.ts b/src/server/api/call.ts index c79f8eef5d..8be1b71cfa 100644 --- a/src/server/api/call.ts +++ b/src/server/api/call.ts @@ -59,7 +59,7 @@ export default async (endpoint: string, user: User | null | undefined, app: App }); } - if (ep.meta.requireCredential && ep.meta.limit) { + if (ep.meta.requireCredential && ep.meta.limit && !user!.isAdmin && !user!.isModerator) { // Rate limit await limiter(ep, user!).catch(e => { throw new ApiError({ From 724f81c7f3e67fe1aea035571198a259bff06f99 Mon Sep 17 00:00:00 2001 From: syuilo Date: Mon, 15 Apr 2019 21:01:46 +0900 Subject: [PATCH 7/7] 11.1.0 --- CHANGELOG.md | 11 +++++++++++ package.json | 2 +- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ba6f905e60..bf207d0052 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,17 @@ If you encounter any problems with updating, please try the following: 1. `npm run clean` or `npm run cleanall` 2. Retry update (Don't forget `npm i`) +11.1.0 (2019/04/15) +------------------- +### Improvements +* アイコン未設定時にランダムな画像を表示するように +* 管理者やモデレーターはレートリミット無効に + +### Fixes +* メンションの「あなた」インジケーターが表示されない問題を修正 +* ブロックAPIでエラーが発生する問題を修正 +* プッシュ通知の購読に失敗する問題を修正 + 11.0.3 (2019/04/15) ------------------- ### Fixes diff --git a/package.json b/package.json index 315c9ffcc9..8fe0129f31 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "misskey", "author": "syuilo ", - "version": "11.0.3", + "version": "11.1.0", "codename": "daybreak", "repository": { "type": "git",