feat: 添加一些assert

This commit is contained in:
Pan Qiancheng 2026-01-15 12:05:47 +08:00
parent 9027a40479
commit cf63a53109
9 changed files with 35 additions and 12 deletions

View File

@ -151,6 +151,7 @@ export default class ALiYunBackend extends ALiYun {
const { instance, config: aliyunCosConfig } = this.getConfigAndInstance(application); const { instance, config: aliyunCosConfig } = this.getConfigAndInstance(application);
const b = aliyunCosConfig.buckets.find((ele) => ele.name === extraFile.bucket); const b = aliyunCosConfig.buckets.find((ele) => ele.name === extraFile.bucket);
assert(b, `extraFile中的bucket名称在阿里云配置中找不到「${extraFile.bucket}`); assert(b, `extraFile中的bucket名称在阿里云配置中找不到「${extraFile.bucket}`);
assert(extraFile.chunkInfo?.uploadId, 'extraFile缺少chunkInfo.uploadId无法中止分片上传操作');
await instance.abortMultipartUpload(extraFile.bucket, b.zone, key, extraFile.chunkInfo.uploadId); await instance.abortMultipartUpload(extraFile.bucket, b.zone, key, extraFile.chunkInfo.uploadId);
} }
async listMultipartUploads(application, extraFile, context) { async listMultipartUploads(application, extraFile, context) {
@ -158,6 +159,7 @@ export default class ALiYunBackend extends ALiYun {
const { instance, config: aliyunCosConfig } = this.getConfigAndInstance(application); const { instance, config: aliyunCosConfig } = this.getConfigAndInstance(application);
const b = aliyunCosConfig.buckets.find((ele) => ele.name === extraFile.bucket); const b = aliyunCosConfig.buckets.find((ele) => ele.name === extraFile.bucket);
assert(b, `extraFile中的bucket名称在阿里云配置中找不到「${extraFile.bucket}`); assert(b, `extraFile中的bucket名称在阿里云配置中找不到「${extraFile.bucket}`);
assert(extraFile.chunkInfo?.uploadId, 'extraFile缺少chunkInfo.uploadId无法列出分片上传信息');
return await instance.listParts(extraFile.bucket, b.zone, key, extraFile.chunkInfo.uploadId); return await instance.listParts(extraFile.bucket, b.zone, key, extraFile.chunkInfo.uploadId);
} }
async presignFile(methods, application, extraFile, context) { async presignFile(methods, application, extraFile, context) {

View File

@ -134,13 +134,15 @@ export default class S3Backend extends S3 {
async abortMultipartUpload(application, extraFile, context) { async abortMultipartUpload(application, extraFile, context) {
const key = this.formKey(extraFile); const key = this.formKey(extraFile);
const { instance, config: s3CosConfig } = this.getConfigAndInstance(application, extraFile.bucket); const { instance, config: s3CosConfig } = this.getConfigAndInstance(application, extraFile.bucket);
assert(extraFile.chunkInfo?.uploadId, 'extraFile缺少chunkInfo.uploadId无法中止分片上传操作');
await instance.abortMultipartUpload(extraFile.bucket, key, extraFile.chunkInfo.uploadId, s3CosConfig.endpoint); await instance.abortMultipartUpload(extraFile.bucket, key, extraFile.chunkInfo.uploadId, s3CosConfig.endpoint);
} }
async listMultipartUploads(application, extraFile, context) { async listMultipartUploads(application, extraFile, context) {
const key = this.formKey(extraFile); const key = this.formKey(extraFile);
const { instance, config: s3CosConfig } = this.getConfigAndInstance(application, extraFile.bucket); const { instance, config: s3CosConfig } = this.getConfigAndInstance(application, extraFile.bucket);
const result = await instance.listParts(extraFile.bucket, key, extraFile.chunkInfo.uploadId, s3CosConfig.endpoint, 101); const result = await instance.listParts(extraFile.bucket, key, extraFile.chunkInfo.uploadId, s3CosConfig.endpoint, 1001);
assert(result.isTruncated === false, `分片数量超过101无法列出所有分片信息不应当出现这个情况触发器中已经限制了最大分片数量为100`); assert(result.isTruncated === false, `分片数量超过1001无法列出所有分片信息不应当出现这个情况触发器中已经限制了最大分片数量为100`);
assert(extraFile.chunkInfo?.uploadId, 'extraFile缺少chunkInfo.uploadId无法列出分片上传信息');
return { return {
parts: result.parts.map((part) => ({ parts: result.parts.map((part) => ({
partNumber: part.partNumber, partNumber: part.partNumber,

View File

@ -154,6 +154,7 @@ class ALiYunBackend extends aliyun_1.default {
const { instance, config: aliyunCosConfig } = this.getConfigAndInstance(application); const { instance, config: aliyunCosConfig } = this.getConfigAndInstance(application);
const b = aliyunCosConfig.buckets.find((ele) => ele.name === extraFile.bucket); const b = aliyunCosConfig.buckets.find((ele) => ele.name === extraFile.bucket);
(0, assert_1.assert)(b, `extraFile中的bucket名称在阿里云配置中找不到「${extraFile.bucket}`); (0, assert_1.assert)(b, `extraFile中的bucket名称在阿里云配置中找不到「${extraFile.bucket}`);
(0, assert_1.assert)(extraFile.chunkInfo?.uploadId, 'extraFile缺少chunkInfo.uploadId无法中止分片上传操作');
await instance.abortMultipartUpload(extraFile.bucket, b.zone, key, extraFile.chunkInfo.uploadId); await instance.abortMultipartUpload(extraFile.bucket, b.zone, key, extraFile.chunkInfo.uploadId);
} }
async listMultipartUploads(application, extraFile, context) { async listMultipartUploads(application, extraFile, context) {
@ -161,6 +162,7 @@ class ALiYunBackend extends aliyun_1.default {
const { instance, config: aliyunCosConfig } = this.getConfigAndInstance(application); const { instance, config: aliyunCosConfig } = this.getConfigAndInstance(application);
const b = aliyunCosConfig.buckets.find((ele) => ele.name === extraFile.bucket); const b = aliyunCosConfig.buckets.find((ele) => ele.name === extraFile.bucket);
(0, assert_1.assert)(b, `extraFile中的bucket名称在阿里云配置中找不到「${extraFile.bucket}`); (0, assert_1.assert)(b, `extraFile中的bucket名称在阿里云配置中找不到「${extraFile.bucket}`);
(0, assert_1.assert)(extraFile.chunkInfo?.uploadId, 'extraFile缺少chunkInfo.uploadId无法列出分片上传信息');
return await instance.listParts(extraFile.bucket, b.zone, key, extraFile.chunkInfo.uploadId); return await instance.listParts(extraFile.bucket, b.zone, key, extraFile.chunkInfo.uploadId);
} }
async presignFile(methods, application, extraFile, context) { async presignFile(methods, application, extraFile, context) {

View File

@ -117,8 +117,8 @@ class S3Backend extends s3_1.default {
}; };
} }
/** /**
* 完成分片上传后的合并操作 * 完成分片上传后的合并操作
*/ */
async mergeChunkedUpload(application, extraFile, parts, context) { async mergeChunkedUpload(application, extraFile, parts, context) {
const key = this.formKey(extraFile); const key = this.formKey(extraFile);
const { instance, config: s3CosConfig } = this.getConfigAndInstance(application, extraFile.bucket); const { instance, config: s3CosConfig } = this.getConfigAndInstance(application, extraFile.bucket);
@ -137,13 +137,15 @@ class S3Backend extends s3_1.default {
async abortMultipartUpload(application, extraFile, context) { async abortMultipartUpload(application, extraFile, context) {
const key = this.formKey(extraFile); const key = this.formKey(extraFile);
const { instance, config: s3CosConfig } = this.getConfigAndInstance(application, extraFile.bucket); const { instance, config: s3CosConfig } = this.getConfigAndInstance(application, extraFile.bucket);
(0, assert_1.assert)(extraFile.chunkInfo?.uploadId, 'extraFile缺少chunkInfo.uploadId无法中止分片上传操作');
await instance.abortMultipartUpload(extraFile.bucket, key, extraFile.chunkInfo.uploadId, s3CosConfig.endpoint); await instance.abortMultipartUpload(extraFile.bucket, key, extraFile.chunkInfo.uploadId, s3CosConfig.endpoint);
} }
async listMultipartUploads(application, extraFile, context) { async listMultipartUploads(application, extraFile, context) {
const key = this.formKey(extraFile); const key = this.formKey(extraFile);
const { instance, config: s3CosConfig } = this.getConfigAndInstance(application, extraFile.bucket); const { instance, config: s3CosConfig } = this.getConfigAndInstance(application, extraFile.bucket);
const result = await instance.listParts(extraFile.bucket, key, extraFile.chunkInfo.uploadId, s3CosConfig.endpoint, 101); const result = await instance.listParts(extraFile.bucket, key, extraFile.chunkInfo.uploadId, s3CosConfig.endpoint, 1001);
(0, assert_1.assert)(result.isTruncated === false, `分片数量超过101无法列出所有分片信息不应当出现这个情况触发器中已经限制了最大分片数量为100`); (0, assert_1.assert)(result.isTruncated === false, `分片数量超过1001无法列出所有分片信息不应当出现这个情况触发器中已经限制了最大分片数量为100`);
(0, assert_1.assert)(extraFile.chunkInfo?.uploadId, 'extraFile缺少chunkInfo.uploadId无法列出分片上传信息');
return { return {
parts: result.parts.map((part) => ({ parts: result.parts.map((part) => ({
partNumber: part.partNumber, partNumber: part.partNumber,

View File

@ -21,7 +21,6 @@
"classnames": "^2.3.1", "classnames": "^2.3.1",
"compressorjs": "^1.2.1", "compressorjs": "^1.2.1",
"copy-to-clipboard": "^3.3.3", "copy-to-clipboard": "^3.3.3",
"csstype": "^3.1.3",
"dayjs": "^1.11.9", "dayjs": "^1.11.9",
"nodemailer": "^6.9.14", "nodemailer": "^6.9.14",
"oak-common-aspect": "file:../oak-common-aspect", "oak-common-aspect": "file:../oak-common-aspect",

View File

@ -268,6 +268,8 @@ export default class ALiYunBackend
`extraFile中的bucket名称在阿里云配置中找不到「${extraFile.bucket}` `extraFile中的bucket名称在阿里云配置中找不到「${extraFile.bucket}`
); );
assert(extraFile.chunkInfo?.uploadId, 'extraFile缺少chunkInfo.uploadId无法中止分片上传操作');
await instance.abortMultipartUpload( await instance.abortMultipartUpload(
extraFile.bucket!, extraFile.bucket!,
b.zone, b.zone,
@ -298,6 +300,9 @@ export default class ALiYunBackend
b, b,
`extraFile中的bucket名称在阿里云配置中找不到「${extraFile.bucket}` `extraFile中的bucket名称在阿里云配置中找不到「${extraFile.bucket}`
); );
assert(extraFile.chunkInfo?.uploadId, 'extraFile缺少chunkInfo.uploadId无法列出分片上传信息');
return await instance.listParts( return await instance.listParts(
extraFile.bucket!, extraFile.bucket!,
b.zone, b.zone,

View File

@ -250,10 +250,12 @@ export default class S3Backend extends S3 implements CosBackend<EntityDict> {
const { instance, config: s3CosConfig } = const { instance, config: s3CosConfig } =
this.getConfigAndInstance(application, extraFile.bucket!); this.getConfigAndInstance(application, extraFile.bucket!);
assert(extraFile.chunkInfo?.uploadId, 'extraFile缺少chunkInfo.uploadId无法中止分片上传操作');
await instance.abortMultipartUpload( await instance.abortMultipartUpload(
extraFile.bucket!, extraFile.bucket!,
key, key,
extraFile.chunkInfo!.uploadId!, extraFile.chunkInfo!.uploadId,
s3CosConfig.endpoint! s3CosConfig.endpoint!
); );
} }
@ -279,14 +281,16 @@ export default class S3Backend extends S3 implements CosBackend<EntityDict> {
key, key,
extraFile.chunkInfo!.uploadId!, extraFile.chunkInfo!.uploadId!,
s3CosConfig.endpoint!, s3CosConfig.endpoint!,
101, 1001,
); );
assert( assert(
result.isTruncated === false, result.isTruncated === false,
`分片数量超过101无法列出所有分片信息不应当出现这个情况触发器中已经限制了最大分片数量为100` `分片数量超过1001无法列出所有分片信息不应当出现这个情况触发器中已经限制了最大分片数量为100`
); );
assert(extraFile.chunkInfo?.uploadId, 'extraFile缺少chunkInfo.uploadId无法列出分片上传信息');
return { return {
parts: result.parts.map((part) => ({ parts: result.parts.map((part) => ({
partNumber: part.partNumber, partNumber: part.partNumber,

View File

@ -2,7 +2,8 @@
"compilerOptions": { "compilerOptions": {
"jsx": "react-native", "jsx": "react-native",
/* Basic Options */ /* Basic Options */
// "incremental": true, /* Enable incremental compilation */ "incremental": true, /* Enable incremental compilation */
"tsBuildInfoFile": ".tsbuildinfo",
"target": "ESNext", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019' or 'ESNEXT'. */ "target": "ESNext", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019' or 'ESNEXT'. */
"module": "ESNext", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */ "module": "ESNext", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */
"lib": [ "lib": [
@ -90,6 +91,11 @@
"test", "test",
"scripts" "scripts"
], ],
//
"paths": {
"react": ["./node_modules/@types/react"],
"csstype": ["./node_modules/csstype"]
},
"oakBuildChecks": { "oakBuildChecks": {
"context": { "context": {
"checkAsyncContext": false "checkAsyncContext": false

View File

@ -2,7 +2,8 @@
"compilerOptions": { "compilerOptions": {
"jsx": "react-jsx", "jsx": "react-jsx",
/* Basic Options */ /* Basic Options */
// "incremental": true, /* Enable incremental compilation */ "incremental": true, /* Enable incremental compilation */
"tsBuildInfoFile": ".tsbuildinfo",
"target": "esnext", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019' or 'ESNEXT'. */ "target": "esnext", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019' or 'ESNEXT'. */
"module": "commonjs", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */ "module": "commonjs", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */
"lib": [ "lib": [