Skip to content

Commit

Permalink
fix: 🐛 关闭软件之后,再次开启无法同步
Browse files Browse the repository at this point in the history
Closes: #299
  • Loading branch information
meetqy committed Jul 7, 2023
1 parent e5a04f6 commit 42bf4b4
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
22 changes: 19 additions & 3 deletions apps/electron/main/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import startWatcher from "@acme/watch";

import "./security-restrictions";
import { join } from "path";
import fg from "fast-glob";

import { appRouter } from "@acme/api";
import curd from "@acme/curd";
Expand Down Expand Up @@ -161,17 +162,32 @@ app
void (async () => {
// 创建文件监听
const libs = await curd.library.get({});
libs.forEach((lib) => {

for (const lib of libs) {
if (lib.type === "eagle") {
const paths = join(lib.dir, "images", "**", "metadata.json").replace(/\\/g, "/");
const entries = fg.sync(paths);

const exitsImages = await curd.image.get({ libraryId: lib.id });
const exitsImagesPaths = exitsImages.map((item) => item.path);

entries.forEach((entry) => {
if (!exitsImagesPaths.includes(entry)) {
void curd.pending.upsert({ libraryId: lib.id, path: entry, type: "update" });
} else {
void curd.pending.upsert({ libraryId: lib.id, path: entry, type: "create" });
}
});

void startWatcher({
libraryId: lib.id,
paths: join(lib.dir, "./images/**/metadata.json"),
paths,
options: {
ignoreInitial: true,
},
});
}
});
}

// Init config assign to process.env
await getAndUpdateConfig();
Expand Down
5 changes: 5 additions & 0 deletions packages/curd/src/image.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ export const ImageInput = {
get: z.object({
id: z.union([z.number(), z.array(z.number())]).optional(),
path: z.string().optional(),
libraryId: z.number().optional(),
}),
};

Expand All @@ -87,6 +88,10 @@ export const Image = {
};
}

if (input.libraryId) {
where.libraryId = input.libraryId;
}

if (path) {
where.path = path;
}
Expand Down

0 comments on commit 42bf4b4

Please sign in to comment.