Skip to content

Commit

Permalink
refactor(flat-server-api): convert static resources by projector
Browse files Browse the repository at this point in the history
  • Loading branch information
hyrious committed Mar 13, 2024
1 parent da1202b commit 30d6440
Show file tree
Hide file tree
Showing 28 changed files with 134 additions and 478 deletions.
1 change: 1 addition & 0 deletions desktop/main-app/src/window-manager/window-main/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ export class WindowMain extends AbstractWindow<false> {
);
}

// @ts-ignore Don't load react extension which is annoying in debugging
private static loadExtensions(win: CustomWindow, extensionName: "react-devtools"): void {
const { REACT_DEVELOPER_TOOLS } = require("electron-devtools-vendor");

Expand Down
2 changes: 1 addition & 1 deletion desktop/renderer-app/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"extends": "../../tsconfig.base.json",
"compilerOptions": {
"lib": ["dom", "es2017"],
"lib": ["DOM", "ES2017", "DOM.Iterable"],
"module": "ESNext",
"jsx": "react",
"types": ["vite/client"]
Expand Down
6 changes: 6 additions & 0 deletions desktop/renderer-app/typings/global.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,20 @@ declare module "*.mp3";
declare namespace NodeJS {
interface ProcessEnv {
NODE_ENV: "development" | "production";
DEV: boolean;
PROD: boolean;
VERSION: string;

FLAT_SERVER_DOMAIN: string;
FLAT_WEB_DOMAIN: string;

FLAT_DOWNLOAD_URL: string;
FEEDBACK_URL: string;

CLOUD_RECORDING_DEFAULT_AVATAR?: string;

FLAT_REGION: "CN" | "SG";
LOGIN_METHODS: string;
}
}

Expand Down Expand Up @@ -61,4 +66,5 @@ interface Window {
basename: (p: string, ext?: string | undefined) => string;
};
};
isElectron?: boolean;
}
22 changes: 20 additions & 2 deletions packages/flat-pages/src/ResourcePreviewPage/StaticPreview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@ import { Region } from "flat-components";
import React, { useEffect, useState } from "react";
import { queryConvertingTaskStatus } from "@netless/flat-stores";
import { useSafePromise } from "../utils/hooks/lifecycle";
import { ConvertingTaskStatus } from "@netless/flat-server-api";

export interface StaticPreviewProps {
taskUUID: string;
taskToken: string;
region: Region;
projector: boolean;
}

type ConvertedFileList =
Expand All @@ -21,10 +23,22 @@ type ConvertedFileList =
}>
| undefined;

const mapImagesToConvertedFileList = (convert: ConvertingTaskStatus): ConvertedFileList => {
const images = convert.images || {};
const previews = convert.previews || {};
const result: NonNullable<ConvertedFileList> = [];
for (const page in images) {
const { width, height, url } = images[page];
result.push({ width, height, conversionFileUrl: url, preview: previews[page] });
}
return result;
};

export const StaticPreview = observer<StaticPreviewProps>(function DocumentPreview({
taskUUID,
taskToken,
region,
projector,
}) {
const [convertList, setConvertList] = useState<ConvertedFileList>([]);
const sp = useSafePromise();
Expand All @@ -37,11 +51,15 @@ export const StaticPreview = observer<StaticPreviewProps>(function DocumentPrevi
taskToken,
dynamic: false,
region,
projector: false,
projector,
}),
);

setConvertList(convertResult.progress?.convertedFileList);
if (convertResult.images) {
setConvertList(mapImagesToConvertedFileList(convertResult));
} else if (convertResult.progress) {
setConvertList(convertResult.progress.convertedFileList);
}
}

