diff options
| author | Kagami Sascha Rosylight <saschanaz@outlook.com> | 2023-03-10 01:37:22 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-03-10 09:37:22 +0900 |
| commit | 3f53cbd8f680c5659c53bf709fdd044c5dcb59c7 (patch) | |
| tree | b017dd7c0af0862df4e1778a87ad703bf8526e5d /packages/backend/test | |
| parent | enhance(backend): restore OpenAPI endpoints (#10281) (diff) | |
| download | misskey-3f53cbd8f680c5659c53bf709fdd044c5dcb59c7.tar.gz misskey-3f53cbd8f680c5659c53bf709fdd044c5dcb59c7.tar.bz2 misskey-3f53cbd8f680c5659c53bf709fdd044c5dcb59c7.zip | |
fix(backend/DriveService): convert WebP/AVIF to WebP (#10239)
* fix(backend/DriveService): convert transparent WebP/AVIF to PNG
* webpにする
その希望が複数ありましたので
* Update packages/backend/src/core/DriveService.ts
Co-authored-by: Acid Chicken (硫酸鶏) <root@acid-chicken.com>
* update test
* webpはwebpublicにできる
---------
Co-authored-by: Acid Chicken (硫酸鶏) <root@acid-chicken.com>
Co-authored-by: tamaina <tamaina@hotmail.co.jp>
Diffstat (limited to 'packages/backend/test')
| -rw-r--r-- | packages/backend/test/e2e/endpoints.ts | 41 | ||||
| -rw-r--r-- | packages/backend/test/resources/with-alpha.avif | bin | 0 -> 10032 bytes | |||
| -rw-r--r-- | packages/backend/test/resources/with-alpha.webp | bin | 0 -> 4984 bytes | |||
| -rw-r--r-- | packages/backend/test/resources/without-alpha.avif | bin | 0 -> 3982 bytes | |||
| -rw-r--r-- | packages/backend/test/resources/without-alpha.webp | bin | 0 -> 4474 bytes | |||
| -rw-r--r-- | packages/backend/test/utils.ts | 7 |
6 files changed, 46 insertions, 2 deletions
diff --git a/packages/backend/test/e2e/endpoints.ts b/packages/backend/test/e2e/endpoints.ts index c130093732..653520cf5f 100644 --- a/packages/backend/test/e2e/endpoints.ts +++ b/packages/backend/test/e2e/endpoints.ts @@ -4,7 +4,7 @@ import * as assert from 'assert'; // node-fetch only supports it's own Blob yet // https://github.com/node-fetch/node-fetch/pull/1664 import { Blob } from 'node-fetch'; -import { startServer, signup, post, api, uploadFile } from '../utils.js'; +import { startServer, signup, post, api, uploadFile, simpleGet } from '../utils.js'; import type { INestApplicationContext } from '@nestjs/common'; describe('Endpoints', () => { @@ -439,6 +439,45 @@ describe('Endpoints', () => { assert.strictEqual(res.body.name, 'image.svg'); assert.strictEqual(res.body.type, 'image/svg+xml'); }); + + for (const type of ['webp', 'avif']) { + const mediaType = `image/${type}`; + + const getWebpublicType = async (user: any, fileId: string): Promise<string> => { + // drive/files/create does not expose webpublicType directly, so get it by posting it + const res = await post(user, { + text: mediaType, + fileIds: [fileId], + }); + const apRes = await simpleGet(`notes/${res.id}`, 'application/activity+json'); + assert.strictEqual(apRes.status, 200); + assert.ok(Array.isArray(apRes.body.attachment)); + return apRes.body.attachment[0].mediaType; + }; + + test(`透明な${type}ファイルを作成できる`, async () => { + const path = `with-alpha.${type}`; + const res = await uploadFile(alice, { path }); + + assert.strictEqual(res.status, 200); + assert.strictEqual(res.body.name, path); + assert.strictEqual(res.body.type, mediaType); + + const webpublicType = await getWebpublicType(alice, res.body.id); + assert.strictEqual(webpublicType, 'image/webp'); + }); + + test(`透明じゃない${type}ファイルを作成できる`, async () => { + const path = `without-alpha.${type}`; + const res = await uploadFile(alice, { path }); + assert.strictEqual(res.status, 200); + assert.strictEqual(res.body.name, path); + assert.strictEqual(res.body.type, mediaType); + + const webpublicType = await getWebpublicType(alice, res.body.id); + assert.strictEqual(webpublicType, 'image/webp'); + }); + } }); describe('drive/files/update', () => { diff --git a/packages/backend/test/resources/with-alpha.avif b/packages/backend/test/resources/with-alpha.avif Binary files differnew file mode 100644 index 0000000000..05f494212e --- /dev/null +++ b/packages/backend/test/resources/with-alpha.avif diff --git a/packages/backend/test/resources/with-alpha.webp b/packages/backend/test/resources/with-alpha.webp Binary files differnew file mode 100644 index 0000000000..d7b0d70b7f --- /dev/null +++ b/packages/backend/test/resources/with-alpha.webp diff --git a/packages/backend/test/resources/without-alpha.avif b/packages/backend/test/resources/without-alpha.avif Binary files differnew file mode 100644 index 0000000000..9ea23608b8 --- /dev/null +++ b/packages/backend/test/resources/without-alpha.avif diff --git a/packages/backend/test/resources/without-alpha.webp b/packages/backend/test/resources/without-alpha.webp Binary files differnew file mode 100644 index 0000000000..a51091efe2 --- /dev/null +++ b/packages/backend/test/resources/without-alpha.webp diff --git a/packages/backend/test/utils.ts b/packages/backend/test/utils.ts index 37e5ae10d6..d1a5d6d949 100644 --- a/packages/backend/test/utils.ts +++ b/packages/backend/test/utils.ts @@ -204,7 +204,12 @@ export const simpleGet = async (path: string, accept = '*/*'): Promise<{ status: redirect: 'manual', }); - const body = res.headers.get('content-type') === 'application/json; charset=utf-8' + const jsonTypes = [ + 'application/json; charset=utf-8', + 'application/activity+json; charset=utf-8', + ]; + + const body = jsonTypes.includes(res.headers.get('content-type') ?? '') ? await res.json() : null; |