nuxt-ai-ready 0.7.9 → 0.7.11
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/module.json +1 -1
- package/dist/module.mjs +1 -0
- package/dist/runtime/server/routes/__ai-ready/restore.post.d.ts +5 -0
- package/dist/runtime/server/routes/__ai-ready/restore.post.js +41 -0
- package/dist/runtime/server/utils/batchIndex.d.ts +1 -1
- package/dist/runtime/server/utils/runCron.d.ts +1 -1
- package/dist/runtime/server/utils/runCron.js +16 -2
- package/package.json +1 -1
package/dist/module.json
CHANGED
package/dist/module.mjs
CHANGED
|
@@ -692,6 +692,7 @@ export const errorRoutes = []`;
|
|
|
692
692
|
addServerHandler({ route: "/__ai-ready/status", handler: resolve("./runtime/server/routes/__ai-ready/status.get") });
|
|
693
693
|
addServerHandler({ route: "/__ai-ready/poll", method: "post", handler: resolve("./runtime/server/routes/__ai-ready/poll.post") });
|
|
694
694
|
addServerHandler({ route: "/__ai-ready/prune", method: "post", handler: resolve("./runtime/server/routes/__ai-ready/prune.post") });
|
|
695
|
+
addServerHandler({ route: "/__ai-ready/restore", method: "post", handler: resolve("./runtime/server/routes/__ai-ready/restore.post") });
|
|
695
696
|
}
|
|
696
697
|
if (indexNowKey) {
|
|
697
698
|
addServerHandler({ route: `/${indexNowKey}.txt`, handler: resolve("./runtime/server/routes/indexnow-key.get") });
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { createError, eventHandler, getQuery } from "h3";
|
|
2
|
+
import { useRuntimeConfig } from "nitropack/runtime";
|
|
3
|
+
import { useDatabase } from "../../db/index.js";
|
|
4
|
+
import { decompressFromBase64, importDbDump } from "../../db/shared.js";
|
|
5
|
+
export default eventHandler(async (event) => {
|
|
6
|
+
const config = useRuntimeConfig(event)["nuxt-ai-ready"];
|
|
7
|
+
const query = getQuery(event);
|
|
8
|
+
if (config.runtimeSyncSecret) {
|
|
9
|
+
const secret = query.secret;
|
|
10
|
+
if (secret !== config.runtimeSyncSecret) {
|
|
11
|
+
throw createError({ statusCode: 401, message: "Unauthorized" });
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
let dumpData = null;
|
|
15
|
+
const cfEnv = event.context?.cloudflare?.env;
|
|
16
|
+
if (cfEnv?.ASSETS?.fetch) {
|
|
17
|
+
const response = await cfEnv.ASSETS.fetch(new Request("https://assets.local/__ai-ready/pages.dump"));
|
|
18
|
+
if (response.ok) {
|
|
19
|
+
dumpData = await response.text();
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
if (!dumpData) {
|
|
23
|
+
dumpData = await globalThis.$fetch("/__ai-ready/pages.dump", {
|
|
24
|
+
responseType: "text"
|
|
25
|
+
}).catch(() => null);
|
|
26
|
+
}
|
|
27
|
+
if (!dumpData) {
|
|
28
|
+
throw createError({ statusCode: 404, message: "Dump file not found" });
|
|
29
|
+
}
|
|
30
|
+
const db = await useDatabase(event);
|
|
31
|
+
const clear = query.clear !== "false" && query.clear !== "0";
|
|
32
|
+
if (clear) {
|
|
33
|
+
await db.exec("DELETE FROM ai_ready_pages");
|
|
34
|
+
}
|
|
35
|
+
const rows = await decompressFromBase64(dumpData);
|
|
36
|
+
await importDbDump(db, rows);
|
|
37
|
+
return {
|
|
38
|
+
restored: rows.length,
|
|
39
|
+
cleared: clear
|
|
40
|
+
};
|
|
41
|
+
});
|
|
@@ -23,4 +23,4 @@ export interface BatchIndexResult {
|
|
|
23
23
|
* Batch index pending pages (max 50 per batch)
|
|
24
24
|
* Shared logic used by poll endpoint and scheduled task
|
|
25
25
|
*/
|
|
26
|
-
export declare function batchIndexPages(event: H3Event
|
|
26
|
+
export declare function batchIndexPages(event: H3Event, options?: BatchIndexOptions): Promise<BatchIndexResult>;
|
|
@@ -16,6 +16,6 @@ export interface CronResult {
|
|
|
16
16
|
/**
|
|
17
17
|
* Run cron job logic - shared between scheduled task and HTTP endpoint
|
|
18
18
|
*/
|
|
19
|
-
export declare function runCron(
|
|
19
|
+
export declare function runCron(providedEvent: H3Event | undefined, options?: {
|
|
20
20
|
batchSize?: number;
|
|
21
21
|
}): Promise<CronResult>;
|
|
@@ -1,10 +1,24 @@
|
|
|
1
|
-
import { useRuntimeConfig } from "nitropack/runtime";
|
|
1
|
+
import { useEvent, useRuntimeConfig } from "nitropack/runtime";
|
|
2
2
|
import { cleanupOldCronRuns, completeCronRun, startCronRun } from "../db/queries.js";
|
|
3
3
|
import { batchIndexPages } from "./batchIndex.js";
|
|
4
4
|
import { syncToIndexNow } from "./indexnow.js";
|
|
5
|
-
|
|
5
|
+
function getEvent(providedEvent) {
|
|
6
|
+
if (providedEvent)
|
|
7
|
+
return providedEvent;
|
|
8
|
+
try {
|
|
9
|
+
return useEvent();
|
|
10
|
+
} catch {
|
|
11
|
+
return void 0;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
export async function runCron(providedEvent, options) {
|
|
6
15
|
if (import.meta.dev)
|
|
7
16
|
return {};
|
|
17
|
+
const event = getEvent(providedEvent);
|
|
18
|
+
if (!event) {
|
|
19
|
+
console.warn("[ai-ready:cron] No event context available, skipping");
|
|
20
|
+
return {};
|
|
21
|
+
}
|
|
8
22
|
const config = useRuntimeConfig()["nuxt-ai-ready"];
|
|
9
23
|
const results = {};
|
|
10
24
|
const allErrors = [];
|