getStaticResource().catch(console.warn);
Expand Down
1 change: 1 addition & 0 deletions packages/flat-pages/src/ResourcePreviewPage/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ export const ResourcePreviewPage = observer<ResourcePreviewPagePageProps>(
if (taskUUID && taskToken) {
return (
<StaticPreview
projector={projector === "projector"}
region={region as Region}
taskToken={taskToken}
taskUUID={taskUUID}
Expand Down
35 changes: 35 additions & 0 deletions packages/flat-server-api/src/storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -228,3 +228,38 @@ export async function uploadTempPhotoFinish(fileUUID: string): Promise<void> {
fileUUID,
});
}

export interface ConvertingTaskStatus {
uuid: string;
type: "static" | "dynamic";
status: "Waiting" | "Converting" | "Finished" | "Fail" | "Abort";
errorCode?: string;
errorMessage?: string;
convertedPercentage?: number;
prefix?: string;
pageCount?: number;
previews?: { [page: number]: string };
note?: string;
images?: { [page: number]: { width: number; height: number; url: string } };
/** @deprecated This field is for compatible with legacy static convert. New resources should use `images` above. */
progress?: ConvertingTaskStatusLegacy["progress"];
}

export interface ConvertingTaskStatusLegacy {
uuid: string;
type: "static" | "dynamic";
status: "Waiting" | "Converting" | "Finished" | "Fail" | "Abort";
failedReason?: string;
progress?: {
totalPageSize: number;
convertedPageSize: number;
convertedPercentage: number;
convertedFileList: Array<{
width: number;
height: number;
conversionFileUrl: string;
preview?: string;
}>;
currentStep: "Extracting" | "Packaging" | "GeneratingPreview" | "MediaTranscode";
};
}
10 changes: 5 additions & 5 deletions packages/flat-services/src/providers/provider-file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,11 @@ export class FlatServiceProviderFile implements IServiceFile {
try {
if (file.resourceType === FileResourceType.NormalResources) {
await insertService.insert(file);
}
const convertStatus = await this.checkConvertStatus(file, ext);

if (convertStatus === FileConvertStep.Done) {
await insertService.insert(file);
} else {
const convertStatus = await this.checkConvertStatus(file, ext);
if (convertStatus === FileConvertStep.Done) {
await insertService.insert(file);
}
}
} catch (e) {
this.toaster.emit("error", this.flatI18n.t("unable-to-insert-courseware"));
Expand Down
1 change: 1 addition & 0 deletions packages/flat-stores/src/global.d.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
interface Window {
__netlessUA?: string;
isElectron?: boolean;
}
32 changes: 1 addition & 31 deletions packages/flat-stores/src/utils/courseware-converting.ts
Original file line number Diff line number Diff line change
@@ -1,36 +1,6 @@
import Axios from "axios";
import { Region } from "flat-components";

export interface ConvertingTaskStatus {
uuid: string;
type: "static" | "dynamic";
status: "Waiting" | "Converting" | "Finished" | "Fail" | "Abort";
errorCode?: string;
errorMessage?: string;
convertedPercentage?: number;
prefix?: string;
// TODO: `progress` is for static resources and will be changed in the future.
progress?: ConvertingTaskStatusLegacy["progress"];
}

export interface ConvertingTaskStatusLegacy {
uuid: string;
type: "static" | "dynamic";
status: "Waiting" | "Converting" | "Finished" | "Fail" | "Abort";
failedReason?: string;
progress?: {
totalPageSize: number;
convertedPageSize: number;
convertedPercentage: number;
convertedFileList: Array<{
width: number;
height: number;
conversionFileUrl: string;
preview?: string;
}>;
currentStep: "Extracting" | "Packaging" | "GeneratingPreview" | "MediaTranscode";
};
}
import { ConvertingTaskStatus, ConvertingTaskStatusLegacy } from "@netless/flat-server-api";

export interface QueryConvertingParams {
taskUUID: string;
Expand Down
2 changes: 0 additions & 2 deletions packages/flat-stores/src/utils/file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,3 @@
*/
export const getFileExt = (fileName: string): string =>
(/\.([^.]+)$/.exec(fileName) || ["", ""])[1].toLowerCase();

export const isPPTX = (fileName: string): boolean => /\.pptx$/i.test(fileName);
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import {
isServerRequestError,
} from "@netless/flat-server-api";
import { errorTips } from "flat-components";
import { isPPTX } from "../file";
import { globalStore } from "../../global-store";

export enum UploadStatusType {
Expand Down Expand Up @@ -143,10 +142,7 @@ export class UploadTask {
public async finish(): Promise<void> {
if (this.fileUUID) {
try {
await uploadFinish({
fileUUID: this.fileUUID,
isWhiteboardProjector: isPPTX(this.file.name),
});
await uploadFinish({ fileUUID: this.fileUUID });
} catch (e) {
console.error(e);
}
Expand Down

This file was deleted.

19 changes: 0 additions & 19 deletions service-providers/courseware/flat-courseware-netless/package.json

This file was deleted.

This file was deleted.

Loading

0 comments on commit 30d6440

Please sign in to comment.