summaryrefslogtreecommitdiff
path: root/src/services
diff options
context:
space:
mode:
authortamaina <tamaina@hotmail.co.jp>2020-01-04 07:20:41 +0900
committersyuilo <Syuilotan@yahoo.co.jp>2020-01-04 07:20:41 +0900
commite37840d870eec41599cde71baee70e3688e21f32 (patch)
treed32ba90ff25ca7491ea74beb871fdc36bc8e4101 /src/services
parent2020 (diff)
downloadsharkey-e37840d870eec41599cde71baee70e3688e21f32.tar.gz
sharkey-e37840d870eec41599cde71baee70e3688e21f32.tar.bz2
sharkey-e37840d870eec41599cde71baee70e3688e21f32.zip
ドライブ関連の修正 (#5673)
* :v: * Update add-file.ts * fix
Diffstat (limited to 'src/services')
-rw-r--r--src/services/drive/add-file.ts26
-rw-r--r--src/services/drive/image-processor.ts1
-rw-r--r--src/services/drive/internal-storage.ts12
3 files changed, 25 insertions, 14 deletions
diff --git a/src/services/drive/add-file.ts b/src/services/drive/add-file.ts
index 54aa018a46..350e4dfe19 100644
--- a/src/services/drive/add-file.ts
+++ b/src/services/drive/add-file.ts
@@ -159,6 +159,8 @@ export async function generateAlts(path: string, type: string, generateWeb: bool
webpublic = await convertToWebp(path, 2048, 2048);
} else if (['image/png'].includes(type)) {
webpublic = await convertToPng(path, 2048, 2048);
+ } else {
+ logger.debug(`web image not created (not an required image)`);
}
} catch (e) {
logger.warn(`web image not created (an error occured)`, e);
@@ -180,8 +182,10 @@ export async function generateAlts(path: string, type: string, generateWeb: bool
try {
thumbnail = await GenerateVideoThumbnail(path);
} catch (e) {
- logger.error(`GenerateVideoThumbnail failed: ${e}`);
+ logger.warn(`GenerateVideoThumbnail failed: ${e}`);
}
+ } else {
+ logger.debug(`thumbnail not created (not an required file)`);
}
} catch (e) {
logger.warn(`thumbnail not created (an error occured)`, e);
@@ -351,7 +355,7 @@ export default async function(
let propPromises: Promise<void>[] = [];
- const isImage = ['image/jpeg', 'image/gif', 'image/png', 'image/apng', 'image/vnd.mozilla.apng', 'image/webp'].includes(mime);
+ const isImage = ['image/jpeg', 'image/gif', 'image/png', 'image/apng', 'image/vnd.mozilla.apng', 'image/webp', 'image/svg+xml'].includes(mime);
if (isImage) {
const img = sharp(path);
@@ -374,15 +378,21 @@ export default async function(
logger.debug('calculating average color...');
try {
- const info = await (img as any).stats();
+ const info = await img.stats();
+
+ if (info.isOpaque) {
+ const r = Math.round(info.channels[0].mean);
+ const g = Math.round(info.channels[1].mean);
+ const b = Math.round(info.channels[2].mean);
- const r = Math.round(info.channels[0].mean);
- const g = Math.round(info.channels[1].mean);
- const b = Math.round(info.channels[2].mean);
+ logger.debug(`average color is calculated: ${r}, ${g}, ${b}`);
- logger.debug(`average color is calculated: ${r}, ${g}, ${b}`);
+ properties['avgColor'] = `rgb(${r},${g},${b})`;
+ } else {
+ logger.debug(`this image is not opaque so average color is 255, 255, 255`);
- properties['avgColor'] = `rgb(${r},${g},${b})`;
+ properties['avgColor'] = `rgb(255,255,255)`;
+ }
} catch (e) { }
};
diff --git a/src/services/drive/image-processor.ts b/src/services/drive/image-processor.ts
index e2dd90cfa0..21a05fa9e4 100644
--- a/src/services/drive/image-processor.ts
+++ b/src/services/drive/image-processor.ts
@@ -1,5 +1,4 @@
import * as sharp from 'sharp';
-import * as fs from 'fs';
export type IImage = {
data: Buffer;
diff --git a/src/services/drive/internal-storage.ts b/src/services/drive/internal-storage.ts
index ff890d7d47..f8d7489a22 100644
--- a/src/services/drive/internal-storage.ts
+++ b/src/services/drive/internal-storage.ts
@@ -3,25 +3,27 @@ import * as Path from 'path';
import config from '../../config';
export class InternalStorage {
- private static readonly path = Path.resolve(`${__dirname}/../../../files`);
+ private static readonly path = Path.resolve(__dirname, '../../../files');
+
+ public static resolvePath = (key: string) => Path.resolve(InternalStorage.path, key);
public static read(key: string) {
- return fs.createReadStream(`${InternalStorage.path}/${key}`);
+ return fs.createReadStream(InternalStorage.resolvePath(key));
}
public static saveFromPath(key: string, srcPath: string) {
fs.mkdirSync(InternalStorage.path, { recursive: true });
- fs.copyFileSync(srcPath, `${InternalStorage.path}/${key}`);
+ fs.copyFileSync(srcPath, InternalStorage.resolvePath(key));
return `${config.url}/files/${key}`;
}
public static saveFromBuffer(key: string, data: Buffer) {
fs.mkdirSync(InternalStorage.path, { recursive: true });
- fs.writeFileSync(`${InternalStorage.path}/${key}`, data);
+ fs.writeFileSync(InternalStorage.resolvePath(key), data);
return `${config.url}/files/${key}`;
}
public static del(key: string) {
- fs.unlink(`${InternalStorage.path}/${key}`, () => {});
+ fs.unlink(InternalStorage.resolvePath(key), () => {});
}
}