Skip to content

Commit

Permalink
feat: 🎸 同步方案改为chokidar,二次同步速度提升非常大
Browse files Browse the repository at this point in the history
  • Loading branch information
meetqy committed Jul 4, 2023
1 parent 05ec4d6 commit 0ac6a46
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 19 deletions.
33 changes: 19 additions & 14 deletions apps/electron/main/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import "./security-restrictions";
import { join } from "path";

import { appRouter } from "@acme/api";
import { createAssetsServer } from "@acme/assets-server";
import curd from "@acme/curd";

import globalApp from "./global";
Expand Down Expand Up @@ -111,19 +112,6 @@ app
await restoreOrCreateWindow().catch((err) => {
throw err;
});

const libs = await curd.library.get({});
libs.forEach((lib) => {
if (lib.type === "eagle") {
void startWatcher({
libraryId: lib.id,
paths: join(lib.dir, "./images/**/metadata.json"),
options: {
ignoreInitial: true,
},
});
}
});
})
.catch((e) => console.error("Failed create window:", e));

Expand Down Expand Up @@ -164,7 +152,24 @@ app.on("ready", () => {
}),
);

// 创建 Web/Assets 服务
// 创建文件监听
const libs = await curd.library.get({});
libs.forEach((lib) => {
if (lib.type === "eagle") {
void startWatcher({
libraryId: lib.id,
paths: join(lib.dir, "./images/**/metadata.json"),
options: {
ignoreInitial: true,
},
});
}
});

// 创建 Assets 服务
createAssetsServer(Number(process.env["ASSETS_PORT"]), libs);

// 创建 Web 服务
nextjsWebChild = await createWebServer();
if (!nextjsWebChild) {
throw Error("NextJS child process was not created, exiting...");
Expand Down
6 changes: 3 additions & 3 deletions apps/nextjs/src/utils/common.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { type Image } from "@acme/db";

export const getImgUrl = (prefix: string, img: Image, original = false) => {
let imgName = img.noThumbnail ? `${img.name}.${img.ext}` : `${img.name}_thumbnail.png`;
let p = img.thumbnailPath || img.path;

if (original) {
imgName = `${img.name}.${img.ext}`;
p = img.path;
}

return `${prefix}/${img.libraryId}/${img.id}.info/${imgName}`;
return `${prefix}/${img.libraryId}/${p}`;
};

export const transformByteToUnit = (bytes = 0, decimals = 2) => {
Expand Down
2 changes: 1 addition & 1 deletion packages/assets-server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export const createAssetsServer = (port: number, librarys?: Library[]) => {
// Generate app use by library ids
librarys.forEach((lib) => {
if (lib.type === "eagle") {
app.use("/" + lib.id.toString(), express.static(lib.dir + "/images"));
app.use("/" + lib.id.toString() + "/images", express.static(lib.dir + "/images"));
libraryIds.push(lib.id);
}
});
Expand Down
2 changes: 1 addition & 1 deletion packages/support/eagle/src/image.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ const getImageBase = (path: string) => {
const metadata = fs.readJSONSync(path) as Metadata;
const stats = fs.statSync(path);
const imagePath = join("images", `${metadata.id}.info`, `${metadata.name}.${metadata.ext}`);
const thumbnailPath = metadata.noThumbnail ? imagePath : join("images", `${metadata.id}.info`, `${metadata.name}thumbnail.png`);
const thumbnailPath = metadata.noThumbnail ? imagePath : join("images", `${metadata.id}.info`, `${metadata.name}_thumbnail.png`);
const ext = metadata.ext as Constant["ext"];

if (!CONSTANT["EXT"].includes(ext)) {
Expand Down

0 comments on commit 0ac6a46

Please sign in to comment.