forked from mirror/misskey
Refactor
This commit is contained in:
parent
53db52bb40
commit
303ccaa2f7
@ -106,8 +106,8 @@ const addFile = async (
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const [properties, folder] = await Promise.all([
|
const [wh, folder] = await Promise.all([
|
||||||
// properties
|
// Width and height (when image)
|
||||||
(async () => {
|
(async () => {
|
||||||
// 画像かどうか
|
// 画像かどうか
|
||||||
if (!/^image\/.*$/.test(mime)) {
|
if (!/^image\/.*$/.test(mime)) {
|
||||||
@ -116,22 +116,18 @@ const addFile = async (
|
|||||||
|
|
||||||
const imageType = mime.split('/')[1];
|
const imageType = mime.split('/')[1];
|
||||||
|
|
||||||
// 画像でもPNGかJPEGでないならスキップ
|
// 画像でもPNGかJPEGかGIFでないならスキップ
|
||||||
if (imageType != 'png' && imageType != 'jpeg') {
|
if (imageType != 'png' && imageType != 'jpeg' && imageType != 'gif') {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
// If the file is an image, calculate width and height to save in property
|
// Calculate width and height
|
||||||
const g = gm(fs.createReadStream(path), name);
|
const g = gm(fs.createReadStream(path), name);
|
||||||
const size = await prominence(g).size();
|
const size = await prominence(g).size();
|
||||||
const properties = {
|
|
||||||
width: size.width,
|
|
||||||
height: size.height
|
|
||||||
};
|
|
||||||
|
|
||||||
log('image width and height is calculated');
|
log('image width and height is calculated');
|
||||||
|
|
||||||
return properties;
|
return [size.width, size.height];
|
||||||
})(),
|
})(),
|
||||||
// folder
|
// folder
|
||||||
(async () => {
|
(async () => {
|
||||||
@ -181,6 +177,13 @@ const addFile = async (
|
|||||||
|
|
||||||
const readable = fs.createReadStream(path);
|
const readable = fs.createReadStream(path);
|
||||||
|
|
||||||
|
const properties = {};
|
||||||
|
|
||||||
|
if (wh) {
|
||||||
|
properties['width'] = wh[0];
|
||||||
|
properties['height'] = wh[1];
|
||||||
|
}
|
||||||
|
|
||||||
return addToGridFS(detectedName, readable, mime, {
|
return addToGridFS(detectedName, readable, mime, {
|
||||||
user_id: user._id,
|
user_id: user._id,
|
||||||
folder_id: folder !== null ? folder._id : null,
|
folder_id: folder !== null ? folder._id : null,
|
||||||
|
Loading…
Reference in New Issue
Block a user