markpdfdown 0.1.0 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/main/index.js +77 -27
- package/package.json +1 -1
package/dist/main/index.js
CHANGED
|
@@ -4,6 +4,7 @@ import fs, { promises } from "fs";
|
|
|
4
4
|
import isDev from "electron-is-dev";
|
|
5
5
|
import { randomUUID } from "crypto";
|
|
6
6
|
import pkg from "@prisma/client";
|
|
7
|
+
import { fileURLToPath } from "url";
|
|
7
8
|
import { EventEmitter } from "events";
|
|
8
9
|
import { pdfToPng } from "pdf-to-png-converter";
|
|
9
10
|
import { PDFDocument } from "pdf-lib";
|
|
@@ -25,10 +26,23 @@ const getMigrationsDir = () => {
|
|
|
25
26
|
"migrations"
|
|
26
27
|
);
|
|
27
28
|
}
|
|
28
|
-
if (app) {
|
|
29
|
+
if (app.isPackaged) {
|
|
29
30
|
return path.join(app.getAppPath(), "..", "migrations");
|
|
30
31
|
}
|
|
31
|
-
|
|
32
|
+
const currentDir = typeof __dirname !== "undefined" ? __dirname : path.dirname(fileURLToPath(import.meta.url));
|
|
33
|
+
const projectRoot = path.resolve(currentDir, "..", "..");
|
|
34
|
+
const migrationsPath = path.join(
|
|
35
|
+
projectRoot,
|
|
36
|
+
"src",
|
|
37
|
+
"core",
|
|
38
|
+
"infrastructure",
|
|
39
|
+
"db",
|
|
40
|
+
"migrations"
|
|
41
|
+
);
|
|
42
|
+
if (fs.existsSync(migrationsPath)) {
|
|
43
|
+
return migrationsPath;
|
|
44
|
+
}
|
|
45
|
+
return path.join(currentDir, "migrations");
|
|
32
46
|
};
|
|
33
47
|
const createMigrationsTableSQL = `
|
|
34
48
|
CREATE TABLE IF NOT EXISTS _prisma_migrations (
|
|
@@ -152,39 +166,52 @@ const runMigrations = async (prisma2 = null) => {
|
|
|
152
166
|
}
|
|
153
167
|
};
|
|
154
168
|
const { PrismaClient } = pkg;
|
|
169
|
+
let prismaInstance = null;
|
|
170
|
+
let cachedDbUrl = null;
|
|
155
171
|
function getDatabaseUrl() {
|
|
172
|
+
if (cachedDbUrl) {
|
|
173
|
+
return cachedDbUrl;
|
|
174
|
+
}
|
|
156
175
|
if (!isDev) {
|
|
157
176
|
const userDataPath = app.getPath("userData");
|
|
158
177
|
const dbDir = path.join(userDataPath, "db");
|
|
159
178
|
if (!fs.existsSync(dbDir)) {
|
|
160
179
|
fs.mkdirSync(dbDir, { recursive: true });
|
|
161
180
|
}
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
);
|
|
166
|
-
return `file:${path.join(dbDir, "app.db")}`;
|
|
181
|
+
cachedDbUrl = `file:${path.join(dbDir, "app.db")}`;
|
|
182
|
+
console.log("Using userData database path:", cachedDbUrl);
|
|
183
|
+
return cachedDbUrl;
|
|
167
184
|
}
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
);
|
|
172
|
-
return `file:${path.join(process.cwd(), "src", "core", "infrastructure", "db", "dev.db")}`;
|
|
185
|
+
cachedDbUrl = `file:${path.join(process.cwd(), "src", "core", "infrastructure", "db", "dev.db")}`;
|
|
186
|
+
console.log("Using default development database path:", cachedDbUrl);
|
|
187
|
+
return cachedDbUrl;
|
|
173
188
|
}
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
189
|
+
function getPrismaClient() {
|
|
190
|
+
if (!prismaInstance) {
|
|
191
|
+
const dbUrl = getDatabaseUrl();
|
|
192
|
+
prismaInstance = new PrismaClient({
|
|
193
|
+
datasources: {
|
|
194
|
+
db: {
|
|
195
|
+
url: dbUrl
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
});
|
|
199
|
+
}
|
|
200
|
+
return prismaInstance;
|
|
201
|
+
}
|
|
202
|
+
const prisma = new Proxy({}, {
|
|
203
|
+
get(_target, prop) {
|
|
204
|
+
return Reflect.get(getPrismaClient(), prop);
|
|
180
205
|
}
|
|
181
206
|
});
|
|
182
207
|
const initDatabase = async () => {
|
|
183
208
|
try {
|
|
209
|
+
const dbUrl = getDatabaseUrl();
|
|
210
|
+
const client = getPrismaClient();
|
|
184
211
|
console.log(`Initializing database(url:${dbUrl})...`);
|
|
185
|
-
await
|
|
212
|
+
await client.$queryRaw`SELECT 1`;
|
|
186
213
|
console.log("Database connection established successfully.");
|
|
187
|
-
await runMigrations(
|
|
214
|
+
await runMigrations(client);
|
|
188
215
|
return true;
|
|
189
216
|
} catch (error) {
|
|
190
217
|
console.error("Database initialization error:", error);
|
|
@@ -192,8 +219,12 @@ const initDatabase = async () => {
|
|
|
192
219
|
}
|
|
193
220
|
};
|
|
194
221
|
const disconnect = async () => {
|
|
195
|
-
|
|
196
|
-
|
|
222
|
+
if (prismaInstance) {
|
|
223
|
+
await prismaInstance.$disconnect();
|
|
224
|
+
prismaInstance = null;
|
|
225
|
+
cachedDbUrl = null;
|
|
226
|
+
console.log("Database connection has been closed");
|
|
227
|
+
}
|
|
197
228
|
};
|
|
198
229
|
var TaskStatus = /* @__PURE__ */ ((TaskStatus2) => {
|
|
199
230
|
TaskStatus2[TaskStatus2["CREATED"] = -1] = "CREATED";
|
|
@@ -2105,7 +2136,17 @@ class WorkerOrchestrator {
|
|
|
2105
2136
|
this.splitterWorker = null;
|
|
2106
2137
|
this.converterWorkers = [];
|
|
2107
2138
|
this.mergerWorker = null;
|
|
2108
|
-
this.uploadsDir =
|
|
2139
|
+
this.uploadsDir = null;
|
|
2140
|
+
}
|
|
2141
|
+
/**
|
|
2142
|
+
* Get uploads directory (lazy initialization)
|
|
2143
|
+
* Must be called after app.setPath() has been configured
|
|
2144
|
+
*/
|
|
2145
|
+
getUploadsDir() {
|
|
2146
|
+
if (!this.uploadsDir) {
|
|
2147
|
+
this.uploadsDir = fileLogic.getUploadDir();
|
|
2148
|
+
}
|
|
2149
|
+
return this.uploadsDir;
|
|
2109
2150
|
}
|
|
2110
2151
|
/**
|
|
2111
2152
|
* Start all workers
|
|
@@ -2118,9 +2159,10 @@ class WorkerOrchestrator {
|
|
|
2118
2159
|
try {
|
|
2119
2160
|
console.log("[WorkerOrchestrator] Initializing workers...");
|
|
2120
2161
|
await this.cleanupOrphanedWork();
|
|
2121
|
-
|
|
2122
|
-
|
|
2123
|
-
|
|
2162
|
+
const uploadsDir = this.getUploadsDir();
|
|
2163
|
+
ImagePathUtil.init(uploadsDir);
|
|
2164
|
+
console.log(`[WorkerOrchestrator] ImagePathUtil initialized with uploadsDir: ${uploadsDir}`);
|
|
2165
|
+
this.splitterWorker = new SplitterWorker(uploadsDir);
|
|
2124
2166
|
console.log(`[WorkerOrchestrator] SplitterWorker created (ID: ${this.splitterWorker.getWorkerId()})`);
|
|
2125
2167
|
this.splitterWorker.run().catch((error) => {
|
|
2126
2168
|
console.error("[WorkerOrchestrator] SplitterWorker error:", error);
|
|
@@ -2134,7 +2176,7 @@ class WorkerOrchestrator {
|
|
|
2134
2176
|
console.error(`[WorkerOrchestrator] ConverterWorker ${worker.getWorkerId().slice(0, 8)} error:`, error);
|
|
2135
2177
|
});
|
|
2136
2178
|
}
|
|
2137
|
-
this.mergerWorker = new MergerWorker(
|
|
2179
|
+
this.mergerWorker = new MergerWorker(uploadsDir);
|
|
2138
2180
|
console.log(`[WorkerOrchestrator] MergerWorker created (ID: ${this.mergerWorker.getWorkerId().slice(0, 8)})`);
|
|
2139
2181
|
this.mergerWorker.run().catch((error) => {
|
|
2140
2182
|
console.error("[WorkerOrchestrator] MergerWorker error:", error);
|
|
@@ -3342,6 +3384,14 @@ class EventBridge {
|
|
|
3342
3384
|
}
|
|
3343
3385
|
}
|
|
3344
3386
|
const eventBridge = new EventBridge();
|
|
3387
|
+
if (!app.isPackaged) {
|
|
3388
|
+
app.setName("MarkPDFdown");
|
|
3389
|
+
const userDataPath = app.getPath("userData");
|
|
3390
|
+
if (userDataPath.endsWith("Electron")) {
|
|
3391
|
+
const newPath = userDataPath.replace(/Electron$/, "MarkPDFdown");
|
|
3392
|
+
app.setPath("userData", newPath);
|
|
3393
|
+
}
|
|
3394
|
+
}
|
|
3345
3395
|
protocol.registerSchemesAsPrivileged([
|
|
3346
3396
|
{
|
|
3347
3397
|
scheme: "local-file",
|