wip
This commit is contained in:
parent
e2cefb7f47
commit
4d4ac5dda5
4 changed files with 44 additions and 5 deletions
|
@ -178,6 +178,7 @@ export async function generateAlts(path: string, type: string, generateWeb: bool
|
||||||
}
|
}
|
||||||
|
|
||||||
let img: sharp.Sharp | null = null;
|
let img: sharp.Sharp | null = null;
|
||||||
|
let webpublicNeeded: boolean;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
img = sharp(path);
|
img = sharp(path);
|
||||||
|
@ -191,6 +192,9 @@ export async function generateAlts(path: string, type: string, generateWeb: bool
|
||||||
thumbnail: null,
|
thumbnail: null,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
webpublicNeeded = !!metadata.exif || !!metadata.icc || !!metadata.iptc || !!metadata.xmp || !!metadata.tifftagPhotoshop
|
||||||
|
|| !metadata.width || metadata.width > 2048 || !metadata.height || metadata.height > 2048;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
logger.warn(`sharp failed: ${e}`);
|
logger.warn(`sharp failed: ${e}`);
|
||||||
return {
|
return {
|
||||||
|
@ -206,11 +210,13 @@ export async function generateAlts(path: string, type: string, generateWeb: bool
|
||||||
logger.info(`creating web image`);
|
logger.info(`creating web image`);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (['image/jpeg'].includes(type)) {
|
if (['image/jpeg'].includes(type) && webpublicNeeded) {
|
||||||
webpublic = await convertSharpToJpeg(img, 2048, 2048);
|
webpublic = await convertSharpToJpeg(img, 2048, 2048);
|
||||||
} else if (['image/webp'].includes(type)) {
|
} else if (['image/webp'].includes(type) && webpublicNeeded) {
|
||||||
webpublic = await convertSharpToWebp(img, 2048, 2048);
|
webpublic = await convertSharpToWebp(img, 2048, 2048);
|
||||||
} else if (['image/png', 'image/svg+xml'].includes(type)) {
|
} else if (['image/png'].includes(type) && webpublicNeeded) {
|
||||||
|
webpublic = await convertSharpToPng(img, 2048, 2048);
|
||||||
|
} else if (['image/svg+xml'].includes(type)) {
|
||||||
webpublic = await convertSharpToPng(img, 2048, 2048);
|
webpublic = await convertSharpToPng(img, 2048, 2048);
|
||||||
} else {
|
} else {
|
||||||
logger.debug(`web image not created (not an required image)`);
|
logger.debug(`web image not created (not an required image)`);
|
||||||
|
|
|
@ -45,6 +45,7 @@
|
||||||
"autwh": "0.1.0",
|
"autwh": "0.1.0",
|
||||||
"blurhash": "1.1.4",
|
"blurhash": "1.1.4",
|
||||||
"broadcast-channel": "4.9.0",
|
"broadcast-channel": "4.9.0",
|
||||||
|
"browser-image-resizer": "2.2.1",
|
||||||
"chart.js": "3.7.0",
|
"chart.js": "3.7.0",
|
||||||
"chartjs-adapter-date-fns": "2.0.0",
|
"chartjs-adapter-date-fns": "2.0.0",
|
||||||
"chartjs-plugin-zoom": "1.2.0",
|
"chartjs-plugin-zoom": "1.2.0",
|
||||||
|
|
|
@ -9,6 +9,7 @@ import MkPostFormDialog from '@/components/post-form-dialog.vue';
|
||||||
import MkWaitingDialog from '@/components/waiting-dialog.vue';
|
import MkWaitingDialog from '@/components/waiting-dialog.vue';
|
||||||
import { resolve } from '@/router';
|
import { resolve } from '@/router';
|
||||||
import { $i } from '@/account';
|
import { $i } from '@/account';
|
||||||
|
import { readAndCompressImage } from 'browser-image-resizer';
|
||||||
|
|
||||||
export const pendingApiRequestsCount = ref(0);
|
export const pendingApiRequestsCount = ref(0);
|
||||||
|
|
||||||
|
@ -548,7 +549,7 @@ export function upload(file: File, folder?: any, name?: string): Promise<Misskey
|
||||||
const id = Math.random().toString();
|
const id = Math.random().toString();
|
||||||
|
|
||||||
const reader = new FileReader();
|
const reader = new FileReader();
|
||||||
reader.onload = (e) => {
|
reader.onload = async (e) => {
|
||||||
const ctx = reactive({
|
const ctx = reactive({
|
||||||
id: id,
|
id: id,
|
||||||
name: name || file.name || 'untitled',
|
name: name || file.name || 'untitled',
|
||||||
|
@ -557,12 +558,24 @@ export function upload(file: File, folder?: any, name?: string): Promise<Misskey
|
||||||
img: window.URL.createObjectURL(file)
|
img: window.URL.createObjectURL(file)
|
||||||
});
|
});
|
||||||
|
|
||||||
|
let resizedImage: any;
|
||||||
|
if (file.type === 'image/jpeg') {
|
||||||
|
const config = {
|
||||||
|
quality: 0.85,
|
||||||
|
maxWidth: 2048,
|
||||||
|
maxHeight: 2048,
|
||||||
|
autoRotate: true,
|
||||||
|
debug: true
|
||||||
|
};
|
||||||
|
resizedImage = await readAndCompressImage(file, config)
|
||||||
|
}
|
||||||
|
|
||||||
uploads.value.push(ctx);
|
uploads.value.push(ctx);
|
||||||
|
|
||||||
const data = new FormData();
|
const data = new FormData();
|
||||||
data.append('i', $i.token);
|
data.append('i', $i.token);
|
||||||
data.append('force', 'true');
|
data.append('force', 'true');
|
||||||
data.append('file', file);
|
data.append('file', resizedImage || file);
|
||||||
|
|
||||||
if (folder) data.append('folderId', folder);
|
if (folder) data.append('folderId', folder);
|
||||||
if (name) data.append('name', name);
|
if (name) data.append('name', name);
|
||||||
|
|
|
@ -1428,6 +1428,13 @@ broadcast-channel@4.9.0:
|
||||||
rimraf "3.0.2"
|
rimraf "3.0.2"
|
||||||
unload "2.3.1"
|
unload "2.3.1"
|
||||||
|
|
||||||
|
browser-image-resizer@2.2.1:
|
||||||
|
version "2.2.1"
|
||||||
|
resolved "https://registry.yarnpkg.com/browser-image-resizer/-/browser-image-resizer-2.2.1.tgz#61ba6d71edbdcc2caf2017c5687f5a8cf6301689"
|
||||||
|
integrity sha512-NwtjlgzKzX9zjI8bh77bnVeOrn6ZuOhD1u7NFjNClQbjCEwI4VH0GYqCh5Bcb0WIWZCDEVJFH9PH49Blk53nlw==
|
||||||
|
dependencies:
|
||||||
|
exifreader "^3.1.0"
|
||||||
|
|
||||||
browser-stdout@1.3.1:
|
browser-stdout@1.3.1:
|
||||||
version "1.3.1"
|
version "1.3.1"
|
||||||
resolved "https://registry.yarnpkg.com/browser-stdout/-/browser-stdout-1.3.1.tgz#baa559ee14ced73452229bad7326467c61fabd60"
|
resolved "https://registry.yarnpkg.com/browser-stdout/-/browser-stdout-1.3.1.tgz#baa559ee14ced73452229bad7326467c61fabd60"
|
||||||
|
@ -2748,6 +2755,13 @@ executable@^4.1.1:
|
||||||
dependencies:
|
dependencies:
|
||||||
pify "^2.2.0"
|
pify "^2.2.0"
|
||||||
|
|
||||||
|
exifreader@^3.1.0:
|
||||||
|
version "3.16.0"
|
||||||
|
resolved "https://registry.yarnpkg.com/exifreader/-/exifreader-3.16.0.tgz#3c106eccd134e8f4786f9e8e600f8269c5296b80"
|
||||||
|
integrity sha512-RfdE1LrU3KJm8NFnU3jJG4/1quEancwTz1VgwzItP11fBoVnb3Vp7JL8bQKU8rSgZm+Roa3+BJ7zg4OtoFhTFA==
|
||||||
|
optionalDependencies:
|
||||||
|
xmldom "^0.1.31"
|
||||||
|
|
||||||
exit-on-epipe@~1.0.1:
|
exit-on-epipe@~1.0.1:
|
||||||
version "1.0.1"
|
version "1.0.1"
|
||||||
resolved "https://registry.yarnpkg.com/exit-on-epipe/-/exit-on-epipe-1.0.1.tgz#0bdd92e87d5285d267daa8171d0eb06159689692"
|
resolved "https://registry.yarnpkg.com/exit-on-epipe/-/exit-on-epipe-1.0.1.tgz#0bdd92e87d5285d267daa8171d0eb06159689692"
|
||||||
|
@ -6417,6 +6431,11 @@ xml-js@^1.6.11:
|
||||||
dependencies:
|
dependencies:
|
||||||
sax "^1.2.4"
|
sax "^1.2.4"
|
||||||
|
|
||||||
|
xmldom@^0.1.31:
|
||||||
|
version "0.1.31"
|
||||||
|
resolved "https://registry.yarnpkg.com/xmldom/-/xmldom-0.1.31.tgz#b76c9a1bd9f0a9737e5a72dc37231cf38375e2ff"
|
||||||
|
integrity sha512-yS2uJflVQs6n+CyjHoaBmVSqIDevTAWrzMmjG1Gc7h1qQ7uVozNhEPJAwZXWyGQ/Gafo3fCwrcaokezLPupVyQ==
|
||||||
|
|
||||||
y18n@^4.0.0:
|
y18n@^4.0.0:
|
||||||
version "4.0.1"
|
version "4.0.1"
|
||||||
resolved "https://registry.yarnpkg.com/y18n/-/y18n-4.0.1.tgz#8db2b83c31c5d75099bb890b23f3094891e247d4"
|
resolved "https://registry.yarnpkg.com/y18n/-/y18n-4.0.1.tgz#8db2b83c31c5d75099bb890b23f3094891e247d4"
|
||||||
|
|
Loading…
Reference in a new issue