<commit_before>import { Buffer } from 'buffer';
import * as fs from 'fs';

import * as mongodb from 'mongodb';
import * as crypto from 'crypto';
import * as debug from 'debug';
import fileType = require('file-type');
import * as Minio from 'minio';
import * as uuid from 'uuid';
import * as sharp from 'sharp';

import DriveFile, { IMetadata, getDriveFileBucket, IDriveFile } from '../../models/drive-file';
import DriveFolder from '../../models/drive-folder';
import { pack } from '../../models/drive-file';
import { publishUserStream, publishDriveStream } from '../../stream';
import { isLocalUser, IUser, IRemoteUser } from '../../models/user';
import delFile from './delete-file';
import config from '../../config';
import { getDriveFileThumbnailBucket } from '../../models/drive-file-thumbnail';
import { updateDriveStats } from '../update-chart';

const log = debug('misskey:drive:add-file');

async function save(path: string, name: string, type: string, hash: string, size: number, metadata: any): Promise<IDriveFile> {
	let thumbnail: Buffer;

	if (['image/jpeg', 'image/png', 'image/webp'].includes(type)) {
		thumbnail = await sharp(path)
			.resize(300)
			.jpeg({
				quality: 50,
				progressive: true
			})
			.toBuffer();
	}

	if (config.drive && config.drive.storage == 'minio') {
		const minio = new Minio.Client(config.drive.config);
		const key = `${config.drive.prefix}/${uuid.v4()}/${name}`;
		const thumbnailKey = `${config.drive.prefix}/<KEY>`;
<commit_msg>Fix bug<commit_after>import { Buffer } from 'buffer';
import * as fs from 'fs';

import * as mongodb from 'mongodb';
import * as crypto from 'crypto';
import * as debug from 'debug';
import fileType = require('file-type');
import * as Minio from 'minio';
import * as uuid from 'uuid';
import * as sharp from 'sharp';

import DriveFile, { IMetadata, getDriveFileBucket, IDriveFile } from '../../models/drive-file';
import DriveFolder from '../../models/drive-folder';
import { pack } from '../../models/drive-file';
import { publishUserStream, publishDriveStream } from '../../stream';
import { isLocalUser, IUser, IRemoteUser } from '../../models/user';
import delFile from './delete-file';
import config from '../../config';
import { getDriveFileThumbnailBucket } from '../../models/drive-file-thumbnail';
import { updateDriveStats } from '../update-chart';

const log = debug('misskey:drive:add-file');

async function save(path: string, name: string, type: string, hash: string, size: number, metadata: any): Promise<IDriveFile> {
	let thumbnail: Buffer;

	if (['image/jpeg', 'image/png', 'image/webp'].includes(type)) {
		thumbnail = await sharp(path)
			.resize(300)
			.jpeg({
				quality: 50,
				progressive: true
			})
			.toBuffer();
	}

	if (config.drive && config.drive.storage == 'minio') {
		const minio = new Minio.Client(config.drive.config);
		const key = `${config.drive.prefix}/${uuid.v4()}/${encodeURIComponent(name)}`;
		const thumbnailKey = `${config.drive.prefix}/${uuid.v4()}/${encodeURIComponent(name)}.<KEY>`;

{'fraction_non_alphanumeric': 0.17998011269472985, 'fraction_numerical': 0.004308916141862778, 'mean_word_length': 4.212435233160622, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1661054', 'n_tokens_mistral': 980, 'n_tokens_neox': 937, 'n_words': 267}