mirror of
https://git.joinsharkey.org/Sharkey/Sharkey.git
synced 2024-11-30 13:23:09 +02:00
* Resolve #5688 * あああああ * 😇 * :thinking_face: * Update detect-mine.ts Co-authored-by: syuilo <Syuilotan@yahoo.co.jp>
This commit is contained in:
parent
90cfd87f46
commit
8aafafe416
1 changed files with 3 additions and 3 deletions
|
@ -1,15 +1,15 @@
|
||||||
import * as fs from 'fs';
|
import * as fs from 'fs';
|
||||||
import fileType = require('file-type');
|
|
||||||
import checkSvg from '../misc/check-svg';
|
import checkSvg from '../misc/check-svg';
|
||||||
|
const FileType = require('file-type');
|
||||||
|
|
||||||
export async function detectMine(path: string) {
|
export async function detectMine(path: string) {
|
||||||
return new Promise<[string, string | null]>((res, rej) => {
|
return new Promise<[string, string | null]>((res, rej) => {
|
||||||
const readable = fs.createReadStream(path);
|
const readable = fs.createReadStream(path);
|
||||||
readable
|
readable
|
||||||
.on('error', rej)
|
.on('error', rej)
|
||||||
.once('data', (buffer: Buffer) => {
|
.once('data', async (buffer: Buffer) => {
|
||||||
readable.destroy();
|
readable.destroy();
|
||||||
const type = fileType(buffer);
|
const type = await FileType.fromBuffer(buffer);
|
||||||
if (type) {
|
if (type) {
|
||||||
if (type.mime == 'application/xml' && checkSvg(path)) {
|
if (type.mime == 'application/xml' && checkSvg(path)) {
|
||||||
res(['image/svg+xml', 'svg']);
|
res(['image/svg+xml', 'svg']);
|
||||||
|
|
Loading…
Reference in a new issue