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:
Junyi 2025-03-14 22:19:20 +08:00 committed by GitHub
parent 705e167dc4
commit 4b91d890cf
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 19 additions and 9 deletions

View 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');
}

View File

@ -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';

View File

@ -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,