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>
This commit is contained in:
Kagami Sascha Rosylight 2023-03-10 01:37:22 +01:00 committed by GitHub
parent e0b7633a7a
commit 3f53cbd8f6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 86 additions and 42 deletions

View file

@ -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', () => {