Skip to content

Commit

Permalink
fix(region): policy url incorrect (#803)
Browse files Browse the repository at this point in the history
* fix(region): policy url incorrect

* refactor(api): move region params from alibab-cloud/upload/start to finish
  • Loading branch information
BlackHole1 committed Jul 21, 2021
1 parent 8f7ed14 commit da02f73
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 26 deletions.
3 changes: 2 additions & 1 deletion desktop/renderer-app/src/apiMiddleware/flatServer/storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,14 @@ export async function listFiles(payload: ListFilesPayload): Promise<ListFilesRes
export interface UploadStartPayload {
fileName: string;
fileSize: number;
region: Region;
}

export interface UploadStartResult {
fileUUID: string;
filePath: string;
policy: string;
policyURL: string;
signature: string;
}

Expand All @@ -58,7 +60,6 @@ export async function uploadStart(payload: UploadStartPayload): Promise<UploadSt
}
interface UploadFinishPayload {
fileUUID: string;
region: Region;
}

export async function uploadFinish(payload: UploadFinishPayload): Promise<void> {
Expand Down
26 changes: 14 additions & 12 deletions desktop/renderer-app/src/utils/UploadTaskManager/UploadTask.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ export class UploadTask {
uploadStartResult = await uploadStart({
fileName,
fileSize,
region: configStore.getRegion(),
});
} catch (e) {
// max concurrent upload count limit
Expand All @@ -71,13 +72,14 @@ export class UploadTask {
uploadStartResult = await uploadStart({
fileName,
fileSize,
region: configStore.getRegion(),
});
} else {
throw e;
}
}

const { filePath, fileUUID, policy, signature } = uploadStartResult;
const { filePath, fileUUID, policy, policyURL, signature } = uploadStartResult;

if (this.getStatus() !== UploadStatusType.Starting) {
return;
Expand All @@ -104,17 +106,15 @@ export class UploadTask {

this.updateStatus(UploadStatusType.Uploading);

await Axios.post(
`https://${CLOUD_STORAGE_OSS_ALIBABA_CONFIG.bucket}.${CLOUD_STORAGE_OSS_ALIBABA_CONFIG.region}.aliyuncs.com`,
formData,
{
headers: { "Content-Type": "multipart/form-data" },
onUploadProgress: (e: ProgressEvent) => {
this.updatePercent(Math.floor((100 * e.loaded) / e.total));
},
cancelToken: this._cancelTokenSource.token,
await Axios.post(policyURL, formData, {
headers: {
"Content-Type": "multipart/form-data",
},
);
onUploadProgress: (e: ProgressEvent) => {
this.updatePercent(Math.floor((100 * e.loaded) / e.total));
},
cancelToken: this._cancelTokenSource.token,
});
} catch (e) {
if (e instanceof Axios.Cancel) {
this.updateStatus(UploadStatusType.Cancelled);
Expand Down Expand Up @@ -142,7 +142,9 @@ export class UploadTask {
public async finish(): Promise<void> {
if (this.fileUUID) {
try {
await uploadFinish({ fileUUID: this.fileUUID, region: configStore.getRegion() });
await uploadFinish({
fileUUID: this.fileUUID,
});
} catch (e) {
console.error(e);
}
Expand Down
3 changes: 2 additions & 1 deletion web/flat-web/src/apiMiddleware/flatServer/storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,14 @@ export async function listFiles(payload: ListFilesPayload): Promise<ListFilesRes
export interface UploadStartPayload {
fileName: string;
fileSize: number;
region: Region;
}

export interface UploadStartResult {
fileUUID: string;
filePath: string;
policy: string;
policyURL: string;
signature: string;
}

Expand All @@ -58,7 +60,6 @@ export async function uploadStart(payload: UploadStartPayload): Promise<UploadSt
}
interface UploadFinishPayload {
fileUUID: string;
region: Region;
}

export async function uploadFinish(payload: UploadFinishPayload): Promise<void> {
Expand Down
23 changes: 11 additions & 12 deletions web/flat-web/src/utils/UploadTaskManager/UploadTask.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ export class UploadTask {
uploadStartResult = await uploadStart({
fileName,
fileSize,
region: configStore.getRegion(),
});
} catch (e) {
// max concurrent upload count limit
Expand All @@ -71,13 +72,14 @@ export class UploadTask {
uploadStartResult = await uploadStart({
fileName,
fileSize,
region: configStore.getRegion(),
});
} else {
throw e;
}
}

const { filePath, fileUUID, policy, signature } = uploadStartResult;
const { filePath, fileUUID, policy, policyURL, signature } = uploadStartResult;

if (this.getStatus() !== UploadStatusType.Starting) {
return;
Expand All @@ -104,17 +106,15 @@ export class UploadTask {

this.updateStatus(UploadStatusType.Uploading);

await Axios.post(
`https://${CLOUD_STORAGE_OSS_ALIBABA_CONFIG.bucket}.${CLOUD_STORAGE_OSS_ALIBABA_CONFIG.region}.aliyuncs.com`,
formData,
{
headers: { "Content-Type": "multipart/form-data" },
onUploadProgress: (e: ProgressEvent) => {
this.updatePercent(Math.floor((100 * e.loaded) / e.total));
},
cancelToken: this._cancelTokenSource.token,
await Axios.post(policyURL, formData, {
headers: {
"Content-Type": "multipart/form-data",
},
);
onUploadProgress: (e: ProgressEvent) => {
this.updatePercent(Math.floor((100 * e.loaded) / e.total));
},
cancelToken: this._cancelTokenSource.token,
});
} catch (e) {
if (e instanceof Axios.Cancel) {
this.updateStatus(UploadStatusType.Cancelled);
Expand Down Expand Up @@ -144,7 +144,6 @@ export class UploadTask {
try {
await uploadFinish({
fileUUID: this.fileUUID,
region: configStore.getRegion(),
});
} catch (e) {
console.error(e);
Expand Down

0 comments on commit da02f73

Please sign in to comment.