mirror of
https://gitee.com/nocobase/nocobase.git
synced 2025-05-05 05:29:26 +08:00
refactor(utils): move md5 to utils (#6468)
* refactor(utils): move md5 to utils * fix(utils): fix export * fix(utils): add missed file
This commit is contained in:
parent
705e167dc4
commit
4b91d890cf
14
packages/core/utils/src/crypto.ts
Normal file
14
packages/core/utils/src/crypto.ts
Normal file
@ -0,0 +1,14 @@
|
||||
/**
|
||||
* This file is part of the NocoBase (R) project.
|
||||
* Copyright (c) 2020-2024 NocoBase Co., Ltd.
|
||||
* Authors: NocoBase Team.
|
||||
*
|
||||
* This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
|
||||
* For more information, please refer to: https://www.nocobase.com/agreement.
|
||||
*/
|
||||
|
||||
import { createHash } from 'crypto';
|
||||
|
||||
export function md5(input: string) {
|
||||
return createHash('md5').update(input).digest('hex');
|
||||
}
|
@ -8,11 +8,13 @@
|
||||
*/
|
||||
|
||||
import lodash from 'lodash';
|
||||
import { dayjs } from './dayjs';
|
||||
export { lodash };
|
||||
export { dayjs } from './dayjs';
|
||||
|
||||
export * from './assign';
|
||||
export * from './collections-graph';
|
||||
export * from './common';
|
||||
export * from './crypto';
|
||||
export * from './date';
|
||||
export * from './dayjs';
|
||||
export * from './forEach';
|
||||
@ -37,5 +39,4 @@ export * from './url';
|
||||
export * from './i18n';
|
||||
export * from './wrap-middleware';
|
||||
export * from './object-to-cli-args';
|
||||
export { dayjs, lodash };
|
||||
export { Schema } from '@formily/json-schema';
|
||||
|
@ -8,7 +8,7 @@
|
||||
*/
|
||||
|
||||
import { DeleteObjectsCommand } from '@aws-sdk/client-s3';
|
||||
import crypto from 'crypto';
|
||||
import { md5 } from '@nocobase/utils';
|
||||
import { AttachmentModel, StorageType } from '.';
|
||||
import { STORAGE_TYPE_S3 } from '../../constants';
|
||||
import { cloudFilenameGetter, getFileKey } from '../utils';
|
||||
@ -64,17 +64,12 @@ export default class extends StorageType {
|
||||
});
|
||||
}
|
||||
|
||||
calculateContentMD5(body) {
|
||||
const hash = crypto.createHash('md5').update(body).digest('base64');
|
||||
return hash;
|
||||
}
|
||||
|
||||
async deleteS3Objects(bucketName: string, objects: string[]) {
|
||||
const deleteBody = JSON.stringify({
|
||||
Objects: objects.map((objectKey) => ({ Key: objectKey })),
|
||||
});
|
||||
|
||||
const contentMD5 = this.calculateContentMD5(deleteBody);
|
||||
const contentMD5 = md5(deleteBody);
|
||||
|
||||
const deleteCommand = new DeleteObjectsCommand({
|
||||
Bucket: bucketName,
|
||||
|
Loading…
x
Reference in New Issue
Block a user