summaryrefslogtreecommitdiff
path: root/src/services
diff options
context:
space:
mode:
authorsyuilo <syuilotan@yahoo.co.jp>2019-05-16 01:07:32 +0900
committersyuilo <syuilotan@yahoo.co.jp>2019-05-16 01:07:32 +0900
commit3f5b96bf629da5f736c09b10058802eed28cca18 (patch)
tree9ee346f40ba93b252396b6b58ce724be54362c7c /src/services
parentGIFのサムネイルが生成されないのを修正 (diff)
downloadsharkey-3f5b96bf629da5f736c09b10058802eed28cca18.tar.gz
sharkey-3f5b96bf629da5f736c09b10058802eed28cca18.tar.bz2
sharkey-3f5b96bf629da5f736c09b10058802eed28cca18.zip
Resolve #4928
Diffstat (limited to 'src/services')
-rw-r--r--src/services/drive/add-file.ts27
-rw-r--r--src/services/drive/delete-file.ts18
2 files changed, 31 insertions, 14 deletions
diff --git a/src/services/drive/add-file.ts b/src/services/drive/add-file.ts
index 949089eded..701878b282 100644
--- a/src/services/drive/add-file.ts
+++ b/src/services/drive/add-file.ts
@@ -8,7 +8,6 @@ import * as sharp from 'sharp';
import { publishMainStream, publishDriveStream } from '../stream';
import delFile from './delete-file';
-import config from '../../config';
import { fetchMeta } from '../../misc/fetch-meta';
import { GenerateVideoThumbnail } from './generate-video-thumbnail';
import { driveLogger } from './logger';
@@ -37,7 +36,9 @@ async function save(file: DriveFile, path: string, name: string, type: string, h
// thunbnail, webpublic を必要なら生成
const alts = await generateAlts(path, type, !file.uri);
- if (config.drive && config.drive.storage == 'minio') {
+ const meta = await fetchMeta();
+
+ if (meta.useObjectStorage) {
//#region ObjectStorage params
let [ext] = (name.match(/\.([a-zA-Z0-9_-]+)$/) || ['']);
@@ -47,11 +48,11 @@ async function save(file: DriveFile, path: string, name: string, type: string, h
if (type === 'image/webp') ext = '.webp';
}
- const baseUrl = config.drive.baseUrl
- || `${ config.drive.config.useSSL ? 'https' : 'http' }://${ config.drive.config.endPoint }${ config.drive.config.port ? `:${config.drive.config.port}` : '' }/${ config.drive.bucket }`;
+ const baseUrl = meta.objectStorageBaseUrl
+ || `${ meta.objectStorageUseSSL ? 'https' : 'http' }://${ meta.objectStorageEndpoint }${ meta.objectStoragePort ? `:${meta.objectStoragePort}` : '' }/${ meta.objectStorageBucket }`;
// for original
- const key = `${config.drive.prefix}/${uuid.v4()}${ext}`;
+ const key = `${meta.objectStoragePrefix}/${uuid.v4()}${ext}`;
const url = `${ baseUrl }/${ key }`;
// for alts
@@ -68,7 +69,7 @@ async function save(file: DriveFile, path: string, name: string, type: string, h
];
if (alts.webpublic) {
- webpublicKey = `${config.drive.prefix}/${uuid.v4()}.${alts.webpublic.ext}`;
+ webpublicKey = `${meta.objectStoragePrefix}/${uuid.v4()}.${alts.webpublic.ext}`;
webpublicUrl = `${ baseUrl }/${ webpublicKey }`;
logger.info(`uploading webpublic: ${webpublicKey}`);
@@ -76,7 +77,7 @@ async function save(file: DriveFile, path: string, name: string, type: string, h
}
if (alts.thumbnail) {
- thumbnailKey = `${config.drive.prefix}/${uuid.v4()}.${alts.thumbnail.ext}`;
+ thumbnailKey = `${meta.objectStoragePrefix}/${uuid.v4()}.${alts.thumbnail.ext}`;
thumbnailUrl = `${ baseUrl }/${ thumbnailKey }`;
logger.info(`uploading thumbnail: ${thumbnailKey}`);
@@ -194,7 +195,15 @@ export async function generateAlts(path: string, type: string, generateWeb: bool
* Upload to ObjectStorage
*/
async function upload(key: string, stream: fs.ReadStream | Buffer, type: string, filename?: string) {
- const minio = new Minio.Client(config.drive!.config);
+ const meta = await fetchMeta();
+
+ const minio = new Minio.Client({
+ endPoint: meta.objectStorageEndpoint!,
+ port: meta.objectStoragePort ? meta.objectStoragePort : undefined,
+ useSSL: meta.objectStorageUseSSL,
+ accessKey: meta.objectStorageAccessKey!,
+ secretKey: meta.objectStorageSecretKey!,
+ });
const metadata = {
'Content-Type': type,
@@ -203,7 +212,7 @@ async function upload(key: string, stream: fs.ReadStream | Buffer, type: string,
if (filename) metadata['Content-Disposition'] = contentDisposition('inline', filename);
- await minio.putObject(config.drive!.bucket!, key, stream, undefined, metadata);
+ await minio.putObject(meta.objectStorageBucket!, key, stream, undefined, metadata);
}
async function deleteOldFile(user: IRemoteUser) {
diff --git a/src/services/drive/delete-file.ts b/src/services/drive/delete-file.ts
index f1280822a4..ba0482dbe2 100644
--- a/src/services/drive/delete-file.ts
+++ b/src/services/drive/delete-file.ts
@@ -1,9 +1,9 @@
import * as Minio from 'minio';
-import config from '../../config';
import { DriveFile } from '../../models/entities/drive-file';
import { InternalStorage } from './internal-storage';
import { DriveFiles, Instances, Notes } from '../../models';
import { driveChart, perUserDriveChart, instanceChart } from '../chart';
+import { fetchMeta } from '../../misc/fetch-meta';
export default async function(file: DriveFile, isExpired = false) {
if (file.storedInternal) {
@@ -17,16 +17,24 @@ export default async function(file: DriveFile, isExpired = false) {
InternalStorage.del(file.webpublicAccessKey!);
}
} else if (!file.isLink) {
- const minio = new Minio.Client(config.drive!.config);
+ const meta = await fetchMeta();
- await minio.removeObject(config.drive!.bucket!, file.accessKey!);
+ const minio = new Minio.Client({
+ endPoint: meta.objectStorageEndpoint!,
+ port: meta.objectStoragePort ? meta.objectStoragePort : undefined,
+ useSSL: meta.objectStorageUseSSL,
+ accessKey: meta.objectStorageAccessKey!,
+ secretKey: meta.objectStorageSecretKey!,
+ });
+
+ await minio.removeObject(meta.objectStorageBucket!, file.accessKey!);
if (file.thumbnailUrl) {
- await minio.removeObject(config.drive!.bucket!, file.thumbnailAccessKey!);
+ await minio.removeObject(meta.objectStorageBucket!, file.thumbnailAccessKey!);
}
if (file.webpublicUrl) {
- await minio.removeObject(config.drive!.bucket!, file.webpublicAccessKey!);
+ await minio.removeObject(meta.objectStorageBucket!, file.webpublicAccessKey!);
}
}