AVIF support

This commit is contained in:
ThatOneCalculator 2022-11-14 18:53:38 -08:00
parent 470dd5ba5b
commit f3f63a5dc1
10 changed files with 14 additions and 9 deletions

View File

@ -84,7 +84,8 @@
- Phosphor icons instead of FontAwesome - Phosphor icons instead of FontAwesome
- Fully deprecate MkEmojiPickerWindow in favor of MkEmojiPickerDialog - Fully deprecate MkEmojiPickerWindow in favor of MkEmojiPickerDialog
- Link hover effect - Link hover effect
- Replace all `$ts` with i18n - Replace all `$ts` with i18n\
- AVIF support
- Obliteration of Ai-chan - Obliteration of Ai-chan
- [Make showing ads optional](https://github.com/misskey-dev/misskey/pull/8996) - [Make showing ads optional](https://github.com/misskey-dev/misskey/pull/8996)
- [Tapping avatar in mobile opens account modal](https://github.com/misskey-dev/misskey/pull/9056) - [Tapping avatar in mobile opens account modal](https://github.com/misskey-dev/misskey/pull/9056)

View File

@ -1,6 +1,6 @@
{ {
"name": "calckey", "name": "calckey",
"version": "12.119.0-calc.13-rc.10", "version": "12.119.0-calc.13-rc.11",
"codename": "aqua", "codename": "aqua",
"repository": { "repository": {
"type": "git", "type": "git",

View File

@ -63,7 +63,7 @@ export async function getFileInfo(path: string, opts: {
let height: number | undefined; let height: number | undefined;
let orientation: number | undefined; let orientation: number | undefined;
if (['image/jpeg', 'image/gif', 'image/png', 'image/apng', 'image/webp', 'image/bmp', 'image/tiff', 'image/svg+xml', 'image/vnd.adobe.photoshop'].includes(type.mime)) { if (['image/jpeg', 'image/gif', 'image/png', 'image/apng', 'image/webp', 'image/bmp', 'image/tiff', 'image/svg+xml', 'image/vnd.adobe.photoshop', 'image/avif'].includes(type.mime)) {
const imageSize = await detectImageSize(path).catch(e => { const imageSize = await detectImageSize(path).catch(e => {
warnings.push(`detectImageSize failed: ${e}`); warnings.push(`detectImageSize failed: ${e}`);
return undefined; return undefined;
@ -90,7 +90,7 @@ export async function getFileInfo(path: string, opts: {
let blurhash: string | undefined; let blurhash: string | undefined;
if (['image/jpeg', 'image/gif', 'image/png', 'image/apng', 'image/webp', 'image/svg+xml'].includes(type.mime)) { if (['image/jpeg', 'image/gif', 'image/png', 'image/apng', 'image/webp', 'image/svg+xml', 'image/avif'].includes(type.mime)) {
blurhash = await getBlurhash(path).catch(e => { blurhash = await getBlurhash(path).catch(e => {
warnings.push(`getBlurhash failed: ${e}`); warnings.push(`getBlurhash failed: ${e}`);
return undefined; return undefined;

View File

@ -2,7 +2,7 @@ import { FILE_TYPE_BROWSERSAFE } from '@/const.js';
const dictionary = { const dictionary = {
'safe-file': FILE_TYPE_BROWSERSAFE, 'safe-file': FILE_TYPE_BROWSERSAFE,
'sharp-convertible-image': ['image/jpeg', 'image/png', 'image/gif', 'image/apng', 'image/vnd.mozilla.apng', 'image/webp', 'image/svg+xml'], 'sharp-convertible-image': ['image/jpeg', 'image/png', 'image/gif', 'image/apng', 'image/vnd.mozilla.apng', 'image/webp', 'image/svg+xml', 'image/avif'],
}; };
export const isMimeImage = (mime: string, type: keyof typeof dictionary): boolean => dictionary[type].includes(mime); export const isMimeImage = (mime: string, type: keyof typeof dictionary): boolean => dictionary[type].includes(mime);

View File

@ -60,7 +60,7 @@ export const DriveFileRepository = db.getRepository(DriveFile).extend({
} }
} }
const isImage = file.type && ['image/png', 'image/apng', 'image/gif', 'image/jpeg', 'image/webp', 'image/svg+xml'].includes(file.type); const isImage = file.type && ['image/png', 'image/apng', 'image/gif', 'image/jpeg', 'image/webp', 'image/svg+xml', 'image/avif'].includes(file.type);
return thumbnail ? (file.thumbnailUrl || (isImage ? (file.webpublicUrl || file.url) : null)) : (file.webpublicUrl || file.url); return thumbnail ? (file.thumbnailUrl || (isImage ? (file.webpublicUrl || file.url) : null)) : (file.webpublicUrl || file.url);
}, },

View File

@ -59,7 +59,7 @@ export default async function(ctx: Koa.Context) {
const convertFile = async () => { const convertFile = async () => {
if (isThumbnail) { if (isThumbnail) {
if (['image/jpeg', 'image/webp', 'image/png', 'image/svg+xml'].includes(mime)) { if (['image/jpeg', 'image/webp', 'image/png', 'image/svg+xml', 'image/avif'].includes(mime)) {
return await convertToWebp(path, 498, 280); return await convertToWebp(path, 498, 280);
} else if (mime.startsWith('video/')) { } else if (mime.startsWith('video/')) {
return await GenerateVideoThumbnail(path); return await GenerateVideoThumbnail(path);

View File

@ -49,6 +49,7 @@ async function save(file: DriveFile, path: string, name: string, type: string, h
if (type === 'image/png') ext = '.png'; if (type === 'image/png') ext = '.png';
if (type === 'image/webp') ext = '.webp'; if (type === 'image/webp') ext = '.webp';
if (type === 'image/apng') ext = '.apng'; if (type === 'image/apng') ext = '.apng';
if (type === 'image/avif') ext = '.avif';
if (type === 'image/vnd.mozilla.apng') ext = '.apng'; if (type === 'image/vnd.mozilla.apng') ext = '.apng';
} }
@ -171,7 +172,7 @@ export async function generateAlts(path: string, type: string, generateWeb: bool
} }
} }
if (!['image/jpeg', 'image/png', 'image/webp', 'image/svg+xml'].includes(type)) { if (!['image/jpeg', 'image/png', 'image/webp', 'image/svg+xml', 'image/avif'].includes(type)) {
logger.debug('web image and thumbnail not created (not an required file)'); logger.debug('web image and thumbnail not created (not an required file)');
return { return {
webpublic: null, webpublic: null,
@ -238,7 +239,7 @@ export async function generateAlts(path: string, type: string, generateWeb: bool
let thumbnail: IImage | null = null; let thumbnail: IImage | null = null;
try { try {
if (['image/jpeg', 'image/webp', 'image/png', 'image/svg+xml'].includes(type)) { if (['image/jpeg', 'image/webp', 'image/png', 'image/svg+xml', 'image/avif'].includes(type)) {
thumbnail = await convertSharpToWebp(img, 498, 280); thumbnail = await convertSharpToWebp(img, 498, 280);
} else { } else {
logger.debug('thumbnail not created (not an required file)'); logger.debug('thumbnail not created (not an required file)');

View File

@ -11,6 +11,7 @@ export const FILE_TYPE_BROWSERSAFE = [
'image/bmp', 'image/bmp',
'image/tiff', 'image/tiff',
'image/x-icon', 'image/x-icon',
'image/avif',
// OggS // OggS
'audio/opus', 'audio/opus',

View File

@ -52,6 +52,7 @@ onMounted(() => {
'image/gif', 'image/gif',
'image/apng', 'image/apng',
'image/vnd.mozilla.apng', 'image/vnd.mozilla.apng',
'image/avif',
]; ];
os.api('users/notes', { os.api('users/notes', {
userId: props.user.id, userId: props.user.id,

View File

@ -26,6 +26,7 @@ const mimeTypeMap = {
'image/webp': 'webp', 'image/webp': 'webp',
'image/jpeg': 'jpg', 'image/jpeg': 'jpg',
'image/png': 'png', 'image/png': 'png',
'image/avif': 'avif',
} as const; } as const;
export function uploadFile( export function uploadFile(