-
Notifications
You must be signed in to change notification settings - Fork 801
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add html5 courseware uploading (#1023)
* refactor(flat-components): add h5 courseware icons * feat(desktop): add ice courseware upload * feat(web): add ice courseware upload * refactor(web): translate html5 courseware src * refactor(desktop): translate html5 courseware src * refactor(web): update query h5 error code
- Loading branch information
Showing
19 changed files
with
519 additions
and
98 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import Axios from "axios"; | ||
import { ServerRequestError } from "../utils/error/server-request-error"; | ||
|
||
export type H5ConvertingStatusType = "Converting" | "Finished" | "Failed"; | ||
|
||
export type H5ConvertingStatusResultNormal = { | ||
status: Exclude<H5ConvertingStatusType, "Failed">; | ||
error?: undefined; | ||
}; | ||
|
||
export type H5ConvertingStatusResultFailed = { | ||
status: "Failed"; | ||
error: Error; | ||
}; | ||
|
||
export type H5ConvertingStatusResult = | ||
| H5ConvertingStatusResultNormal | ||
| H5ConvertingStatusResultFailed; | ||
|
||
export async function queryH5ConvertingStatus(fileURL: string): Promise<H5ConvertingStatusResult> { | ||
try { | ||
const response = await Axios.head(fileURL.replace(/[^/]+$/, "") + "result"); | ||
if (response.headers["x-oss-meta-success"] !== "true") { | ||
const errorCode = Number(response.headers["x-oss-meta-error-code"]); | ||
if (errorCode > 0) { | ||
return { | ||
status: "Failed", | ||
error: new ServerRequestError(errorCode), | ||
}; | ||
} | ||
if (response.status >= 200 && response.status < 500) { | ||
return { status: "Converting" }; | ||
} | ||
return { status: "Failed", error: new Error(response.statusText) }; | ||
} | ||
return { status: "Finished" }; | ||
} catch (e) { | ||
console.warn(e); | ||
return { status: "Converting" }; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
desktop/renderer-app/src/pages/CloudStoragePage/ConvertStatusManager.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import { FileUUID } from "flat-components"; | ||
|
||
/** | ||
* @returns true: keep polling, false: stop | ||
*/ | ||
export type ConvertTask = () => Promise<boolean>; | ||
|
||
export class ConvertStatusManager { | ||
private tasks = new Map<FileUUID, { ticket: number; executor: ConvertTask }>(); | ||
|
||
public hasTask(fileUUID: FileUUID): boolean { | ||
return this.tasks.has(fileUUID); | ||
} | ||
|
||
public async addTask( | ||
fileUUID: FileUUID, | ||
executor: ConvertTask, | ||
interval = 1500, | ||
): Promise<void> { | ||
const task = this.tasks.get(fileUUID); | ||
if (task) { | ||
task.executor = executor; | ||
} else if (!(await executor())) { | ||
const ticket = window.setInterval(async () => { | ||
const task = this.tasks.get(fileUUID); | ||
if (!task) { | ||
window.clearInterval(ticket); | ||
} else if (await task.executor()) { | ||
this.cancelTask(fileUUID); | ||
} | ||
}, interval); | ||
this.tasks.set(fileUUID, { executor, ticket }); | ||
} | ||
} | ||
|
||
public cancelTask(fileUUID: FileUUID): void { | ||
const task = this.tasks.get(fileUUID); | ||
if (task) { | ||
window.clearInterval(task.ticket); | ||
this.tasks.delete(fileUUID); | ||
} | ||
} | ||
|
||
public cancelAllTasks(): void { | ||
this.tasks.forEach(task => { | ||
window.clearInterval(task.ticket); | ||
}); | ||
this.tasks.clear(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.