From cfd18889694650d9ebb798fab240c0e474690c37 Mon Sep 17 00:00:00 2001 From: syuilo Date: Sun, 26 Dec 2021 12:08:22 +0900 Subject: [PATCH 01/20] refactor --- packages/backend/src/const.ts | 2 +- packages/backend/src/server/file/send-drive-file.ts | 8 ++++---- packages/backend/src/server/proxy/proxy-media.ts | 4 ++-- packages/backend/src/services/drive/add-file.ts | 4 ++-- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/packages/backend/src/const.ts b/packages/backend/src/const.ts index eb0c81f2c7..59d7206e01 100644 --- a/packages/backend/src/const.ts +++ b/packages/backend/src/const.ts @@ -4,7 +4,7 @@ export const USER_ACTIVE_THRESHOLD = 1000 * 60 * 60 * 24 * 3; // 3days // ブラウザで直接表示することを許可するファイルの種類のリスト // ここに含まれないものは application/octet-stream としてレスポンスされる // SVGはXSSを生むので許可しない -export const FILE_TYPE_WHITELIST = [ +export const FILE_TYPE_BROWSERSAFE = [ 'image/png', 'image/gif', 'image/jpeg', diff --git a/packages/backend/src/server/file/send-drive-file.ts b/packages/backend/src/server/file/send-drive-file.ts index 1f88d9e315..7bfc36e25a 100644 --- a/packages/backend/src/server/file/send-drive-file.ts +++ b/packages/backend/src/server/file/send-drive-file.ts @@ -14,7 +14,7 @@ import { detectType } from '@/misc/get-file-info'; import { convertToJpeg, convertToPngOrJpeg } from '@/services/drive/image-processor'; import { GenerateVideoThumbnail } from '@/services/drive/generate-video-thumbnail'; import { StatusError } from '@/misc/fetch'; -import { FILE_TYPE_WHITELIST } from '@/const'; +import { FILE_TYPE_BROWSERSAFE } from '@/const'; //const _filename = fileURLToPath(import.meta.url); const _filename = __filename; @@ -83,7 +83,7 @@ export default async function(ctx: Koa.Context) { const image = await convertFile(); ctx.body = image.data; - ctx.set('Content-Type', FILE_TYPE_WHITELIST.includes(image.type) ? image.type : 'application/octet-stream'); + ctx.set('Content-Type', FILE_TYPE_BROWSERSAFE.includes(image.type) ? image.type : 'application/octet-stream'); ctx.set('Cache-Control', 'max-age=31536000, immutable'); } catch (e) { serverLogger.error(`${e}`); @@ -114,14 +114,14 @@ export default async function(ctx: Koa.Context) { }).toString(); ctx.body = InternalStorage.read(key); - ctx.set('Content-Type', FILE_TYPE_WHITELIST.includes(mime) ? mime : 'application/octet-stream'); + ctx.set('Content-Type', FILE_TYPE_BROWSERSAFE.includes(mime) ? mime : 'application/octet-stream'); ctx.set('Cache-Control', 'max-age=31536000, immutable'); ctx.set('Content-Disposition', contentDisposition('inline', filename)); } else { const readable = InternalStorage.read(file.accessKey!); readable.on('error', commonReadableHandlerGenerator(ctx)); ctx.body = readable; - ctx.set('Content-Type', FILE_TYPE_WHITELIST.includes(file.type) ? file.type : 'application/octet-stream'); + ctx.set('Content-Type', FILE_TYPE_BROWSERSAFE.includes(file.type) ? file.type : 'application/octet-stream'); ctx.set('Cache-Control', 'max-age=31536000, immutable'); ctx.set('Content-Disposition', contentDisposition('inline', file.name)); } diff --git a/packages/backend/src/server/proxy/proxy-media.ts b/packages/backend/src/server/proxy/proxy-media.ts index 7d6652a97a..b116b4b961 100644 --- a/packages/backend/src/server/proxy/proxy-media.ts +++ b/packages/backend/src/server/proxy/proxy-media.ts @@ -6,7 +6,7 @@ import { createTemp } from '@/misc/create-temp'; import { downloadUrl } from '@/misc/download-url'; import { detectType } from '@/misc/get-file-info'; import { StatusError } from '@/misc/fetch'; -import { FILE_TYPE_WHITELIST } from '@/const'; +import { FILE_TYPE_BROWSERSAFE } from '@/const'; export async function proxyMedia(ctx: Koa.Context) { const url = 'url' in ctx.query ? ctx.query.url : 'https://' + ctx.params.url; @@ -19,7 +19,7 @@ export async function proxyMedia(ctx: Koa.Context) { const { mime, ext } = await detectType(path); - if (!FILE_TYPE_WHITELIST.includes(mime)) throw 403; + if (!FILE_TYPE_BROWSERSAFE.includes(mime)) throw 403; let image: IImage; diff --git a/packages/backend/src/services/drive/add-file.ts b/packages/backend/src/services/drive/add-file.ts index ae1dbd3ca7..a59c9501bc 100644 --- a/packages/backend/src/services/drive/add-file.ts +++ b/packages/backend/src/services/drive/add-file.ts @@ -20,7 +20,7 @@ import { isDuplicateKeyValueError } from '@/misc/is-duplicate-key-value-error'; import * as S3 from 'aws-sdk/clients/s3'; import { getS3 } from './s3'; import * as sharp from 'sharp'; -import { FILE_TYPE_WHITELIST } from '@/const'; +import { FILE_TYPE_BROWSERSAFE } from '@/const'; const logger = driveLogger.createSubLogger('register', 'yellow'); @@ -242,7 +242,7 @@ export async function generateAlts(path: string, type: string, generateWeb: bool */ async function upload(key: string, stream: fs.ReadStream | Buffer, type: string, filename?: string) { if (type === 'image/apng') type = 'image/png'; - if (!FILE_TYPE_WHITELIST.includes(type)) type = 'application/octet-stream'; + if (!FILE_TYPE_BROWSERSAFE.includes(type)) type = 'application/octet-stream'; const meta = await fetchMeta(); From 154e418c3413882014c61fbf5e9462629ad4a6da Mon Sep 17 00:00:00 2001 From: syuilo Date: Sun, 26 Dec 2021 12:10:33 +0900 Subject: [PATCH 02/20] Update const.ts --- packages/backend/src/const.ts | 42 +++++++++++++++++++++++------------ 1 file changed, 28 insertions(+), 14 deletions(-) diff --git a/packages/backend/src/const.ts b/packages/backend/src/const.ts index 59d7206e01..b00bd81655 100644 --- a/packages/backend/src/const.ts +++ b/packages/backend/src/const.ts @@ -5,6 +5,7 @@ export const USER_ACTIVE_THRESHOLD = 1000 * 60 * 60 * 24 * 3; // 3days // ここに含まれないものは application/octet-stream としてレスポンスされる // SVGはXSSを生むので許可しない export const FILE_TYPE_BROWSERSAFE = [ + // Images 'image/png', 'image/gif', 'image/jpeg', @@ -13,21 +14,34 @@ export const FILE_TYPE_BROWSERSAFE = [ 'image/bmp', 'image/tiff', 'image/x-icon', - 'video/mpeg', - 'video/mp4', - 'video/mp2t', - 'video/webm', + + // OggS + 'audio/opus', 'video/ogg', - 'video/3gpp', - 'video/quicktime', - 'video/x-m4v', - 'video/x-msvideo', - 'audio/mpeg', - 'audio/aac', - 'audio/wav', - 'audio/webm', 'audio/ogg', - 'audio/x-m4a', - 'audio/x-flac', 'application/ogg', + + // ISO/IEC base media file format + 'video/quicktime', + 'video/mp4', + 'audio/mp4', + 'video/x-m4v', + 'audio/x-m4a', + 'video/3gpp', + 'video/3gpp2', + + 'video/mpeg', + 'audio/mpeg', + + 'video/webm', + 'audio/webm', + + 'audio/aac', + 'audio/x-flac', + 'audio/vnd.wave', ]; +/* +https://github.com/sindresorhus/file-type/blob/main/supported.js +https://github.com/sindresorhus/file-type/blob/main/core.js +https://developer.mozilla.org/en-US/docs/Web/Media/Formats/Containers +*/ From ae2d71553e92b324f59c15d2b151b2583a6e65ab Mon Sep 17 00:00:00 2001 From: syuilo Date: Mon, 27 Dec 2021 22:59:14 +0900 Subject: [PATCH 03/20] enhance(client): :art: --- .../client/src/components/emoji-picker.vue | 8 +-- .../client/src/components/form/switch.vue | 42 ++++++++++----- .../components/reactions-viewer.reaction.vue | 2 +- .../components/{particle.vue => ripple.vue} | 53 +++++++++++-------- packages/client/src/directives/index.ts | 4 +- .../src/directives/{particle.ts => ripple.ts} | 8 +-- 6 files changed, 71 insertions(+), 46 deletions(-) rename packages/client/src/components/{particle.vue => ripple.vue} (65%) rename packages/client/src/directives/{particle.ts => ripple.ts} (59%) diff --git a/packages/client/src/components/emoji-picker.vue b/packages/client/src/components/emoji-picker.vue index ff450246f9..a8eed1ca21 100644 --- a/packages/client/src/components/emoji-picker.vue +++ b/packages/client/src/components/emoji-picker.vue @@ -77,7 +77,7 @@ import { defineComponent, markRaw } from 'vue'; import { emojilist } from '@/scripts/emojilist'; import { getStaticImageUrl } from '@/scripts/get-static-image-url'; -import Particle from '@/components/particle.vue'; +import Ripple from '@/components/ripple.vue'; import * as os from '@/os'; import { isTouchUsing } from '@/scripts/touch'; import { isMobile } from '@/scripts/is-mobile'; @@ -296,9 +296,9 @@ export default defineComponent({ if (ev) { const el = ev.currentTarget || ev.target; const rect = el.getBoundingClientRect(); - const x = rect.left + (el.clientWidth / 2); - const y = rect.top + (el.clientHeight / 2); - os.popup(Particle, { x, y }, {}, 'end'); + const x = rect.left + (el.offsetWidth / 2); + const y = rect.top + (el.offsetHeight / 2); + os.popup(Ripple, { x, y }, {}, 'end'); } const key = this.getKey(emoji); diff --git a/packages/client/src/components/form/switch.vue b/packages/client/src/components/form/switch.vue index aa28292b97..aa9b09215e 100644 --- a/packages/client/src/components/form/switch.vue +++ b/packages/client/src/components/form/switch.vue @@ -9,7 +9,7 @@ :disabled="disabled" @keydown.enter="toggle" > - + @@ -20,7 +20,9 @@ @@ -51,7 +64,7 @@ export default defineComponent({ .ziffeoms { position: relative; display: flex; - transition: all 0.2s; + transition: all 0.2s ease; > * { user-select: none; @@ -85,6 +98,8 @@ export default defineComponent({ opacity: 0; color: var(--fgOnAccent); font-size: 13px; + transform: scale(0.5); + transition: all 0.2s ease; } } @@ -131,6 +146,7 @@ export default defineComponent({ > .check { opacity: 1; + transform: scale(1); } } } diff --git a/packages/client/src/components/reactions-viewer.reaction.vue b/packages/client/src/components/reactions-viewer.reaction.vue index a1de99f018..bbf518549c 100644 --- a/packages/client/src/components/reactions-viewer.reaction.vue +++ b/packages/client/src/components/reactions-viewer.reaction.vue @@ -2,7 +2,7 @@