wip????
This commit is contained in:
parent
ca0025b499
commit
12afc294f7
4 changed files with 48 additions and 41 deletions
|
|
@ -15,7 +15,8 @@ import { encode } from 'blurhash';
|
|||
import { createTempDir } from '@/misc/create-temp.js';
|
||||
import { AiService } from '@/core/AiService.js';
|
||||
import { bindThis } from '@/decorators.js';
|
||||
import type { Request } from 'got';
|
||||
import { Response } from 'undici';
|
||||
import { StatusError } from '@/misc/status-error.js';
|
||||
|
||||
const pipeline = util.promisify(stream.pipeline);
|
||||
|
||||
|
|
@ -343,18 +344,18 @@ export class FileInfoService {
|
|||
* Detect MIME Type and extension by stream for performance (this cannot detect SVG)
|
||||
*/
|
||||
@bindThis
|
||||
public async detectRequestType(request: Request): Promise<{
|
||||
public async detectRequestType(_response: Response): Promise<{
|
||||
mime: string;
|
||||
ext: string | null;
|
||||
}> {
|
||||
const response = _response.clone();
|
||||
|
||||
// Check 0 byte
|
||||
if ((request.response?.complete || request.closed) && !request.response?.rawBody?.length) {
|
||||
return TYPE_OCTET_STREAM;
|
||||
if (!response.body) {
|
||||
throw new StatusError('No Body', 400, 'No Body');
|
||||
}
|
||||
|
||||
const copied = request.pipe(new stream.PassThrough());
|
||||
|
||||
const type = await fileTypeFromStream(copied);
|
||||
const type = await fileTypeFromStream(stream.Readable.fromWeb(response.body));
|
||||
|
||||
if (type) {
|
||||
return {
|
||||
|
|
@ -375,7 +376,7 @@ export class FileInfoService {
|
|||
try {
|
||||
const size = await this.getFileSize(path);
|
||||
if (size > 1 * 1024 * 1024) return false;
|
||||
return isSvg(await fs.promises.readFile(target));
|
||||
return isSvg(await fs.promises.readFile(path));
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue