diff options
| author | syuilo <syuilotan@yahoo.co.jp> | 2017-12-08 19:42:02 +0900 |
|---|---|---|
| committer | syuilo <syuilotan@yahoo.co.jp> | 2017-12-08 19:42:02 +0900 |
| commit | 303ccaa2f7bc6bdb52feef8c5f405f5b8fdda004 (patch) | |
| tree | 1602b993416120c6cea75222e1e83aa067530da5 | |
| parent | Refactor (diff) | |
| download | sharkey-303ccaa2f7bc6bdb52feef8c5f405f5b8fdda004.tar.gz sharkey-303ccaa2f7bc6bdb52feef8c5f405f5b8fdda004.tar.bz2 sharkey-303ccaa2f7bc6bdb52feef8c5f405f5b8fdda004.zip | |
Refactor
| -rw-r--r-- | src/api/common/add-file-to-drive.ts | 23 |
1 files changed, 13 insertions, 10 deletions
diff --git a/src/api/common/add-file-to-drive.ts b/src/api/common/add-file-to-drive.ts index 2a649788af..dea02eeca6 100644 --- a/src/api/common/add-file-to-drive.ts +++ b/src/api/common/add-file-to-drive.ts @@ -106,8 +106,8 @@ const addFile = async ( } } - const [properties, folder] = await Promise.all([ - // properties + const [wh, folder] = await Promise.all([ + // Width and height (when image) (async () => { // 画像かどうか if (!/^image\/.*$/.test(mime)) { @@ -116,22 +116,18 @@ const addFile = async ( const imageType = mime.split('/')[1]; - // 画像でもPNGかJPEGでないならスキップ - if (imageType != 'png' && imageType != 'jpeg') { + // 画像でもPNGかJPEGかGIFでないならスキップ + if (imageType != 'png' && imageType != 'jpeg' && imageType != 'gif') { 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 size = await prominence(g).size(); - const properties = { - width: size.width, - height: size.height - }; log('image width and height is calculated'); - return properties; + return [size.width, size.height]; })(), // folder (async () => { @@ -181,6 +177,13 @@ const addFile = async ( const readable = fs.createReadStream(path); + const properties = {}; + + if (wh) { + properties['width'] = wh[0]; + properties['height'] = wh[1]; + } + return addToGridFS(detectedName, readable, mime, { user_id: user._id, folder_id: folder !== null ? folder._id : null, |