fix: #148 fix non-mime problem when get file from minio

infer mime with extname
pull/150/head
moonrailgun 2 years ago
parent c4d3d8c3fa
commit 98e81fa9b7

@ -508,7 +508,6 @@ class MessageService extends TcService {
if (groupId) {
// 是群组
const group = await call(ctx).getGroupInfo(groupId);
console.log('group.members', group.members, group);
if (group.members.findIndex((m) => String(m.userId) === userId) === -1) {
// 不存在该用户
throw new NoPermissionError(t('没有当前会话权限'));

@ -10,7 +10,7 @@ import {
} from 'tailchat-server-sdk';
import _ from 'lodash';
import mime from 'mime';
import type { Client as MinioClient } from 'minio';
import type { BucketItemStat, Client as MinioClient } from 'minio';
import { isValidStaticAssetsUrl, isValidStr } from '../../lib/utils';
import path from 'node:path';
import type { FileDocument, FileModel } from '../../models/file';
@ -59,6 +59,12 @@ class FileService extends TcService {
},
disableSocket: true,
});
this.registerAction('stat', this.stat, {
params: {
objectName: 'string',
},
disableSocket: true,
});
this.registerAction('delete', this.delete, {
params: {
objectName: 'string',
@ -322,6 +328,21 @@ class FileService extends TcService {
return stream;
}
/**
*
*/
async stat(
ctx: PureContext<{
objectName: string;
}>
): Promise<BucketItemStat> {
const objectName = ctx.params.objectName;
const stat = await this.minioClient.statObject(this.bucketName, objectName);
return stat;
}
/**
*
*/

@ -18,6 +18,8 @@ import { checkPathMatch } from '../../lib/utils';
import serve from 'serve-static';
import accepts from 'accepts';
import send from 'send';
import path from 'path';
import mime from 'mime';
export default class ApiService extends TcService {
authWhitelist = [];
@ -289,6 +291,12 @@ export default class ApiService extends TcService {
parentCtx: _.get(req, '$ctx'),
}
);
const ext = path.extname(objectName);
if (ext) {
res.setHeader('Content-Type', mime.getType(ext));
}
result.pipe(res);
} catch (err) {
this.logger.error(err);

Loading…
Cancel
Save