flowrix 1.0.1-beta.52 → 1.0.1-beta.53
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
CHANGED
package/dist/module.mjs
CHANGED
|
@@ -262,6 +262,10 @@ const module = defineNuxtModule({
|
|
|
262
262
|
route: "/api/service/:slug",
|
|
263
263
|
handler: resolver.resolve("./runtime/server/api/service/[slug]")
|
|
264
264
|
});
|
|
265
|
+
addServerHandler({
|
|
266
|
+
route: "/api/service/getall",
|
|
267
|
+
handler: resolver.resolve("./runtime/server/api/service/getall")
|
|
268
|
+
});
|
|
265
269
|
addServerHandler({
|
|
266
270
|
route: "/api/service/availability",
|
|
267
271
|
handler: resolver.resolve("./runtime/server/api/service/availability")
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { defineEventHandler, getQuery, createError, readBody } from "h3";
|
|
2
|
+
import { $fetch } from "ofetch";
|
|
3
|
+
import { writeFile, mkdir, readFile } from "fs/promises";
|
|
4
|
+
import { join } from "path";
|
|
5
|
+
const CACHE_DIR = join(process.cwd(), ".nuxt", "cache", "nitro", "services");
|
|
6
|
+
export const serviceCache = /* @__PURE__ */ new Map();
|
|
7
|
+
async function ensureCacheDir() {
|
|
8
|
+
try {
|
|
9
|
+
await mkdir(CACHE_DIR, { recursive: true });
|
|
10
|
+
} catch (error) {
|
|
11
|
+
console.error("Error creating cache directory:", error);
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
export default defineEventHandler(async (event) => {
|
|
15
|
+
const slug = "all";
|
|
16
|
+
const query = getQuery(event);
|
|
17
|
+
const body = await readBody(event);
|
|
18
|
+
if (!slug) {
|
|
19
|
+
throw createError({ statusCode: 400, statusMessage: "Missing slug parameter" });
|
|
20
|
+
}
|
|
21
|
+
if (!/^[a-zA-Z0-9-_]+$/.test(slug)) {
|
|
22
|
+
throw createError({ statusCode: 400, statusMessage: "Invalid slug" });
|
|
23
|
+
}
|
|
24
|
+
const cacheKey = `${slug}-${JSON.stringify(query)}`;
|
|
25
|
+
const fileName = cacheKey.replace(/[^a-zA-Z0-9-_]/g, "_");
|
|
26
|
+
const filePath = join(CACHE_DIR, `${fileName}.json`);
|
|
27
|
+
try {
|
|
28
|
+
const fileContent = await readFile(filePath, "utf-8");
|
|
29
|
+
const service = JSON.parse(fileContent);
|
|
30
|
+
return service;
|
|
31
|
+
} catch (error) {
|
|
32
|
+
}
|
|
33
|
+
try {
|
|
34
|
+
const service = await $fetch(`${process.env.FLOWRIX_API_BASE}services`, {
|
|
35
|
+
headers: {
|
|
36
|
+
"x-public-key": process.env.FLOWRIX_API_KEY,
|
|
37
|
+
"x-api-secret": process.env.FLOWRIX_API_SECRET,
|
|
38
|
+
"Origin": process.env.FLOWRIX_API_ORIGIN
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
await ensureCacheDir();
|
|
42
|
+
await writeFile(filePath, JSON.stringify(service, null, 2), "utf-8");
|
|
43
|
+
return service;
|
|
44
|
+
} catch (error) {
|
|
45
|
+
throw createError({
|
|
46
|
+
statusCode: 500,
|
|
47
|
+
statusMessage: `Failed to fetch services`,
|
|
48
|
+
data: error.message
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
});
|
|
@@ -8,9 +8,9 @@ export const useServiceStore = defineStore("ServiceStore", {
|
|
|
8
8
|
actions: {
|
|
9
9
|
async getAllServices() {
|
|
10
10
|
try {
|
|
11
|
-
const apiUrl = `/api/
|
|
11
|
+
const apiUrl = `/api/service/getall`;
|
|
12
12
|
const response = await $fetch(apiUrl, {
|
|
13
|
-
method: "
|
|
13
|
+
method: "POST",
|
|
14
14
|
headers: {
|
|
15
15
|
"Content-Type": "application/json"
|
|
16
16
|
}
|