|
|
@@ -0,0 +1,2235 @@
|
|
|
+import process from 'node:process';globalThis._importMeta_={url:import.meta.url,env:process.env};import { tmpdir } from 'node:os';
|
|
|
+import destr from 'file:///Users/linjiancheng/Documents/gameMame/web_admin_fortue_tiger_vben/node_modules/.pnpm/destr@2.0.5/node_modules/destr/dist/index.mjs';
|
|
|
+import { defineEventHandler, handleCacheHeaders, splitCookiesString, createEvent, fetchWithEvent, isEvent, eventHandler, setHeaders, sendRedirect, proxyRequest, getRequestURL, getRequestHeader, getResponseHeader, getRequestHeaders, setResponseHeaders, setResponseStatus, send, createApp, createRouter as createRouter$1, toNodeListener, lazyEventHandler, createError, getRouterParam, readBody, getQuery as getQuery$1, getHeader, deleteCookie, setCookie, getCookie, setHeader } from 'file:///Users/linjiancheng/Documents/gameMame/web_admin_fortue_tiger_vben/node_modules/.pnpm/h3@1.15.3/node_modules/h3/dist/index.mjs';
|
|
|
+import { createHooks } from 'file:///Users/linjiancheng/Documents/gameMame/web_admin_fortue_tiger_vben/node_modules/.pnpm/hookable@5.5.3/node_modules/hookable/dist/index.mjs';
|
|
|
+import { createFetch, Headers as Headers$1 } from 'file:///Users/linjiancheng/Documents/gameMame/web_admin_fortue_tiger_vben/node_modules/.pnpm/ofetch@1.4.1/node_modules/ofetch/dist/node.mjs';
|
|
|
+import { fetchNodeRequestHandler, callNodeRequestHandler } from 'file:///Users/linjiancheng/Documents/gameMame/web_admin_fortue_tiger_vben/node_modules/.pnpm/node-mock-http@1.0.1/node_modules/node-mock-http/dist/index.mjs';
|
|
|
+import { parseURL, withoutBase, joinURL, getQuery, withQuery } from 'file:///Users/linjiancheng/Documents/gameMame/web_admin_fortue_tiger_vben/node_modules/.pnpm/ufo@1.6.1/node_modules/ufo/dist/index.mjs';
|
|
|
+import { createStorage, prefixStorage } from 'file:///Users/linjiancheng/Documents/gameMame/web_admin_fortue_tiger_vben/node_modules/.pnpm/unstorage@1.16.0_@netlify+blobs@8.2.0_db0@0.3.2_ioredis@5.6.1/node_modules/unstorage/dist/index.mjs';
|
|
|
+import unstorage_47drivers_47fs from 'file:///Users/linjiancheng/Documents/gameMame/web_admin_fortue_tiger_vben/node_modules/.pnpm/unstorage@1.16.0_@netlify+blobs@8.2.0_db0@0.3.2_ioredis@5.6.1/node_modules/unstorage/drivers/fs.mjs';
|
|
|
+import { digest } from 'file:///Users/linjiancheng/Documents/gameMame/web_admin_fortue_tiger_vben/node_modules/.pnpm/ohash@2.0.11/node_modules/ohash/dist/index.mjs';
|
|
|
+import { klona } from 'file:///Users/linjiancheng/Documents/gameMame/web_admin_fortue_tiger_vben/node_modules/.pnpm/klona@2.0.6/node_modules/klona/dist/index.mjs';
|
|
|
+import defu, { defuFn } from 'file:///Users/linjiancheng/Documents/gameMame/web_admin_fortue_tiger_vben/node_modules/.pnpm/defu@6.1.4/node_modules/defu/dist/defu.mjs';
|
|
|
+import { snakeCase } from 'file:///Users/linjiancheng/Documents/gameMame/web_admin_fortue_tiger_vben/node_modules/.pnpm/scule@1.3.0/node_modules/scule/dist/index.mjs';
|
|
|
+import { getContext } from 'file:///Users/linjiancheng/Documents/gameMame/web_admin_fortue_tiger_vben/node_modules/.pnpm/unctx@2.4.1/node_modules/unctx/dist/index.mjs';
|
|
|
+import { toRouteMatcher, createRouter } from 'file:///Users/linjiancheng/Documents/gameMame/web_admin_fortue_tiger_vben/node_modules/.pnpm/radix3@1.1.2/node_modules/radix3/dist/index.mjs';
|
|
|
+import { readFile } from 'node:fs/promises';
|
|
|
+import { resolve, dirname, join } from 'node:path';
|
|
|
+import consola from 'file:///Users/linjiancheng/Documents/gameMame/web_admin_fortue_tiger_vben/node_modules/.pnpm/consola@3.4.2/node_modules/consola/dist/index.mjs';
|
|
|
+import { ErrorParser } from 'file:///Users/linjiancheng/Documents/gameMame/web_admin_fortue_tiger_vben/node_modules/.pnpm/youch-core@0.3.2/node_modules/youch-core/build/index.js';
|
|
|
+import { Youch } from 'file:///Users/linjiancheng/Documents/gameMame/web_admin_fortue_tiger_vben/node_modules/.pnpm/youch@4.1.0-beta.8/node_modules/youch/build/index.js';
|
|
|
+import { SourceMapConsumer } from 'file:///Users/linjiancheng/Documents/gameMame/web_admin_fortue_tiger_vben/node_modules/.pnpm/source-map@0.7.4/node_modules/source-map/source-map.js';
|
|
|
+import { Server } from 'node:http';
|
|
|
+import nodeCrypto from 'node:crypto';
|
|
|
+import { parentPort, threadId } from 'node:worker_threads';
|
|
|
+import { faker } from 'file:///Users/linjiancheng/Documents/gameMame/web_admin_fortue_tiger_vben/node_modules/.pnpm/@faker-js+faker@9.9.0/node_modules/@faker-js/faker/dist/index.js';
|
|
|
+import jwt from 'file:///Users/linjiancheng/Documents/gameMame/web_admin_fortue_tiger_vben/node_modules/.pnpm/jsonwebtoken@9.0.2/node_modules/jsonwebtoken/index.js';
|
|
|
+
|
|
|
+const serverAssets = [{"baseName":"server","dir":"/Users/linjiancheng/Documents/gameMame/web_admin_fortue_tiger_vben/apps/backend-mock/assets"}];
|
|
|
+
|
|
|
+const assets = createStorage();
|
|
|
+
|
|
|
+for (const asset of serverAssets) {
|
|
|
+ assets.mount(asset.baseName, unstorage_47drivers_47fs({ base: asset.dir, ignore: (asset?.ignore || []) }));
|
|
|
+}
|
|
|
+
|
|
|
+const storage = createStorage({});
|
|
|
+
|
|
|
+storage.mount('/assets', assets);
|
|
|
+
|
|
|
+storage.mount('root', unstorage_47drivers_47fs({"driver":"fs","readOnly":true,"base":"/Users/linjiancheng/Documents/gameMame/web_admin_fortue_tiger_vben/apps/backend-mock"}));
|
|
|
+storage.mount('src', unstorage_47drivers_47fs({"driver":"fs","readOnly":true,"base":"/Users/linjiancheng/Documents/gameMame/web_admin_fortue_tiger_vben/apps/backend-mock"}));
|
|
|
+storage.mount('build', unstorage_47drivers_47fs({"driver":"fs","readOnly":false,"base":"/Users/linjiancheng/Documents/gameMame/web_admin_fortue_tiger_vben/apps/backend-mock/.nitro"}));
|
|
|
+storage.mount('cache', unstorage_47drivers_47fs({"driver":"fs","readOnly":false,"base":"/Users/linjiancheng/Documents/gameMame/web_admin_fortue_tiger_vben/apps/backend-mock/.nitro/cache"}));
|
|
|
+storage.mount('data', unstorage_47drivers_47fs({"driver":"fs","base":"/Users/linjiancheng/Documents/gameMame/web_admin_fortue_tiger_vben/apps/backend-mock/.data/kv"}));
|
|
|
+
|
|
|
+function useStorage(base = "") {
|
|
|
+ return base ? prefixStorage(storage, base) : storage;
|
|
|
+}
|
|
|
+
|
|
|
+const Hasher = /* @__PURE__ */ (() => {
|
|
|
+ class Hasher2 {
|
|
|
+ buff = "";
|
|
|
+ #context = /* @__PURE__ */ new Map();
|
|
|
+ write(str) {
|
|
|
+ this.buff += str;
|
|
|
+ }
|
|
|
+ dispatch(value) {
|
|
|
+ const type = value === null ? "null" : typeof value;
|
|
|
+ return this[type](value);
|
|
|
+ }
|
|
|
+ object(object) {
|
|
|
+ if (object && typeof object.toJSON === "function") {
|
|
|
+ return this.object(object.toJSON());
|
|
|
+ }
|
|
|
+ const objString = Object.prototype.toString.call(object);
|
|
|
+ let objType = "";
|
|
|
+ const objectLength = objString.length;
|
|
|
+ objType = objectLength < 10 ? "unknown:[" + objString + "]" : objString.slice(8, objectLength - 1);
|
|
|
+ objType = objType.toLowerCase();
|
|
|
+ let objectNumber = null;
|
|
|
+ if ((objectNumber = this.#context.get(object)) === void 0) {
|
|
|
+ this.#context.set(object, this.#context.size);
|
|
|
+ } else {
|
|
|
+ return this.dispatch("[CIRCULAR:" + objectNumber + "]");
|
|
|
+ }
|
|
|
+ if (typeof Buffer !== "undefined" && Buffer.isBuffer && Buffer.isBuffer(object)) {
|
|
|
+ this.write("buffer:");
|
|
|
+ return this.write(object.toString("utf8"));
|
|
|
+ }
|
|
|
+ if (objType !== "object" && objType !== "function" && objType !== "asyncfunction") {
|
|
|
+ if (this[objType]) {
|
|
|
+ this[objType](object);
|
|
|
+ } else {
|
|
|
+ this.unknown(object, objType);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ const keys = Object.keys(object).sort();
|
|
|
+ const extraKeys = [];
|
|
|
+ this.write("object:" + (keys.length + extraKeys.length) + ":");
|
|
|
+ const dispatchForKey = (key) => {
|
|
|
+ this.dispatch(key);
|
|
|
+ this.write(":");
|
|
|
+ this.dispatch(object[key]);
|
|
|
+ this.write(",");
|
|
|
+ };
|
|
|
+ for (const key of keys) {
|
|
|
+ dispatchForKey(key);
|
|
|
+ }
|
|
|
+ for (const key of extraKeys) {
|
|
|
+ dispatchForKey(key);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ array(arr, unordered) {
|
|
|
+ unordered = unordered === void 0 ? false : unordered;
|
|
|
+ this.write("array:" + arr.length + ":");
|
|
|
+ if (!unordered || arr.length <= 1) {
|
|
|
+ for (const entry of arr) {
|
|
|
+ this.dispatch(entry);
|
|
|
+ }
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ const contextAdditions = /* @__PURE__ */ new Map();
|
|
|
+ const entries = arr.map((entry) => {
|
|
|
+ const hasher = new Hasher2();
|
|
|
+ hasher.dispatch(entry);
|
|
|
+ for (const [key, value] of hasher.#context) {
|
|
|
+ contextAdditions.set(key, value);
|
|
|
+ }
|
|
|
+ return hasher.toString();
|
|
|
+ });
|
|
|
+ this.#context = contextAdditions;
|
|
|
+ entries.sort();
|
|
|
+ return this.array(entries, false);
|
|
|
+ }
|
|
|
+ date(date) {
|
|
|
+ return this.write("date:" + date.toJSON());
|
|
|
+ }
|
|
|
+ symbol(sym) {
|
|
|
+ return this.write("symbol:" + sym.toString());
|
|
|
+ }
|
|
|
+ unknown(value, type) {
|
|
|
+ this.write(type);
|
|
|
+ if (!value) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ this.write(":");
|
|
|
+ if (value && typeof value.entries === "function") {
|
|
|
+ return this.array(
|
|
|
+ [...value.entries()],
|
|
|
+ true
|
|
|
+ /* ordered */
|
|
|
+ );
|
|
|
+ }
|
|
|
+ }
|
|
|
+ error(err) {
|
|
|
+ return this.write("error:" + err.toString());
|
|
|
+ }
|
|
|
+ boolean(bool) {
|
|
|
+ return this.write("bool:" + bool);
|
|
|
+ }
|
|
|
+ string(string) {
|
|
|
+ this.write("string:" + string.length + ":");
|
|
|
+ this.write(string);
|
|
|
+ }
|
|
|
+ function(fn) {
|
|
|
+ this.write("fn:");
|
|
|
+ if (isNativeFunction(fn)) {
|
|
|
+ this.dispatch("[native]");
|
|
|
+ } else {
|
|
|
+ this.dispatch(fn.toString());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ number(number) {
|
|
|
+ return this.write("number:" + number);
|
|
|
+ }
|
|
|
+ null() {
|
|
|
+ return this.write("Null");
|
|
|
+ }
|
|
|
+ undefined() {
|
|
|
+ return this.write("Undefined");
|
|
|
+ }
|
|
|
+ regexp(regex) {
|
|
|
+ return this.write("regex:" + regex.toString());
|
|
|
+ }
|
|
|
+ arraybuffer(arr) {
|
|
|
+ this.write("arraybuffer:");
|
|
|
+ return this.dispatch(new Uint8Array(arr));
|
|
|
+ }
|
|
|
+ url(url) {
|
|
|
+ return this.write("url:" + url.toString());
|
|
|
+ }
|
|
|
+ map(map) {
|
|
|
+ this.write("map:");
|
|
|
+ const arr = [...map];
|
|
|
+ return this.array(arr, false);
|
|
|
+ }
|
|
|
+ set(set) {
|
|
|
+ this.write("set:");
|
|
|
+ const arr = [...set];
|
|
|
+ return this.array(arr, false);
|
|
|
+ }
|
|
|
+ bigint(number) {
|
|
|
+ return this.write("bigint:" + number.toString());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ for (const type of [
|
|
|
+ "uint8array",
|
|
|
+ "uint8clampedarray",
|
|
|
+ "unt8array",
|
|
|
+ "uint16array",
|
|
|
+ "unt16array",
|
|
|
+ "uint32array",
|
|
|
+ "unt32array",
|
|
|
+ "float32array",
|
|
|
+ "float64array"
|
|
|
+ ]) {
|
|
|
+ Hasher2.prototype[type] = function(arr) {
|
|
|
+ this.write(type + ":");
|
|
|
+ return this.array([...arr], false);
|
|
|
+ };
|
|
|
+ }
|
|
|
+ function isNativeFunction(f) {
|
|
|
+ if (typeof f !== "function") {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ return Function.prototype.toString.call(f).slice(
|
|
|
+ -15
|
|
|
+ /* "[native code] }".length */
|
|
|
+ ) === "[native code] }";
|
|
|
+ }
|
|
|
+ return Hasher2;
|
|
|
+})();
|
|
|
+function serialize(object) {
|
|
|
+ const hasher = new Hasher();
|
|
|
+ hasher.dispatch(object);
|
|
|
+ return hasher.buff;
|
|
|
+}
|
|
|
+function hash(value) {
|
|
|
+ return digest(typeof value === "string" ? value : serialize(value)).replace(/[-_]/g, "").slice(0, 10);
|
|
|
+}
|
|
|
+
|
|
|
+function defaultCacheOptions() {
|
|
|
+ return {
|
|
|
+ name: "_",
|
|
|
+ base: "/cache",
|
|
|
+ swr: true,
|
|
|
+ maxAge: 1
|
|
|
+ };
|
|
|
+}
|
|
|
+function defineCachedFunction(fn, opts = {}) {
|
|
|
+ opts = { ...defaultCacheOptions(), ...opts };
|
|
|
+ const pending = {};
|
|
|
+ const group = opts.group || "nitro/functions";
|
|
|
+ const name = opts.name || fn.name || "_";
|
|
|
+ const integrity = opts.integrity || hash([fn, opts]);
|
|
|
+ const validate = opts.validate || ((entry) => entry.value !== void 0);
|
|
|
+ async function get(key, resolver, shouldInvalidateCache, event) {
|
|
|
+ const cacheKey = [opts.base, group, name, key + ".json"].filter(Boolean).join(":").replace(/:\/$/, ":index");
|
|
|
+ let entry = await useStorage().getItem(cacheKey).catch((error) => {
|
|
|
+ console.error(`[cache] Cache read error.`, error);
|
|
|
+ useNitroApp().captureError(error, { event, tags: ["cache"] });
|
|
|
+ }) || {};
|
|
|
+ if (typeof entry !== "object") {
|
|
|
+ entry = {};
|
|
|
+ const error = new Error("Malformed data read from cache.");
|
|
|
+ console.error("[cache]", error);
|
|
|
+ useNitroApp().captureError(error, { event, tags: ["cache"] });
|
|
|
+ }
|
|
|
+ const ttl = (opts.maxAge ?? 0) * 1e3;
|
|
|
+ if (ttl) {
|
|
|
+ entry.expires = Date.now() + ttl;
|
|
|
+ }
|
|
|
+ const expired = shouldInvalidateCache || entry.integrity !== integrity || ttl && Date.now() - (entry.mtime || 0) > ttl || validate(entry) === false;
|
|
|
+ const _resolve = async () => {
|
|
|
+ const isPending = pending[key];
|
|
|
+ if (!isPending) {
|
|
|
+ if (entry.value !== void 0 && (opts.staleMaxAge || 0) >= 0 && opts.swr === false) {
|
|
|
+ entry.value = void 0;
|
|
|
+ entry.integrity = void 0;
|
|
|
+ entry.mtime = void 0;
|
|
|
+ entry.expires = void 0;
|
|
|
+ }
|
|
|
+ pending[key] = Promise.resolve(resolver());
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ entry.value = await pending[key];
|
|
|
+ } catch (error) {
|
|
|
+ if (!isPending) {
|
|
|
+ delete pending[key];
|
|
|
+ }
|
|
|
+ throw error;
|
|
|
+ }
|
|
|
+ if (!isPending) {
|
|
|
+ entry.mtime = Date.now();
|
|
|
+ entry.integrity = integrity;
|
|
|
+ delete pending[key];
|
|
|
+ if (validate(entry) !== false) {
|
|
|
+ let setOpts;
|
|
|
+ if (opts.maxAge && !opts.swr) {
|
|
|
+ setOpts = { ttl: opts.maxAge };
|
|
|
+ }
|
|
|
+ const promise = useStorage().setItem(cacheKey, entry, setOpts).catch((error) => {
|
|
|
+ console.error(`[cache] Cache write error.`, error);
|
|
|
+ useNitroApp().captureError(error, { event, tags: ["cache"] });
|
|
|
+ });
|
|
|
+ if (event?.waitUntil) {
|
|
|
+ event.waitUntil(promise);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ };
|
|
|
+ const _resolvePromise = expired ? _resolve() : Promise.resolve();
|
|
|
+ if (entry.value === void 0) {
|
|
|
+ await _resolvePromise;
|
|
|
+ } else if (expired && event && event.waitUntil) {
|
|
|
+ event.waitUntil(_resolvePromise);
|
|
|
+ }
|
|
|
+ if (opts.swr && validate(entry) !== false) {
|
|
|
+ _resolvePromise.catch((error) => {
|
|
|
+ console.error(`[cache] SWR handler error.`, error);
|
|
|
+ useNitroApp().captureError(error, { event, tags: ["cache"] });
|
|
|
+ });
|
|
|
+ return entry;
|
|
|
+ }
|
|
|
+ return _resolvePromise.then(() => entry);
|
|
|
+ }
|
|
|
+ return async (...args) => {
|
|
|
+ const shouldBypassCache = await opts.shouldBypassCache?.(...args);
|
|
|
+ if (shouldBypassCache) {
|
|
|
+ return fn(...args);
|
|
|
+ }
|
|
|
+ const key = await (opts.getKey || getKey)(...args);
|
|
|
+ const shouldInvalidateCache = await opts.shouldInvalidateCache?.(...args);
|
|
|
+ const entry = await get(
|
|
|
+ key,
|
|
|
+ () => fn(...args),
|
|
|
+ shouldInvalidateCache,
|
|
|
+ args[0] && isEvent(args[0]) ? args[0] : void 0
|
|
|
+ );
|
|
|
+ let value = entry.value;
|
|
|
+ if (opts.transform) {
|
|
|
+ value = await opts.transform(entry, ...args) || value;
|
|
|
+ }
|
|
|
+ return value;
|
|
|
+ };
|
|
|
+}
|
|
|
+function cachedFunction(fn, opts = {}) {
|
|
|
+ return defineCachedFunction(fn, opts);
|
|
|
+}
|
|
|
+function getKey(...args) {
|
|
|
+ return args.length > 0 ? hash(args) : "";
|
|
|
+}
|
|
|
+function escapeKey(key) {
|
|
|
+ return String(key).replace(/\W/g, "");
|
|
|
+}
|
|
|
+function defineCachedEventHandler(handler, opts = defaultCacheOptions()) {
|
|
|
+ const variableHeaderNames = (opts.varies || []).filter(Boolean).map((h) => h.toLowerCase()).sort();
|
|
|
+ const _opts = {
|
|
|
+ ...opts,
|
|
|
+ getKey: async (event) => {
|
|
|
+ const customKey = await opts.getKey?.(event);
|
|
|
+ if (customKey) {
|
|
|
+ return escapeKey(customKey);
|
|
|
+ }
|
|
|
+ const _path = event.node.req.originalUrl || event.node.req.url || event.path;
|
|
|
+ let _pathname;
|
|
|
+ try {
|
|
|
+ _pathname = escapeKey(decodeURI(parseURL(_path).pathname)).slice(0, 16) || "index";
|
|
|
+ } catch {
|
|
|
+ _pathname = "-";
|
|
|
+ }
|
|
|
+ const _hashedPath = `${_pathname}.${hash(_path)}`;
|
|
|
+ const _headers = variableHeaderNames.map((header) => [header, event.node.req.headers[header]]).map(([name, value]) => `${escapeKey(name)}.${hash(value)}`);
|
|
|
+ return [_hashedPath, ..._headers].join(":");
|
|
|
+ },
|
|
|
+ validate: (entry) => {
|
|
|
+ if (!entry.value) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ if (entry.value.code >= 400) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ if (entry.value.body === void 0) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ if (entry.value.headers.etag === "undefined" || entry.value.headers["last-modified"] === "undefined") {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ return true;
|
|
|
+ },
|
|
|
+ group: opts.group || "nitro/handlers",
|
|
|
+ integrity: opts.integrity || hash([handler, opts])
|
|
|
+ };
|
|
|
+ const _cachedHandler = cachedFunction(
|
|
|
+ async (incomingEvent) => {
|
|
|
+ const variableHeaders = {};
|
|
|
+ for (const header of variableHeaderNames) {
|
|
|
+ const value = incomingEvent.node.req.headers[header];
|
|
|
+ if (value !== void 0) {
|
|
|
+ variableHeaders[header] = value;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ const reqProxy = cloneWithProxy(incomingEvent.node.req, {
|
|
|
+ headers: variableHeaders
|
|
|
+ });
|
|
|
+ const resHeaders = {};
|
|
|
+ let _resSendBody;
|
|
|
+ const resProxy = cloneWithProxy(incomingEvent.node.res, {
|
|
|
+ statusCode: 200,
|
|
|
+ writableEnded: false,
|
|
|
+ writableFinished: false,
|
|
|
+ headersSent: false,
|
|
|
+ closed: false,
|
|
|
+ getHeader(name) {
|
|
|
+ return resHeaders[name];
|
|
|
+ },
|
|
|
+ setHeader(name, value) {
|
|
|
+ resHeaders[name] = value;
|
|
|
+ return this;
|
|
|
+ },
|
|
|
+ getHeaderNames() {
|
|
|
+ return Object.keys(resHeaders);
|
|
|
+ },
|
|
|
+ hasHeader(name) {
|
|
|
+ return name in resHeaders;
|
|
|
+ },
|
|
|
+ removeHeader(name) {
|
|
|
+ delete resHeaders[name];
|
|
|
+ },
|
|
|
+ getHeaders() {
|
|
|
+ return resHeaders;
|
|
|
+ },
|
|
|
+ end(chunk, arg2, arg3) {
|
|
|
+ if (typeof chunk === "string") {
|
|
|
+ _resSendBody = chunk;
|
|
|
+ }
|
|
|
+ if (typeof arg2 === "function") {
|
|
|
+ arg2();
|
|
|
+ }
|
|
|
+ if (typeof arg3 === "function") {
|
|
|
+ arg3();
|
|
|
+ }
|
|
|
+ return this;
|
|
|
+ },
|
|
|
+ write(chunk, arg2, arg3) {
|
|
|
+ if (typeof chunk === "string") {
|
|
|
+ _resSendBody = chunk;
|
|
|
+ }
|
|
|
+ if (typeof arg2 === "function") {
|
|
|
+ arg2(void 0);
|
|
|
+ }
|
|
|
+ if (typeof arg3 === "function") {
|
|
|
+ arg3();
|
|
|
+ }
|
|
|
+ return true;
|
|
|
+ },
|
|
|
+ writeHead(statusCode, headers2) {
|
|
|
+ this.statusCode = statusCode;
|
|
|
+ if (headers2) {
|
|
|
+ if (Array.isArray(headers2) || typeof headers2 === "string") {
|
|
|
+ throw new TypeError("Raw headers is not supported.");
|
|
|
+ }
|
|
|
+ for (const header in headers2) {
|
|
|
+ const value = headers2[header];
|
|
|
+ if (value !== void 0) {
|
|
|
+ this.setHeader(
|
|
|
+ header,
|
|
|
+ value
|
|
|
+ );
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return this;
|
|
|
+ }
|
|
|
+ });
|
|
|
+ const event = createEvent(reqProxy, resProxy);
|
|
|
+ event.fetch = (url, fetchOptions) => fetchWithEvent(event, url, fetchOptions, {
|
|
|
+ fetch: useNitroApp().localFetch
|
|
|
+ });
|
|
|
+ event.$fetch = (url, fetchOptions) => fetchWithEvent(event, url, fetchOptions, {
|
|
|
+ fetch: globalThis.$fetch
|
|
|
+ });
|
|
|
+ event.waitUntil = incomingEvent.waitUntil;
|
|
|
+ event.context = incomingEvent.context;
|
|
|
+ event.context.cache = {
|
|
|
+ options: _opts
|
|
|
+ };
|
|
|
+ const body = await handler(event) || _resSendBody;
|
|
|
+ const headers = event.node.res.getHeaders();
|
|
|
+ headers.etag = String(
|
|
|
+ headers.Etag || headers.etag || `W/"${hash(body)}"`
|
|
|
+ );
|
|
|
+ headers["last-modified"] = String(
|
|
|
+ headers["Last-Modified"] || headers["last-modified"] || (/* @__PURE__ */ new Date()).toUTCString()
|
|
|
+ );
|
|
|
+ const cacheControl = [];
|
|
|
+ if (opts.swr) {
|
|
|
+ if (opts.maxAge) {
|
|
|
+ cacheControl.push(`s-maxage=${opts.maxAge}`);
|
|
|
+ }
|
|
|
+ if (opts.staleMaxAge) {
|
|
|
+ cacheControl.push(`stale-while-revalidate=${opts.staleMaxAge}`);
|
|
|
+ } else {
|
|
|
+ cacheControl.push("stale-while-revalidate");
|
|
|
+ }
|
|
|
+ } else if (opts.maxAge) {
|
|
|
+ cacheControl.push(`max-age=${opts.maxAge}`);
|
|
|
+ }
|
|
|
+ if (cacheControl.length > 0) {
|
|
|
+ headers["cache-control"] = cacheControl.join(", ");
|
|
|
+ }
|
|
|
+ const cacheEntry = {
|
|
|
+ code: event.node.res.statusCode,
|
|
|
+ headers,
|
|
|
+ body
|
|
|
+ };
|
|
|
+ return cacheEntry;
|
|
|
+ },
|
|
|
+ _opts
|
|
|
+ );
|
|
|
+ return defineEventHandler(async (event) => {
|
|
|
+ if (opts.headersOnly) {
|
|
|
+ if (handleCacheHeaders(event, { maxAge: opts.maxAge })) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ return handler(event);
|
|
|
+ }
|
|
|
+ const response = await _cachedHandler(
|
|
|
+ event
|
|
|
+ );
|
|
|
+ if (event.node.res.headersSent || event.node.res.writableEnded) {
|
|
|
+ return response.body;
|
|
|
+ }
|
|
|
+ if (handleCacheHeaders(event, {
|
|
|
+ modifiedTime: new Date(response.headers["last-modified"]),
|
|
|
+ etag: response.headers.etag,
|
|
|
+ maxAge: opts.maxAge
|
|
|
+ })) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ event.node.res.statusCode = response.code;
|
|
|
+ for (const name in response.headers) {
|
|
|
+ const value = response.headers[name];
|
|
|
+ if (name === "set-cookie") {
|
|
|
+ event.node.res.appendHeader(
|
|
|
+ name,
|
|
|
+ splitCookiesString(value)
|
|
|
+ );
|
|
|
+ } else {
|
|
|
+ if (value !== void 0) {
|
|
|
+ event.node.res.setHeader(name, value);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return response.body;
|
|
|
+ });
|
|
|
+}
|
|
|
+function cloneWithProxy(obj, overrides) {
|
|
|
+ return new Proxy(obj, {
|
|
|
+ get(target, property, receiver) {
|
|
|
+ if (property in overrides) {
|
|
|
+ return overrides[property];
|
|
|
+ }
|
|
|
+ return Reflect.get(target, property, receiver);
|
|
|
+ },
|
|
|
+ set(target, property, value, receiver) {
|
|
|
+ if (property in overrides) {
|
|
|
+ overrides[property] = value;
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ return Reflect.set(target, property, value, receiver);
|
|
|
+ }
|
|
|
+ });
|
|
|
+}
|
|
|
+const cachedEventHandler = defineCachedEventHandler;
|
|
|
+
|
|
|
+const inlineAppConfig = {};
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+const appConfig = defuFn(inlineAppConfig);
|
|
|
+
|
|
|
+function getEnv(key, opts) {
|
|
|
+ const envKey = snakeCase(key).toUpperCase();
|
|
|
+ return destr(
|
|
|
+ process.env[opts.prefix + envKey] ?? process.env[opts.altPrefix + envKey]
|
|
|
+ );
|
|
|
+}
|
|
|
+function _isObject(input) {
|
|
|
+ return typeof input === "object" && !Array.isArray(input);
|
|
|
+}
|
|
|
+function applyEnv(obj, opts, parentKey = "") {
|
|
|
+ for (const key in obj) {
|
|
|
+ const subKey = parentKey ? `${parentKey}_${key}` : key;
|
|
|
+ const envValue = getEnv(subKey, opts);
|
|
|
+ if (_isObject(obj[key])) {
|
|
|
+ if (_isObject(envValue)) {
|
|
|
+ obj[key] = { ...obj[key], ...envValue };
|
|
|
+ applyEnv(obj[key], opts, subKey);
|
|
|
+ } else if (envValue === void 0) {
|
|
|
+ applyEnv(obj[key], opts, subKey);
|
|
|
+ } else {
|
|
|
+ obj[key] = envValue ?? obj[key];
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ obj[key] = envValue ?? obj[key];
|
|
|
+ }
|
|
|
+ if (opts.envExpansion && typeof obj[key] === "string") {
|
|
|
+ obj[key] = _expandFromEnv(obj[key]);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return obj;
|
|
|
+}
|
|
|
+const envExpandRx = /\{\{([^{}]*)\}\}/g;
|
|
|
+function _expandFromEnv(value) {
|
|
|
+ return value.replace(envExpandRx, (match, key) => {
|
|
|
+ return process.env[key] || match;
|
|
|
+ });
|
|
|
+}
|
|
|
+
|
|
|
+const _inlineRuntimeConfig = {
|
|
|
+ "app": {
|
|
|
+ "baseURL": "/"
|
|
|
+ },
|
|
|
+ "nitro": {
|
|
|
+ "routeRules": {
|
|
|
+ "/api/**": {
|
|
|
+ "cors": true,
|
|
|
+ "headers": {
|
|
|
+ "access-control-allow-origin": "*",
|
|
|
+ "access-control-allow-methods": "*",
|
|
|
+ "access-control-allow-headers": "*",
|
|
|
+ "access-control-max-age": "0",
|
|
|
+ "Access-Control-Allow-Credentials": "true",
|
|
|
+ "Access-Control-Allow-Headers": "Accept, Authorization, Content-Length, Content-Type, If-Match, If-Modified-Since, If-None-Match, If-Unmodified-Since, X-CSRF-TOKEN, X-Requested-With",
|
|
|
+ "Access-Control-Allow-Methods": "GET,HEAD,PUT,PATCH,POST,DELETE",
|
|
|
+ "Access-Control-Allow-Origin": "*",
|
|
|
+ "Access-Control-Expose-Headers": "*"
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+};
|
|
|
+const envOptions = {
|
|
|
+ prefix: "NITRO_",
|
|
|
+ altPrefix: _inlineRuntimeConfig.nitro.envPrefix ?? process.env.NITRO_ENV_PREFIX ?? "_",
|
|
|
+ envExpansion: _inlineRuntimeConfig.nitro.envExpansion ?? process.env.NITRO_ENV_EXPANSION ?? false
|
|
|
+};
|
|
|
+const _sharedRuntimeConfig = _deepFreeze(
|
|
|
+ applyEnv(klona(_inlineRuntimeConfig), envOptions)
|
|
|
+);
|
|
|
+function useRuntimeConfig(event) {
|
|
|
+ {
|
|
|
+ return _sharedRuntimeConfig;
|
|
|
+ }
|
|
|
+}
|
|
|
+_deepFreeze(klona(appConfig));
|
|
|
+function _deepFreeze(object) {
|
|
|
+ const propNames = Object.getOwnPropertyNames(object);
|
|
|
+ for (const name of propNames) {
|
|
|
+ const value = object[name];
|
|
|
+ if (value && typeof value === "object") {
|
|
|
+ _deepFreeze(value);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return Object.freeze(object);
|
|
|
+}
|
|
|
+new Proxy(/* @__PURE__ */ Object.create(null), {
|
|
|
+ get: (_, prop) => {
|
|
|
+ console.warn(
|
|
|
+ "Please use `useRuntimeConfig()` instead of accessing config directly."
|
|
|
+ );
|
|
|
+ const runtimeConfig = useRuntimeConfig();
|
|
|
+ if (prop in runtimeConfig) {
|
|
|
+ return runtimeConfig[prop];
|
|
|
+ }
|
|
|
+ return void 0;
|
|
|
+ }
|
|
|
+});
|
|
|
+
|
|
|
+getContext("nitro-app", {
|
|
|
+ asyncContext: undefined,
|
|
|
+ AsyncLocalStorage: void 0
|
|
|
+});
|
|
|
+
|
|
|
+const config = useRuntimeConfig();
|
|
|
+const _routeRulesMatcher = toRouteMatcher(
|
|
|
+ createRouter({ routes: config.nitro.routeRules })
|
|
|
+);
|
|
|
+function createRouteRulesHandler(ctx) {
|
|
|
+ return eventHandler((event) => {
|
|
|
+ const routeRules = getRouteRules(event);
|
|
|
+ if (routeRules.headers) {
|
|
|
+ setHeaders(event, routeRules.headers);
|
|
|
+ }
|
|
|
+ if (routeRules.redirect) {
|
|
|
+ let target = routeRules.redirect.to;
|
|
|
+ if (target.endsWith("/**")) {
|
|
|
+ let targetPath = event.path;
|
|
|
+ const strpBase = routeRules.redirect._redirectStripBase;
|
|
|
+ if (strpBase) {
|
|
|
+ targetPath = withoutBase(targetPath, strpBase);
|
|
|
+ }
|
|
|
+ target = joinURL(target.slice(0, -3), targetPath);
|
|
|
+ } else if (event.path.includes("?")) {
|
|
|
+ const query = getQuery(event.path);
|
|
|
+ target = withQuery(target, query);
|
|
|
+ }
|
|
|
+ return sendRedirect(event, target, routeRules.redirect.statusCode);
|
|
|
+ }
|
|
|
+ if (routeRules.proxy) {
|
|
|
+ let target = routeRules.proxy.to;
|
|
|
+ if (target.endsWith("/**")) {
|
|
|
+ let targetPath = event.path;
|
|
|
+ const strpBase = routeRules.proxy._proxyStripBase;
|
|
|
+ if (strpBase) {
|
|
|
+ targetPath = withoutBase(targetPath, strpBase);
|
|
|
+ }
|
|
|
+ target = joinURL(target.slice(0, -3), targetPath);
|
|
|
+ } else if (event.path.includes("?")) {
|
|
|
+ const query = getQuery(event.path);
|
|
|
+ target = withQuery(target, query);
|
|
|
+ }
|
|
|
+ return proxyRequest(event, target, {
|
|
|
+ fetch: ctx.localFetch,
|
|
|
+ ...routeRules.proxy
|
|
|
+ });
|
|
|
+ }
|
|
|
+ });
|
|
|
+}
|
|
|
+function getRouteRules(event) {
|
|
|
+ event.context._nitro = event.context._nitro || {};
|
|
|
+ if (!event.context._nitro.routeRules) {
|
|
|
+ event.context._nitro.routeRules = getRouteRulesForPath(
|
|
|
+ withoutBase(event.path.split("?")[0], useRuntimeConfig().app.baseURL)
|
|
|
+ );
|
|
|
+ }
|
|
|
+ return event.context._nitro.routeRules;
|
|
|
+}
|
|
|
+function getRouteRulesForPath(path) {
|
|
|
+ return defu({}, ..._routeRulesMatcher.matchAll(path).reverse());
|
|
|
+}
|
|
|
+
|
|
|
+function _captureError(error, type) {
|
|
|
+ console.error(`[${type}]`, error);
|
|
|
+ useNitroApp().captureError(error, { tags: [type] });
|
|
|
+}
|
|
|
+function trapUnhandledNodeErrors() {
|
|
|
+ process.on(
|
|
|
+ "unhandledRejection",
|
|
|
+ (error) => _captureError(error, "unhandledRejection")
|
|
|
+ );
|
|
|
+ process.on(
|
|
|
+ "uncaughtException",
|
|
|
+ (error) => _captureError(error, "uncaughtException")
|
|
|
+ );
|
|
|
+}
|
|
|
+function joinHeaders(value) {
|
|
|
+ return Array.isArray(value) ? value.join(", ") : String(value);
|
|
|
+}
|
|
|
+function normalizeFetchResponse(response) {
|
|
|
+ if (!response.headers.has("set-cookie")) {
|
|
|
+ return response;
|
|
|
+ }
|
|
|
+ return new Response(response.body, {
|
|
|
+ status: response.status,
|
|
|
+ statusText: response.statusText,
|
|
|
+ headers: normalizeCookieHeaders(response.headers)
|
|
|
+ });
|
|
|
+}
|
|
|
+function normalizeCookieHeader(header = "") {
|
|
|
+ return splitCookiesString(joinHeaders(header));
|
|
|
+}
|
|
|
+function normalizeCookieHeaders(headers) {
|
|
|
+ const outgoingHeaders = new Headers();
|
|
|
+ for (const [name, header] of headers) {
|
|
|
+ if (name === "set-cookie") {
|
|
|
+ for (const cookie of normalizeCookieHeader(header)) {
|
|
|
+ outgoingHeaders.append("set-cookie", cookie);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ outgoingHeaders.set(name, joinHeaders(header));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return outgoingHeaders;
|
|
|
+}
|
|
|
+
|
|
|
+const errorHandler$2 = function(error, event) {
|
|
|
+ event.node.res.end(`[Error Handler] ${error.stack}`);
|
|
|
+};
|
|
|
+
|
|
|
+function defineNitroErrorHandler(handler) {
|
|
|
+ return handler;
|
|
|
+}
|
|
|
+
|
|
|
+const errorHandler$1 = defineNitroErrorHandler(
|
|
|
+ async function defaultNitroErrorHandler(error, event) {
|
|
|
+ const res = await defaultHandler(error, event);
|
|
|
+ if (!event.node?.res.headersSent) {
|
|
|
+ setResponseHeaders(event, res.headers);
|
|
|
+ }
|
|
|
+ setResponseStatus(event, res.status, res.statusText);
|
|
|
+ return send(
|
|
|
+ event,
|
|
|
+ typeof res.body === "string" ? res.body : JSON.stringify(res.body, null, 2)
|
|
|
+ );
|
|
|
+ }
|
|
|
+);
|
|
|
+async function defaultHandler(error, event, opts) {
|
|
|
+ const isSensitive = error.unhandled || error.fatal;
|
|
|
+ const statusCode = error.statusCode || 500;
|
|
|
+ const statusMessage = error.statusMessage || "Server Error";
|
|
|
+ const url = getRequestURL(event, { xForwardedHost: true, xForwardedProto: true });
|
|
|
+ if (statusCode === 404) {
|
|
|
+ const baseURL = "/";
|
|
|
+ if (/^\/[^/]/.test(baseURL) && !url.pathname.startsWith(baseURL)) {
|
|
|
+ const redirectTo = `${baseURL}${url.pathname.slice(1)}${url.search}`;
|
|
|
+ return {
|
|
|
+ status: 302,
|
|
|
+ statusText: "Found",
|
|
|
+ headers: { location: redirectTo },
|
|
|
+ body: `Redirecting...`
|
|
|
+ };
|
|
|
+ }
|
|
|
+ }
|
|
|
+ await loadStackTrace(error).catch(consola.error);
|
|
|
+ const youch = new Youch();
|
|
|
+ if (isSensitive && !opts?.silent) {
|
|
|
+ const tags = [error.unhandled && "[unhandled]", error.fatal && "[fatal]"].filter(Boolean).join(" ");
|
|
|
+ const ansiError = await (await youch.toANSI(error)).replaceAll(process.cwd(), ".");
|
|
|
+ consola.error(
|
|
|
+ `[request error] ${tags} [${event.method}] ${url}
|
|
|
+
|
|
|
+`,
|
|
|
+ ansiError
|
|
|
+ );
|
|
|
+ }
|
|
|
+ const useJSON = opts?.json || !getRequestHeader(event, "accept")?.includes("text/html");
|
|
|
+ const headers = {
|
|
|
+ "content-type": useJSON ? "application/json" : "text/html",
|
|
|
+ // Prevent browser from guessing the MIME types of resources.
|
|
|
+ "x-content-type-options": "nosniff",
|
|
|
+ // Prevent error page from being embedded in an iframe
|
|
|
+ "x-frame-options": "DENY",
|
|
|
+ // Prevent browsers from sending the Referer header
|
|
|
+ "referrer-policy": "no-referrer",
|
|
|
+ // Disable the execution of any js
|
|
|
+ "content-security-policy": "script-src 'self' 'unsafe-inline'; object-src 'none'; base-uri 'self';"
|
|
|
+ };
|
|
|
+ if (statusCode === 404 || !getResponseHeader(event, "cache-control")) {
|
|
|
+ headers["cache-control"] = "no-cache";
|
|
|
+ }
|
|
|
+ const body = useJSON ? {
|
|
|
+ error: true,
|
|
|
+ url,
|
|
|
+ statusCode,
|
|
|
+ statusMessage,
|
|
|
+ message: error.message,
|
|
|
+ data: error.data,
|
|
|
+ stack: error.stack?.split("\n").map((line) => line.trim())
|
|
|
+ } : await youch.toHTML(error, {
|
|
|
+ request: {
|
|
|
+ url: url.href,
|
|
|
+ method: event.method,
|
|
|
+ headers: getRequestHeaders(event)
|
|
|
+ }
|
|
|
+ });
|
|
|
+ return {
|
|
|
+ status: statusCode,
|
|
|
+ statusText: statusMessage,
|
|
|
+ headers,
|
|
|
+ body
|
|
|
+ };
|
|
|
+}
|
|
|
+async function loadStackTrace(error) {
|
|
|
+ if (!(error instanceof Error)) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ const parsed = await new ErrorParser().defineSourceLoader(sourceLoader).parse(error);
|
|
|
+ const stack = error.message + "\n" + parsed.frames.map((frame) => fmtFrame(frame)).join("\n");
|
|
|
+ Object.defineProperty(error, "stack", { value: stack });
|
|
|
+ if (error.cause) {
|
|
|
+ await loadStackTrace(error.cause).catch(consola.error);
|
|
|
+ }
|
|
|
+}
|
|
|
+async function sourceLoader(frame) {
|
|
|
+ if (!frame.fileName || frame.fileType !== "fs" || frame.type === "native") {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (frame.type === "app") {
|
|
|
+ const rawSourceMap = await readFile(`${frame.fileName}.map`, "utf8").catch(() => {
|
|
|
+ });
|
|
|
+ if (rawSourceMap) {
|
|
|
+ const consumer = await new SourceMapConsumer(rawSourceMap);
|
|
|
+ const originalPosition = consumer.originalPositionFor({ line: frame.lineNumber, column: frame.columnNumber });
|
|
|
+ if (originalPosition.source && originalPosition.line) {
|
|
|
+ frame.fileName = resolve(dirname(frame.fileName), originalPosition.source);
|
|
|
+ frame.lineNumber = originalPosition.line;
|
|
|
+ frame.columnNumber = originalPosition.column || 0;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ const contents = await readFile(frame.fileName, "utf8").catch(() => {
|
|
|
+ });
|
|
|
+ return contents ? { contents } : void 0;
|
|
|
+}
|
|
|
+function fmtFrame(frame) {
|
|
|
+ if (frame.type === "native") {
|
|
|
+ return frame.raw;
|
|
|
+ }
|
|
|
+ const src = `${frame.fileName || ""}:${frame.lineNumber}:${frame.columnNumber})`;
|
|
|
+ return frame.functionName ? `at ${frame.functionName} (${src}` : `at ${src}`;
|
|
|
+}
|
|
|
+
|
|
|
+const errorHandlers = [errorHandler$2, errorHandler$1];
|
|
|
+
|
|
|
+async function errorHandler(error, event) {
|
|
|
+ for (const handler of errorHandlers) {
|
|
|
+ try {
|
|
|
+ await handler(error, event, { defaultHandler });
|
|
|
+ if (event.handled) {
|
|
|
+ return; // Response handled
|
|
|
+ }
|
|
|
+ } catch(error) {
|
|
|
+ // Handler itself thrown, log and continue
|
|
|
+ console.error(error);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // H3 will handle fallback
|
|
|
+}
|
|
|
+
|
|
|
+const plugins = [
|
|
|
+
|
|
|
+];
|
|
|
+
|
|
|
+function useResponseSuccess(data) {
|
|
|
+ return {
|
|
|
+ code: 0,
|
|
|
+ data,
|
|
|
+ error: null,
|
|
|
+ message: "ok"
|
|
|
+ };
|
|
|
+}
|
|
|
+function usePageResponseSuccess(page, pageSize, list, { message = "ok" } = {}) {
|
|
|
+ const pageData = pagination(
|
|
|
+ Number.parseInt(`${page}`),
|
|
|
+ Number.parseInt(`${pageSize}`),
|
|
|
+ list
|
|
|
+ );
|
|
|
+ return {
|
|
|
+ ...useResponseSuccess({
|
|
|
+ items: pageData,
|
|
|
+ total: list.length
|
|
|
+ }),
|
|
|
+ message
|
|
|
+ };
|
|
|
+}
|
|
|
+function useResponseError(message, error = null) {
|
|
|
+ return {
|
|
|
+ code: -1,
|
|
|
+ data: null,
|
|
|
+ error,
|
|
|
+ message
|
|
|
+ };
|
|
|
+}
|
|
|
+function forbiddenResponse(event, message = "Forbidden Exception") {
|
|
|
+ setResponseStatus(event, 403);
|
|
|
+ return useResponseError(message, message);
|
|
|
+}
|
|
|
+function unAuthorizedResponse(event) {
|
|
|
+ setResponseStatus(event, 401);
|
|
|
+ return useResponseError("Unauthorized Exception", "Unauthorized Exception");
|
|
|
+}
|
|
|
+function sleep(ms) {
|
|
|
+ return new Promise((resolve) => setTimeout(resolve, ms));
|
|
|
+}
|
|
|
+function pagination(pageNo, pageSize, array) {
|
|
|
+ const offset = (pageNo - 1) * Number(pageSize);
|
|
|
+ return offset + Number(pageSize) >= array.length ? array.slice(offset) : array.slice(offset, offset + Number(pageSize));
|
|
|
+}
|
|
|
+
|
|
|
+const _3Kb7Di = defineEventHandler(async (event) => {
|
|
|
+ var _a;
|
|
|
+ event.node.res.setHeader(
|
|
|
+ "Access-Control-Allow-Origin",
|
|
|
+ (_a = event.headers.get("Origin")) != null ? _a : "*"
|
|
|
+ );
|
|
|
+ if (event.method === "OPTIONS") {
|
|
|
+ event.node.res.statusCode = 204;
|
|
|
+ event.node.res.statusMessage = "No Content.";
|
|
|
+ return "OK";
|
|
|
+ } else if (["DELETE", "PATCH", "POST", "PUT"].includes(event.method) && event.path.startsWith("/api/system/")) {
|
|
|
+ await sleep(Math.floor(Math.random() * 2e3));
|
|
|
+ return forbiddenResponse(event, "\u6F14\u793A\u73AF\u5883\uFF0C\u7981\u6B62\u4FEE\u6539");
|
|
|
+ }
|
|
|
+});
|
|
|
+
|
|
|
+const _lazy_Cjg2LV = () => Promise.resolve().then(function () { return codes$1; });
|
|
|
+const _lazy_rtEwLH = () => Promise.resolve().then(function () { return login_post$1; });
|
|
|
+const _lazy_HQfk2e = () => Promise.resolve().then(function () { return logout_post$1; });
|
|
|
+const _lazy_LV4MmU = () => Promise.resolve().then(function () { return refresh_post$1; });
|
|
|
+const _lazy_hTfDqU = () => Promise.resolve().then(function () { return bigint$1; });
|
|
|
+const _lazy_d4BSOr = () => Promise.resolve().then(function () { return all$1; });
|
|
|
+const _lazy_r9rMys = () => Promise.resolve().then(function () { return status$1; });
|
|
|
+const _lazy_QIRnpN = () => Promise.resolve().then(function () { return _post$1; });
|
|
|
+const _lazy_WxQT4N = () => Promise.resolve().then(function () { return _id__delete$1; });
|
|
|
+const _lazy_DthOu8 = () => Promise.resolve().then(function () { return _id__put$1; });
|
|
|
+const _lazy_9OBCpg = () => Promise.resolve().then(function () { return list$7; });
|
|
|
+const _lazy_UM7Fl_ = () => Promise.resolve().then(function () { return list$5; });
|
|
|
+const _lazy_fqwdxs = () => Promise.resolve().then(function () { return nameExists$1; });
|
|
|
+const _lazy_I47CY1 = () => Promise.resolve().then(function () { return pathExists$1; });
|
|
|
+const _lazy_oMtqRm = () => Promise.resolve().then(function () { return list$3; });
|
|
|
+const _lazy_R0gwfL = () => Promise.resolve().then(function () { return list$1; });
|
|
|
+const _lazy_DbYADR = () => Promise.resolve().then(function () { return test_get$1; });
|
|
|
+const _lazy_Tjiaxz = () => Promise.resolve().then(function () { return test_post$1; });
|
|
|
+const _lazy_Ut5b2V = () => Promise.resolve().then(function () { return upload$1; });
|
|
|
+const _lazy_NDYxuW = () => Promise.resolve().then(function () { return info$1; });
|
|
|
+const _lazy_IBn8TT = () => Promise.resolve().then(function () { return _____$1; });
|
|
|
+
|
|
|
+const handlers = [
|
|
|
+ { route: '', handler: _3Kb7Di, lazy: false, middleware: true, method: undefined },
|
|
|
+ { route: '/api/auth/codes', handler: _lazy_Cjg2LV, lazy: true, middleware: false, method: undefined },
|
|
|
+ { route: '/api/auth/login', handler: _lazy_rtEwLH, lazy: true, middleware: false, method: "post" },
|
|
|
+ { route: '/api/auth/logout', handler: _lazy_HQfk2e, lazy: true, middleware: false, method: "post" },
|
|
|
+ { route: '/api/auth/refresh', handler: _lazy_LV4MmU, lazy: true, middleware: false, method: "post" },
|
|
|
+ { route: '/api/demo/bigint', handler: _lazy_hTfDqU, lazy: true, middleware: false, method: undefined },
|
|
|
+ { route: '/api/menu/all', handler: _lazy_d4BSOr, lazy: true, middleware: false, method: undefined },
|
|
|
+ { route: '/api/status', handler: _lazy_r9rMys, lazy: true, middleware: false, method: undefined },
|
|
|
+ { route: '/api/system/dept/', handler: _lazy_QIRnpN, lazy: true, middleware: false, method: "post" },
|
|
|
+ { route: '/api/system/dept/:id', handler: _lazy_WxQT4N, lazy: true, middleware: false, method: "delete" },
|
|
|
+ { route: '/api/system/dept/:id', handler: _lazy_DthOu8, lazy: true, middleware: false, method: "put" },
|
|
|
+ { route: '/api/system/dept/list', handler: _lazy_9OBCpg, lazy: true, middleware: false, method: undefined },
|
|
|
+ { route: '/api/system/menu/list', handler: _lazy_UM7Fl_, lazy: true, middleware: false, method: undefined },
|
|
|
+ { route: '/api/system/menu/name-exists', handler: _lazy_fqwdxs, lazy: true, middleware: false, method: undefined },
|
|
|
+ { route: '/api/system/menu/path-exists', handler: _lazy_I47CY1, lazy: true, middleware: false, method: undefined },
|
|
|
+ { route: '/api/system/role/list', handler: _lazy_oMtqRm, lazy: true, middleware: false, method: undefined },
|
|
|
+ { route: '/api/table/list', handler: _lazy_R0gwfL, lazy: true, middleware: false, method: undefined },
|
|
|
+ { route: '/api/test', handler: _lazy_DbYADR, lazy: true, middleware: false, method: "get" },
|
|
|
+ { route: '/api/test', handler: _lazy_Tjiaxz, lazy: true, middleware: false, method: "post" },
|
|
|
+ { route: '/api/upload', handler: _lazy_Ut5b2V, lazy: true, middleware: false, method: undefined },
|
|
|
+ { route: '/api/user/info', handler: _lazy_NDYxuW, lazy: true, middleware: false, method: undefined },
|
|
|
+ { route: '/**', handler: _lazy_IBn8TT, lazy: true, middleware: false, method: undefined }
|
|
|
+];
|
|
|
+
|
|
|
+function createNitroApp() {
|
|
|
+ const config = useRuntimeConfig();
|
|
|
+ const hooks = createHooks();
|
|
|
+ const captureError = (error, context = {}) => {
|
|
|
+ const promise = hooks.callHookParallel("error", error, context).catch((error_) => {
|
|
|
+ console.error("Error while capturing another error", error_);
|
|
|
+ });
|
|
|
+ if (context.event && isEvent(context.event)) {
|
|
|
+ const errors = context.event.context.nitro?.errors;
|
|
|
+ if (errors) {
|
|
|
+ errors.push({ error, context });
|
|
|
+ }
|
|
|
+ if (context.event.waitUntil) {
|
|
|
+ context.event.waitUntil(promise);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ };
|
|
|
+ const h3App = createApp({
|
|
|
+ debug: destr(true),
|
|
|
+ onError: (error, event) => {
|
|
|
+ captureError(error, { event, tags: ["request"] });
|
|
|
+ return errorHandler(error, event);
|
|
|
+ },
|
|
|
+ onRequest: async (event) => {
|
|
|
+ event.context.nitro = event.context.nitro || { errors: [] };
|
|
|
+ const fetchContext = event.node.req?.__unenv__;
|
|
|
+ if (fetchContext?._platform) {
|
|
|
+ event.context = {
|
|
|
+ _platform: fetchContext?._platform,
|
|
|
+ // #3335
|
|
|
+ ...fetchContext._platform,
|
|
|
+ ...event.context
|
|
|
+ };
|
|
|
+ }
|
|
|
+ if (!event.context.waitUntil && fetchContext?.waitUntil) {
|
|
|
+ event.context.waitUntil = fetchContext.waitUntil;
|
|
|
+ }
|
|
|
+ event.fetch = (req, init) => fetchWithEvent(event, req, init, { fetch: localFetch });
|
|
|
+ event.$fetch = (req, init) => fetchWithEvent(event, req, init, {
|
|
|
+ fetch: $fetch
|
|
|
+ });
|
|
|
+ event.waitUntil = (promise) => {
|
|
|
+ if (!event.context.nitro._waitUntilPromises) {
|
|
|
+ event.context.nitro._waitUntilPromises = [];
|
|
|
+ }
|
|
|
+ event.context.nitro._waitUntilPromises.push(promise);
|
|
|
+ if (event.context.waitUntil) {
|
|
|
+ event.context.waitUntil(promise);
|
|
|
+ }
|
|
|
+ };
|
|
|
+ event.captureError = (error, context) => {
|
|
|
+ captureError(error, { event, ...context });
|
|
|
+ };
|
|
|
+ await nitroApp$1.hooks.callHook("request", event).catch((error) => {
|
|
|
+ captureError(error, { event, tags: ["request"] });
|
|
|
+ });
|
|
|
+ },
|
|
|
+ onBeforeResponse: async (event, response) => {
|
|
|
+ await nitroApp$1.hooks.callHook("beforeResponse", event, response).catch((error) => {
|
|
|
+ captureError(error, { event, tags: ["request", "response"] });
|
|
|
+ });
|
|
|
+ },
|
|
|
+ onAfterResponse: async (event, response) => {
|
|
|
+ await nitroApp$1.hooks.callHook("afterResponse", event, response).catch((error) => {
|
|
|
+ captureError(error, { event, tags: ["request", "response"] });
|
|
|
+ });
|
|
|
+ }
|
|
|
+ });
|
|
|
+ const router = createRouter$1({
|
|
|
+ preemptive: true
|
|
|
+ });
|
|
|
+ const nodeHandler = toNodeListener(h3App);
|
|
|
+ const localCall = (aRequest) => callNodeRequestHandler(nodeHandler, aRequest);
|
|
|
+ const localFetch = (input, init) => {
|
|
|
+ if (!input.toString().startsWith("/")) {
|
|
|
+ return globalThis.fetch(input, init);
|
|
|
+ }
|
|
|
+ return fetchNodeRequestHandler(
|
|
|
+ nodeHandler,
|
|
|
+ input,
|
|
|
+ init
|
|
|
+ ).then((response) => normalizeFetchResponse(response));
|
|
|
+ };
|
|
|
+ const $fetch = createFetch({
|
|
|
+ fetch: localFetch,
|
|
|
+ Headers: Headers$1,
|
|
|
+ defaults: { baseURL: config.app.baseURL }
|
|
|
+ });
|
|
|
+ globalThis.$fetch = $fetch;
|
|
|
+ h3App.use(createRouteRulesHandler({ localFetch }));
|
|
|
+ for (const h of handlers) {
|
|
|
+ let handler = h.lazy ? lazyEventHandler(h.handler) : h.handler;
|
|
|
+ if (h.middleware || !h.route) {
|
|
|
+ const middlewareBase = (config.app.baseURL + (h.route || "/")).replace(
|
|
|
+ /\/+/g,
|
|
|
+ "/"
|
|
|
+ );
|
|
|
+ h3App.use(middlewareBase, handler);
|
|
|
+ } else {
|
|
|
+ const routeRules = getRouteRulesForPath(
|
|
|
+ h.route.replace(/:\w+|\*\*/g, "_")
|
|
|
+ );
|
|
|
+ if (routeRules.cache) {
|
|
|
+ handler = cachedEventHandler(handler, {
|
|
|
+ group: "nitro/routes",
|
|
|
+ ...routeRules.cache
|
|
|
+ });
|
|
|
+ }
|
|
|
+ router.use(h.route, handler, h.method);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ h3App.use(config.app.baseURL, router.handler);
|
|
|
+ const app = {
|
|
|
+ hooks,
|
|
|
+ h3App,
|
|
|
+ router,
|
|
|
+ localCall,
|
|
|
+ localFetch,
|
|
|
+ captureError
|
|
|
+ };
|
|
|
+ return app;
|
|
|
+}
|
|
|
+function runNitroPlugins(nitroApp2) {
|
|
|
+ for (const plugin of plugins) {
|
|
|
+ try {
|
|
|
+ plugin(nitroApp2);
|
|
|
+ } catch (error) {
|
|
|
+ nitroApp2.captureError(error, { tags: ["plugin"] });
|
|
|
+ throw error;
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+const nitroApp$1 = createNitroApp();
|
|
|
+function useNitroApp() {
|
|
|
+ return nitroApp$1;
|
|
|
+}
|
|
|
+runNitroPlugins(nitroApp$1);
|
|
|
+
|
|
|
+const scheduledTasks = false;
|
|
|
+
|
|
|
+const tasks = {
|
|
|
+
|
|
|
+};
|
|
|
+
|
|
|
+const __runningTasks__ = {};
|
|
|
+async function runTask(name, {
|
|
|
+ payload = {},
|
|
|
+ context = {}
|
|
|
+} = {}) {
|
|
|
+ if (__runningTasks__[name]) {
|
|
|
+ return __runningTasks__[name];
|
|
|
+ }
|
|
|
+ if (!(name in tasks)) {
|
|
|
+ throw createError({
|
|
|
+ message: `Task \`${name}\` is not available!`,
|
|
|
+ statusCode: 404
|
|
|
+ });
|
|
|
+ }
|
|
|
+ if (!tasks[name].resolve) {
|
|
|
+ throw createError({
|
|
|
+ message: `Task \`${name}\` is not implemented!`,
|
|
|
+ statusCode: 501
|
|
|
+ });
|
|
|
+ }
|
|
|
+ const handler = await tasks[name].resolve();
|
|
|
+ const taskEvent = { name, payload, context };
|
|
|
+ __runningTasks__[name] = handler.run(taskEvent);
|
|
|
+ try {
|
|
|
+ const res = await __runningTasks__[name];
|
|
|
+ return res;
|
|
|
+ } finally {
|
|
|
+ delete __runningTasks__[name];
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+if (!globalThis.crypto) {
|
|
|
+ globalThis.crypto = nodeCrypto;
|
|
|
+}
|
|
|
+const { NITRO_NO_UNIX_SOCKET, NITRO_DEV_WORKER_ID } = process.env;
|
|
|
+trapUnhandledNodeErrors();
|
|
|
+parentPort?.on("message", (msg) => {
|
|
|
+ if (msg && msg.event === "shutdown") {
|
|
|
+ shutdown();
|
|
|
+ }
|
|
|
+});
|
|
|
+const nitroApp = useNitroApp();
|
|
|
+const server = new Server(toNodeListener(nitroApp.h3App));
|
|
|
+let listener;
|
|
|
+listen().catch(() => listen(
|
|
|
+ true
|
|
|
+ /* use random port */
|
|
|
+)).catch((error) => {
|
|
|
+ console.error("Dev worker failed to listen:", error);
|
|
|
+ return shutdown();
|
|
|
+});
|
|
|
+nitroApp.router.get(
|
|
|
+ "/_nitro/tasks",
|
|
|
+ defineEventHandler(async (event) => {
|
|
|
+ const _tasks = await Promise.all(
|
|
|
+ Object.entries(tasks).map(async ([name, task]) => {
|
|
|
+ const _task = await task.resolve?.();
|
|
|
+ return [name, { description: _task?.meta?.description }];
|
|
|
+ })
|
|
|
+ );
|
|
|
+ return {
|
|
|
+ tasks: Object.fromEntries(_tasks),
|
|
|
+ scheduledTasks
|
|
|
+ };
|
|
|
+ })
|
|
|
+);
|
|
|
+nitroApp.router.use(
|
|
|
+ "/_nitro/tasks/:name",
|
|
|
+ defineEventHandler(async (event) => {
|
|
|
+ const name = getRouterParam(event, "name");
|
|
|
+ const payload = {
|
|
|
+ ...getQuery$1(event),
|
|
|
+ ...await readBody(event).then((r) => r?.payload).catch(() => ({}))
|
|
|
+ };
|
|
|
+ return await runTask(name, { payload });
|
|
|
+ })
|
|
|
+);
|
|
|
+function listen(useRandomPort = Boolean(
|
|
|
+ NITRO_NO_UNIX_SOCKET || process.versions.webcontainer || "Bun" in globalThis && process.platform === "win32"
|
|
|
+)) {
|
|
|
+ return new Promise((resolve, reject) => {
|
|
|
+ try {
|
|
|
+ listener = server.listen(useRandomPort ? 0 : getSocketAddress(), () => {
|
|
|
+ const address = server.address();
|
|
|
+ parentPort?.postMessage({
|
|
|
+ event: "listen",
|
|
|
+ address: typeof address === "string" ? { socketPath: address } : { host: "localhost", port: address?.port }
|
|
|
+ });
|
|
|
+ resolve();
|
|
|
+ });
|
|
|
+ } catch (error) {
|
|
|
+ reject(error);
|
|
|
+ }
|
|
|
+ });
|
|
|
+}
|
|
|
+function getSocketAddress() {
|
|
|
+ const socketName = `nitro-worker-${process.pid}-${threadId}-${NITRO_DEV_WORKER_ID}-${Math.round(Math.random() * 1e4)}.sock`;
|
|
|
+ if (process.platform === "win32") {
|
|
|
+ return join(String.raw`\\.\pipe`, socketName);
|
|
|
+ }
|
|
|
+ if (process.platform === "linux") {
|
|
|
+ const nodeMajor = Number.parseInt(process.versions.node.split(".")[0], 10);
|
|
|
+ if (nodeMajor >= 20) {
|
|
|
+ return `\0${socketName}`;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return join(tmpdir(), socketName);
|
|
|
+}
|
|
|
+async function shutdown() {
|
|
|
+ server.closeAllConnections?.();
|
|
|
+ await Promise.all([
|
|
|
+ new Promise((resolve) => listener?.close(resolve)),
|
|
|
+ nitroApp.hooks.callHook("close").catch(console.error)
|
|
|
+ ]);
|
|
|
+ parentPort?.postMessage({ event: "exit" });
|
|
|
+}
|
|
|
+
|
|
|
+const MOCK_USERS = [
|
|
|
+ {
|
|
|
+ id: 0,
|
|
|
+ password: "123456",
|
|
|
+ realName: "Vben",
|
|
|
+ roles: ["super"],
|
|
|
+ username: "vben"
|
|
|
+ },
|
|
|
+ {
|
|
|
+ id: 1,
|
|
|
+ password: "123456",
|
|
|
+ realName: "Admin",
|
|
|
+ roles: ["admin"],
|
|
|
+ username: "admin",
|
|
|
+ homePath: "/workspace"
|
|
|
+ },
|
|
|
+ {
|
|
|
+ id: 2,
|
|
|
+ password: "123456",
|
|
|
+ realName: "Jack",
|
|
|
+ roles: ["user"],
|
|
|
+ username: "jack",
|
|
|
+ homePath: "/analytics"
|
|
|
+ }
|
|
|
+];
|
|
|
+const MOCK_CODES = [
|
|
|
+ // super
|
|
|
+ {
|
|
|
+ codes: ["AC_100100", "AC_100110", "AC_100120", "AC_100010"],
|
|
|
+ username: "vben"
|
|
|
+ },
|
|
|
+ {
|
|
|
+ // admin
|
|
|
+ codes: ["AC_100010", "AC_100020", "AC_100030"],
|
|
|
+ username: "admin"
|
|
|
+ },
|
|
|
+ {
|
|
|
+ // user
|
|
|
+ codes: ["AC_1000001", "AC_1000002"],
|
|
|
+ username: "jack"
|
|
|
+ }
|
|
|
+];
|
|
|
+const dashboardMenus = [
|
|
|
+ {
|
|
|
+ meta: {
|
|
|
+ order: -1,
|
|
|
+ title: "page.dashboard.title"
|
|
|
+ },
|
|
|
+ name: "Dashboard",
|
|
|
+ path: "/dashboard",
|
|
|
+ redirect: "/analytics",
|
|
|
+ children: [
|
|
|
+ {
|
|
|
+ name: "Analytics",
|
|
|
+ path: "/analytics",
|
|
|
+ component: "/dashboard/analytics/index",
|
|
|
+ meta: {
|
|
|
+ affixTab: true,
|
|
|
+ title: "page.dashboard.analytics"
|
|
|
+ }
|
|
|
+ },
|
|
|
+ {
|
|
|
+ name: "Workspace",
|
|
|
+ path: "/workspace",
|
|
|
+ component: "/dashboard/workspace/index",
|
|
|
+ meta: {
|
|
|
+ title: "page.dashboard.workspace"
|
|
|
+ }
|
|
|
+ }
|
|
|
+ ]
|
|
|
+ }
|
|
|
+];
|
|
|
+const createDemosMenus = (role) => {
|
|
|
+ const roleWithMenus = {
|
|
|
+ admin: {
|
|
|
+ component: "/demos/access/admin-visible",
|
|
|
+ meta: {
|
|
|
+ icon: "mdi:button-cursor",
|
|
|
+ title: "demos.access.adminVisible"
|
|
|
+ },
|
|
|
+ name: "AccessAdminVisibleDemo",
|
|
|
+ path: "/demos/access/admin-visible"
|
|
|
+ },
|
|
|
+ super: {
|
|
|
+ component: "/demos/access/super-visible",
|
|
|
+ meta: {
|
|
|
+ icon: "mdi:button-cursor",
|
|
|
+ title: "demos.access.superVisible"
|
|
|
+ },
|
|
|
+ name: "AccessSuperVisibleDemo",
|
|
|
+ path: "/demos/access/super-visible"
|
|
|
+ },
|
|
|
+ user: {
|
|
|
+ component: "/demos/access/user-visible",
|
|
|
+ meta: {
|
|
|
+ icon: "mdi:button-cursor",
|
|
|
+ title: "demos.access.userVisible"
|
|
|
+ },
|
|
|
+ name: "AccessUserVisibleDemo",
|
|
|
+ path: "/demos/access/user-visible"
|
|
|
+ }
|
|
|
+ };
|
|
|
+ return [
|
|
|
+ {
|
|
|
+ meta: {
|
|
|
+ icon: "ic:baseline-view-in-ar",
|
|
|
+ keepAlive: true,
|
|
|
+ order: 1e3,
|
|
|
+ title: "demos.title"
|
|
|
+ },
|
|
|
+ name: "Demos",
|
|
|
+ path: "/demos",
|
|
|
+ redirect: "/demos/access",
|
|
|
+ children: [
|
|
|
+ {
|
|
|
+ name: "AccessDemos",
|
|
|
+ path: "/demosaccess",
|
|
|
+ meta: {
|
|
|
+ icon: "mdi:cloud-key-outline",
|
|
|
+ title: "demos.access.backendPermissions"
|
|
|
+ },
|
|
|
+ redirect: "/demos/access/page-control",
|
|
|
+ children: [
|
|
|
+ {
|
|
|
+ name: "AccessPageControlDemo",
|
|
|
+ path: "/demos/access/page-control",
|
|
|
+ component: "/demos/access/index",
|
|
|
+ meta: {
|
|
|
+ icon: "mdi:page-previous-outline",
|
|
|
+ title: "demos.access.pageAccess"
|
|
|
+ }
|
|
|
+ },
|
|
|
+ {
|
|
|
+ name: "AccessButtonControlDemo",
|
|
|
+ path: "/demos/access/button-control",
|
|
|
+ component: "/demos/access/button-control",
|
|
|
+ meta: {
|
|
|
+ icon: "mdi:button-cursor",
|
|
|
+ title: "demos.access.buttonControl"
|
|
|
+ }
|
|
|
+ },
|
|
|
+ {
|
|
|
+ name: "AccessMenuVisible403Demo",
|
|
|
+ path: "/demos/access/menu-visible-403",
|
|
|
+ component: "/demos/access/menu-visible-403",
|
|
|
+ meta: {
|
|
|
+ authority: ["no-body"],
|
|
|
+ icon: "mdi:button-cursor",
|
|
|
+ menuVisibleWithForbidden: true,
|
|
|
+ title: "demos.access.menuVisible403"
|
|
|
+ }
|
|
|
+ },
|
|
|
+ roleWithMenus[role]
|
|
|
+ ]
|
|
|
+ }
|
|
|
+ ]
|
|
|
+ }
|
|
|
+ ];
|
|
|
+};
|
|
|
+const MOCK_MENUS = [
|
|
|
+ {
|
|
|
+ menus: [...dashboardMenus, ...createDemosMenus("super")],
|
|
|
+ username: "vben"
|
|
|
+ },
|
|
|
+ {
|
|
|
+ menus: [...dashboardMenus, ...createDemosMenus("admin")],
|
|
|
+ username: "admin"
|
|
|
+ },
|
|
|
+ {
|
|
|
+ menus: [...dashboardMenus, ...createDemosMenus("user")],
|
|
|
+ username: "jack"
|
|
|
+ }
|
|
|
+];
|
|
|
+const MOCK_MENU_LIST = [
|
|
|
+ {
|
|
|
+ id: 1,
|
|
|
+ name: "Workspace",
|
|
|
+ status: 1,
|
|
|
+ type: "menu",
|
|
|
+ icon: "mdi:dashboard",
|
|
|
+ path: "/workspace",
|
|
|
+ component: "/dashboard/workspace/index",
|
|
|
+ meta: {
|
|
|
+ icon: "carbon:workspace",
|
|
|
+ title: "page.dashboard.workspace",
|
|
|
+ affixTab: true,
|
|
|
+ order: 0
|
|
|
+ }
|
|
|
+ },
|
|
|
+ {
|
|
|
+ id: 2,
|
|
|
+ meta: {
|
|
|
+ icon: "carbon:settings",
|
|
|
+ order: 9997,
|
|
|
+ title: "system.title",
|
|
|
+ badge: "new",
|
|
|
+ badgeType: "normal",
|
|
|
+ badgeVariants: "primary"
|
|
|
+ },
|
|
|
+ status: 1,
|
|
|
+ type: "catalog",
|
|
|
+ name: "System",
|
|
|
+ path: "/system",
|
|
|
+ children: [
|
|
|
+ {
|
|
|
+ id: 201,
|
|
|
+ pid: 2,
|
|
|
+ path: "/system/menu",
|
|
|
+ name: "SystemMenu",
|
|
|
+ authCode: "System:Menu:List",
|
|
|
+ status: 1,
|
|
|
+ type: "menu",
|
|
|
+ meta: {
|
|
|
+ icon: "carbon:menu",
|
|
|
+ title: "system.menu.title"
|
|
|
+ },
|
|
|
+ component: "/system/menu/list",
|
|
|
+ children: [
|
|
|
+ {
|
|
|
+ id: 20101,
|
|
|
+ pid: 201,
|
|
|
+ name: "SystemMenuCreate",
|
|
|
+ status: 1,
|
|
|
+ type: "button",
|
|
|
+ authCode: "System:Menu:Create",
|
|
|
+ meta: { title: "common.create" }
|
|
|
+ },
|
|
|
+ {
|
|
|
+ id: 20102,
|
|
|
+ pid: 201,
|
|
|
+ name: "SystemMenuEdit",
|
|
|
+ status: 1,
|
|
|
+ type: "button",
|
|
|
+ authCode: "System:Menu:Edit",
|
|
|
+ meta: { title: "common.edit" }
|
|
|
+ },
|
|
|
+ {
|
|
|
+ id: 20103,
|
|
|
+ pid: 201,
|
|
|
+ name: "SystemMenuDelete",
|
|
|
+ status: 1,
|
|
|
+ type: "button",
|
|
|
+ authCode: "System:Menu:Delete",
|
|
|
+ meta: { title: "common.delete" }
|
|
|
+ }
|
|
|
+ ]
|
|
|
+ },
|
|
|
+ {
|
|
|
+ id: 202,
|
|
|
+ pid: 2,
|
|
|
+ path: "/system/dept",
|
|
|
+ name: "SystemDept",
|
|
|
+ status: 1,
|
|
|
+ type: "menu",
|
|
|
+ authCode: "System:Dept:List",
|
|
|
+ meta: {
|
|
|
+ icon: "carbon:container-services",
|
|
|
+ title: "system.dept.title"
|
|
|
+ },
|
|
|
+ component: "/system/dept/list",
|
|
|
+ children: [
|
|
|
+ {
|
|
|
+ id: 20401,
|
|
|
+ pid: 201,
|
|
|
+ name: "SystemDeptCreate",
|
|
|
+ status: 1,
|
|
|
+ type: "button",
|
|
|
+ authCode: "System:Dept:Create",
|
|
|
+ meta: { title: "common.create" }
|
|
|
+ },
|
|
|
+ {
|
|
|
+ id: 20402,
|
|
|
+ pid: 201,
|
|
|
+ name: "SystemDeptEdit",
|
|
|
+ status: 1,
|
|
|
+ type: "button",
|
|
|
+ authCode: "System:Dept:Edit",
|
|
|
+ meta: { title: "common.edit" }
|
|
|
+ },
|
|
|
+ {
|
|
|
+ id: 20403,
|
|
|
+ pid: 201,
|
|
|
+ name: "SystemDeptDelete",
|
|
|
+ status: 1,
|
|
|
+ type: "button",
|
|
|
+ authCode: "System:Dept:Delete",
|
|
|
+ meta: { title: "common.delete" }
|
|
|
+ }
|
|
|
+ ]
|
|
|
+ }
|
|
|
+ ]
|
|
|
+ },
|
|
|
+ {
|
|
|
+ id: 9,
|
|
|
+ meta: {
|
|
|
+ badgeType: "dot",
|
|
|
+ order: 9998,
|
|
|
+ title: "demos.vben.title",
|
|
|
+ icon: "carbon:data-center"
|
|
|
+ },
|
|
|
+ name: "Project",
|
|
|
+ path: "/vben-admin",
|
|
|
+ type: "catalog",
|
|
|
+ status: 1,
|
|
|
+ children: [
|
|
|
+ {
|
|
|
+ id: 901,
|
|
|
+ pid: 9,
|
|
|
+ name: "VbenDocument",
|
|
|
+ path: "/vben-admin/document",
|
|
|
+ component: "IFrameView",
|
|
|
+ type: "embedded",
|
|
|
+ status: 1,
|
|
|
+ meta: {
|
|
|
+ icon: "carbon:book",
|
|
|
+ iframeSrc: "https://doc.vben.pro",
|
|
|
+ title: "demos.vben.document"
|
|
|
+ }
|
|
|
+ },
|
|
|
+ {
|
|
|
+ id: 902,
|
|
|
+ pid: 9,
|
|
|
+ name: "VbenGithub",
|
|
|
+ path: "/vben-admin/github",
|
|
|
+ component: "IFrameView",
|
|
|
+ type: "link",
|
|
|
+ status: 1,
|
|
|
+ meta: {
|
|
|
+ icon: "carbon:logo-github",
|
|
|
+ link: "https://github.com/vbenjs/vue-vben-admin",
|
|
|
+ title: "Github"
|
|
|
+ }
|
|
|
+ },
|
|
|
+ {
|
|
|
+ id: 903,
|
|
|
+ pid: 9,
|
|
|
+ name: "VbenAntdv",
|
|
|
+ path: "/vben-admin/antdv",
|
|
|
+ component: "IFrameView",
|
|
|
+ type: "link",
|
|
|
+ status: 0,
|
|
|
+ meta: {
|
|
|
+ icon: "carbon:hexagon-vertical-solid",
|
|
|
+ badgeType: "dot",
|
|
|
+ link: "https://ant.vben.pro",
|
|
|
+ title: "demos.vben.antdv"
|
|
|
+ }
|
|
|
+ }
|
|
|
+ ]
|
|
|
+ },
|
|
|
+ {
|
|
|
+ id: 10,
|
|
|
+ component: "_core/about/index",
|
|
|
+ type: "menu",
|
|
|
+ status: 1,
|
|
|
+ meta: {
|
|
|
+ icon: "lucide:copyright",
|
|
|
+ order: 9999,
|
|
|
+ title: "demos.vben.about"
|
|
|
+ },
|
|
|
+ name: "About",
|
|
|
+ path: "/about"
|
|
|
+ }
|
|
|
+];
|
|
|
+function getMenuIds(menus) {
|
|
|
+ const ids = [];
|
|
|
+ menus.forEach((item) => {
|
|
|
+ ids.push(item.id);
|
|
|
+ if (item.children && item.children.length > 0) {
|
|
|
+ ids.push(...getMenuIds(item.children));
|
|
|
+ }
|
|
|
+ });
|
|
|
+ return ids;
|
|
|
+}
|
|
|
+
|
|
|
+const ACCESS_TOKEN_SECRET = "access_token_secret";
|
|
|
+const REFRESH_TOKEN_SECRET = "refresh_token_secret";
|
|
|
+function generateAccessToken(user) {
|
|
|
+ return jwt.sign(user, ACCESS_TOKEN_SECRET, { expiresIn: "7d" });
|
|
|
+}
|
|
|
+function generateRefreshToken(user) {
|
|
|
+ return jwt.sign(user, REFRESH_TOKEN_SECRET, {
|
|
|
+ expiresIn: "30d"
|
|
|
+ });
|
|
|
+}
|
|
|
+function verifyAccessToken(event) {
|
|
|
+ const authHeader = getHeader(event, "Authorization");
|
|
|
+ if (!(authHeader == null ? void 0 : authHeader.startsWith("Bearer"))) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ const token = authHeader.split(" ")[1];
|
|
|
+ try {
|
|
|
+ const decoded = jwt.verify(token, ACCESS_TOKEN_SECRET);
|
|
|
+ const username = decoded.username;
|
|
|
+ const user = MOCK_USERS.find((item) => item.username === username);
|
|
|
+ const { password: _pwd, ...userinfo } = user;
|
|
|
+ return userinfo;
|
|
|
+ } catch {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+}
|
|
|
+function verifyRefreshToken(token) {
|
|
|
+ try {
|
|
|
+ const decoded = jwt.verify(token, REFRESH_TOKEN_SECRET);
|
|
|
+ const username = decoded.username;
|
|
|
+ const user = MOCK_USERS.find((item) => item.username === username);
|
|
|
+ const { password: _pwd, ...userinfo } = user;
|
|
|
+ return userinfo;
|
|
|
+ } catch {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+const codes = eventHandler((event) => {
|
|
|
+ var _a, _b;
|
|
|
+ const userinfo = verifyAccessToken(event);
|
|
|
+ if (!userinfo) {
|
|
|
+ return unAuthorizedResponse(event);
|
|
|
+ }
|
|
|
+ const codes = (_b = (_a = MOCK_CODES.find((item) => item.username === userinfo.username)) == null ? void 0 : _a.codes) != null ? _b : [];
|
|
|
+ return useResponseSuccess(codes);
|
|
|
+});
|
|
|
+
|
|
|
+const codes$1 = /*#__PURE__*/Object.freeze({
|
|
|
+ __proto__: null,
|
|
|
+ default: codes
|
|
|
+});
|
|
|
+
|
|
|
+function clearRefreshTokenCookie(event) {
|
|
|
+ deleteCookie(event, "jwt", {
|
|
|
+ httpOnly: true,
|
|
|
+ sameSite: "none",
|
|
|
+ secure: true
|
|
|
+ });
|
|
|
+}
|
|
|
+function setRefreshTokenCookie(event, refreshToken) {
|
|
|
+ setCookie(event, "jwt", refreshToken, {
|
|
|
+ httpOnly: true,
|
|
|
+ maxAge: 24 * 60 * 60,
|
|
|
+ // unit: seconds
|
|
|
+ sameSite: "none",
|
|
|
+ secure: true
|
|
|
+ });
|
|
|
+}
|
|
|
+function getRefreshTokenFromCookie(event) {
|
|
|
+ const refreshToken = getCookie(event, "jwt");
|
|
|
+ return refreshToken;
|
|
|
+}
|
|
|
+
|
|
|
+const login_post = defineEventHandler(async (event) => {
|
|
|
+ const { password, username } = await readBody(event);
|
|
|
+ if (!password || !username) {
|
|
|
+ setResponseStatus(event, 400);
|
|
|
+ return useResponseError(
|
|
|
+ "BadRequestException",
|
|
|
+ "Username and password are required"
|
|
|
+ );
|
|
|
+ }
|
|
|
+ const findUser = MOCK_USERS.find(
|
|
|
+ (item) => item.username === username && item.password === password
|
|
|
+ );
|
|
|
+ if (!findUser) {
|
|
|
+ clearRefreshTokenCookie(event);
|
|
|
+ return forbiddenResponse(event, "Username or password is incorrect.");
|
|
|
+ }
|
|
|
+ const accessToken = generateAccessToken(findUser);
|
|
|
+ const refreshToken = generateRefreshToken(findUser);
|
|
|
+ setRefreshTokenCookie(event, refreshToken);
|
|
|
+ return useResponseSuccess({
|
|
|
+ ...findUser,
|
|
|
+ accessToken
|
|
|
+ });
|
|
|
+});
|
|
|
+
|
|
|
+const login_post$1 = /*#__PURE__*/Object.freeze({
|
|
|
+ __proto__: null,
|
|
|
+ default: login_post
|
|
|
+});
|
|
|
+
|
|
|
+const logout_post = defineEventHandler(async (event) => {
|
|
|
+ const refreshToken = getRefreshTokenFromCookie(event);
|
|
|
+ if (!refreshToken) {
|
|
|
+ return useResponseSuccess("");
|
|
|
+ }
|
|
|
+ clearRefreshTokenCookie(event);
|
|
|
+ return useResponseSuccess("");
|
|
|
+});
|
|
|
+
|
|
|
+const logout_post$1 = /*#__PURE__*/Object.freeze({
|
|
|
+ __proto__: null,
|
|
|
+ default: logout_post
|
|
|
+});
|
|
|
+
|
|
|
+const refresh_post = defineEventHandler(async (event) => {
|
|
|
+ const refreshToken = getRefreshTokenFromCookie(event);
|
|
|
+ if (!refreshToken) {
|
|
|
+ return forbiddenResponse(event);
|
|
|
+ }
|
|
|
+ clearRefreshTokenCookie(event);
|
|
|
+ const userinfo = verifyRefreshToken(refreshToken);
|
|
|
+ if (!userinfo) {
|
|
|
+ return forbiddenResponse(event);
|
|
|
+ }
|
|
|
+ const findUser = MOCK_USERS.find(
|
|
|
+ (item) => item.username === userinfo.username
|
|
|
+ );
|
|
|
+ if (!findUser) {
|
|
|
+ return forbiddenResponse(event);
|
|
|
+ }
|
|
|
+ const accessToken = generateAccessToken(findUser);
|
|
|
+ setRefreshTokenCookie(event, refreshToken);
|
|
|
+ return accessToken;
|
|
|
+});
|
|
|
+
|
|
|
+const refresh_post$1 = /*#__PURE__*/Object.freeze({
|
|
|
+ __proto__: null,
|
|
|
+ default: refresh_post
|
|
|
+});
|
|
|
+
|
|
|
+const bigint = eventHandler(async (event) => {
|
|
|
+ const userinfo = verifyAccessToken(event);
|
|
|
+ if (!userinfo) {
|
|
|
+ return unAuthorizedResponse(event);
|
|
|
+ }
|
|
|
+ const data = `
|
|
|
+ {
|
|
|
+ "code": 0,
|
|
|
+ "message": "success",
|
|
|
+ "data": [
|
|
|
+ {
|
|
|
+ "id": 123456789012345678901234567890123456789012345678901234567890,
|
|
|
+ "name": "John Doe",
|
|
|
+ "age": 30,
|
|
|
+ "email": "john-doe@demo.com"
|
|
|
+ },
|
|
|
+ {
|
|
|
+ "id": 987654321098765432109876543210987654321098765432109876543210,
|
|
|
+ "name": "Jane Smith",
|
|
|
+ "age": 25,
|
|
|
+ "email": "jane@demo.com"
|
|
|
+ }
|
|
|
+ ]
|
|
|
+ }
|
|
|
+ `;
|
|
|
+ setHeader(event, "Content-Type", "application/json");
|
|
|
+ return data;
|
|
|
+});
|
|
|
+
|
|
|
+const bigint$1 = /*#__PURE__*/Object.freeze({
|
|
|
+ __proto__: null,
|
|
|
+ default: bigint
|
|
|
+});
|
|
|
+
|
|
|
+const all = eventHandler(async (event) => {
|
|
|
+ var _a, _b;
|
|
|
+ const userinfo = verifyAccessToken(event);
|
|
|
+ if (!userinfo) {
|
|
|
+ return unAuthorizedResponse(event);
|
|
|
+ }
|
|
|
+ const menus = (_b = (_a = MOCK_MENUS.find((item) => item.username === userinfo.username)) == null ? void 0 : _a.menus) != null ? _b : [];
|
|
|
+ return useResponseSuccess(menus);
|
|
|
+});
|
|
|
+
|
|
|
+const all$1 = /*#__PURE__*/Object.freeze({
|
|
|
+ __proto__: null,
|
|
|
+ default: all
|
|
|
+});
|
|
|
+
|
|
|
+const status = eventHandler((event) => {
|
|
|
+ const { status } = getQuery$1(event);
|
|
|
+ setResponseStatus(event, Number(status));
|
|
|
+ return useResponseError(`${status}`);
|
|
|
+});
|
|
|
+
|
|
|
+const status$1 = /*#__PURE__*/Object.freeze({
|
|
|
+ __proto__: null,
|
|
|
+ default: status
|
|
|
+});
|
|
|
+
|
|
|
+const _post = eventHandler(async (event) => {
|
|
|
+ const userinfo = verifyAccessToken(event);
|
|
|
+ if (!userinfo) {
|
|
|
+ return unAuthorizedResponse(event);
|
|
|
+ }
|
|
|
+ await sleep(600);
|
|
|
+ return useResponseSuccess(null);
|
|
|
+});
|
|
|
+
|
|
|
+const _post$1 = /*#__PURE__*/Object.freeze({
|
|
|
+ __proto__: null,
|
|
|
+ default: _post
|
|
|
+});
|
|
|
+
|
|
|
+const _id__delete = eventHandler(async (event) => {
|
|
|
+ const userinfo = verifyAccessToken(event);
|
|
|
+ if (!userinfo) {
|
|
|
+ return unAuthorizedResponse(event);
|
|
|
+ }
|
|
|
+ await sleep(1e3);
|
|
|
+ return useResponseSuccess(null);
|
|
|
+});
|
|
|
+
|
|
|
+const _id__delete$1 = /*#__PURE__*/Object.freeze({
|
|
|
+ __proto__: null,
|
|
|
+ default: _id__delete
|
|
|
+});
|
|
|
+
|
|
|
+const _id__put = eventHandler(async (event) => {
|
|
|
+ const userinfo = verifyAccessToken(event);
|
|
|
+ if (!userinfo) {
|
|
|
+ return unAuthorizedResponse(event);
|
|
|
+ }
|
|
|
+ await sleep(2e3);
|
|
|
+ return useResponseSuccess(null);
|
|
|
+});
|
|
|
+
|
|
|
+const _id__put$1 = /*#__PURE__*/Object.freeze({
|
|
|
+ __proto__: null,
|
|
|
+ default: _id__put
|
|
|
+});
|
|
|
+
|
|
|
+const formatterCN$1 = new Intl.DateTimeFormat("zh-CN", {
|
|
|
+ timeZone: "Asia/Shanghai",
|
|
|
+ year: "numeric",
|
|
|
+ month: "2-digit",
|
|
|
+ day: "2-digit",
|
|
|
+ hour: "2-digit",
|
|
|
+ minute: "2-digit",
|
|
|
+ second: "2-digit"
|
|
|
+});
|
|
|
+function generateMockDataList$2(count) {
|
|
|
+ const dataList = [];
|
|
|
+ for (let i = 0; i < count; i++) {
|
|
|
+ const dataItem = {
|
|
|
+ id: faker.string.uuid(),
|
|
|
+ pid: 0,
|
|
|
+ name: faker.commerce.department(),
|
|
|
+ status: faker.helpers.arrayElement([0, 1]),
|
|
|
+ createTime: formatterCN$1.format(
|
|
|
+ faker.date.between({ from: "2021-01-01", to: "2022-12-31" })
|
|
|
+ ),
|
|
|
+ remark: faker.lorem.sentence()
|
|
|
+ };
|
|
|
+ if (faker.datatype.boolean()) {
|
|
|
+ dataItem.children = Array.from(
|
|
|
+ { length: faker.number.int({ min: 1, max: 5 }) },
|
|
|
+ () => ({
|
|
|
+ id: faker.string.uuid(),
|
|
|
+ pid: dataItem.id,
|
|
|
+ name: faker.commerce.department(),
|
|
|
+ status: faker.helpers.arrayElement([0, 1]),
|
|
|
+ createTime: formatterCN$1.format(
|
|
|
+ faker.date.between({ from: "2023-01-01", to: "2023-12-31" })
|
|
|
+ ),
|
|
|
+ remark: faker.lorem.sentence()
|
|
|
+ })
|
|
|
+ );
|
|
|
+ }
|
|
|
+ dataList.push(dataItem);
|
|
|
+ }
|
|
|
+ return dataList;
|
|
|
+}
|
|
|
+const mockData$2 = generateMockDataList$2(10);
|
|
|
+const list$6 = eventHandler(async (event) => {
|
|
|
+ const userinfo = verifyAccessToken(event);
|
|
|
+ if (!userinfo) {
|
|
|
+ return unAuthorizedResponse(event);
|
|
|
+ }
|
|
|
+ const listData = structuredClone(mockData$2);
|
|
|
+ return useResponseSuccess(listData);
|
|
|
+});
|
|
|
+
|
|
|
+const list$7 = /*#__PURE__*/Object.freeze({
|
|
|
+ __proto__: null,
|
|
|
+ default: list$6
|
|
|
+});
|
|
|
+
|
|
|
+const list$4 = eventHandler(async (event) => {
|
|
|
+ const userinfo = verifyAccessToken(event);
|
|
|
+ if (!userinfo) {
|
|
|
+ return unAuthorizedResponse(event);
|
|
|
+ }
|
|
|
+ return useResponseSuccess(MOCK_MENU_LIST);
|
|
|
+});
|
|
|
+
|
|
|
+const list$5 = /*#__PURE__*/Object.freeze({
|
|
|
+ __proto__: null,
|
|
|
+ default: list$4
|
|
|
+});
|
|
|
+
|
|
|
+const namesMap = {};
|
|
|
+function getNames(menus) {
|
|
|
+ menus.forEach((menu) => {
|
|
|
+ namesMap[menu.name] = String(menu.id);
|
|
|
+ if (menu.children) {
|
|
|
+ getNames(menu.children);
|
|
|
+ }
|
|
|
+ });
|
|
|
+}
|
|
|
+getNames(MOCK_MENU_LIST);
|
|
|
+const nameExists = eventHandler(async (event) => {
|
|
|
+ const userinfo = verifyAccessToken(event);
|
|
|
+ if (!userinfo) {
|
|
|
+ return unAuthorizedResponse(event);
|
|
|
+ }
|
|
|
+ const { id, name } = getQuery$1(event);
|
|
|
+ return name in namesMap && (!id || namesMap[name] !== String(id)) ? useResponseSuccess(true) : useResponseSuccess(false);
|
|
|
+});
|
|
|
+
|
|
|
+const nameExists$1 = /*#__PURE__*/Object.freeze({
|
|
|
+ __proto__: null,
|
|
|
+ default: nameExists
|
|
|
+});
|
|
|
+
|
|
|
+const pathMap = { "/": 0 };
|
|
|
+function getPaths(menus) {
|
|
|
+ menus.forEach((menu) => {
|
|
|
+ pathMap[menu.path] = String(menu.id);
|
|
|
+ if (menu.children) {
|
|
|
+ getPaths(menu.children);
|
|
|
+ }
|
|
|
+ });
|
|
|
+}
|
|
|
+getPaths(MOCK_MENU_LIST);
|
|
|
+const pathExists = eventHandler(async (event) => {
|
|
|
+ const userinfo = verifyAccessToken(event);
|
|
|
+ if (!userinfo) {
|
|
|
+ return unAuthorizedResponse(event);
|
|
|
+ }
|
|
|
+ const { id, path } = getQuery$1(event);
|
|
|
+ return path in pathMap && (!id || pathMap[path] !== String(id)) ? useResponseSuccess(true) : useResponseSuccess(false);
|
|
|
+});
|
|
|
+
|
|
|
+const pathExists$1 = /*#__PURE__*/Object.freeze({
|
|
|
+ __proto__: null,
|
|
|
+ default: pathExists
|
|
|
+});
|
|
|
+
|
|
|
+const formatterCN = new Intl.DateTimeFormat("zh-CN", {
|
|
|
+ timeZone: "Asia/Shanghai",
|
|
|
+ year: "numeric",
|
|
|
+ month: "2-digit",
|
|
|
+ day: "2-digit",
|
|
|
+ hour: "2-digit",
|
|
|
+ minute: "2-digit",
|
|
|
+ second: "2-digit"
|
|
|
+});
|
|
|
+const menuIds = getMenuIds(MOCK_MENU_LIST);
|
|
|
+function generateMockDataList$1(count) {
|
|
|
+ const dataList = [];
|
|
|
+ for (let i = 0; i < count; i++) {
|
|
|
+ const dataItem = {
|
|
|
+ id: faker.string.uuid(),
|
|
|
+ name: faker.commerce.product(),
|
|
|
+ status: faker.helpers.arrayElement([0, 1]),
|
|
|
+ createTime: formatterCN.format(
|
|
|
+ faker.date.between({ from: "2022-01-01", to: "2025-01-01" })
|
|
|
+ ),
|
|
|
+ permissions: faker.helpers.arrayElements(menuIds),
|
|
|
+ remark: faker.lorem.sentence()
|
|
|
+ };
|
|
|
+ dataList.push(dataItem);
|
|
|
+ }
|
|
|
+ return dataList;
|
|
|
+}
|
|
|
+const mockData$1 = generateMockDataList$1(100);
|
|
|
+const list$2 = eventHandler(async (event) => {
|
|
|
+ const userinfo = verifyAccessToken(event);
|
|
|
+ if (!userinfo) {
|
|
|
+ return unAuthorizedResponse(event);
|
|
|
+ }
|
|
|
+ const {
|
|
|
+ page = 1,
|
|
|
+ pageSize = 20,
|
|
|
+ name,
|
|
|
+ id,
|
|
|
+ remark,
|
|
|
+ startTime,
|
|
|
+ endTime,
|
|
|
+ status
|
|
|
+ } = getQuery$1(event);
|
|
|
+ let listData = structuredClone(mockData$1);
|
|
|
+ if (name) {
|
|
|
+ listData = listData.filter(
|
|
|
+ (item) => item.name.toLowerCase().includes(String(name).toLowerCase())
|
|
|
+ );
|
|
|
+ }
|
|
|
+ if (id) {
|
|
|
+ listData = listData.filter(
|
|
|
+ (item) => item.id.toLowerCase().includes(String(id).toLowerCase())
|
|
|
+ );
|
|
|
+ }
|
|
|
+ if (remark) {
|
|
|
+ listData = listData.filter(
|
|
|
+ (item) => {
|
|
|
+ var _a, _b;
|
|
|
+ return (_b = (_a = item.remark) == null ? void 0 : _a.toLowerCase()) == null ? void 0 : _b.includes(String(remark).toLowerCase());
|
|
|
+ }
|
|
|
+ );
|
|
|
+ }
|
|
|
+ if (startTime) {
|
|
|
+ listData = listData.filter((item) => item.createTime >= startTime);
|
|
|
+ }
|
|
|
+ if (endTime) {
|
|
|
+ listData = listData.filter((item) => item.createTime <= endTime);
|
|
|
+ }
|
|
|
+ if (["0", "1"].includes(status)) {
|
|
|
+ listData = listData.filter((item) => item.status === Number(status));
|
|
|
+ }
|
|
|
+ return usePageResponseSuccess(page, pageSize, listData);
|
|
|
+});
|
|
|
+
|
|
|
+const list$3 = /*#__PURE__*/Object.freeze({
|
|
|
+ __proto__: null,
|
|
|
+ default: list$2
|
|
|
+});
|
|
|
+
|
|
|
+function generateMockDataList(count) {
|
|
|
+ const dataList = [];
|
|
|
+ for (let i = 0; i < count; i++) {
|
|
|
+ const dataItem = {
|
|
|
+ id: faker.string.uuid(),
|
|
|
+ imageUrl: faker.image.avatar(),
|
|
|
+ imageUrl2: faker.image.avatar(),
|
|
|
+ open: faker.datatype.boolean(),
|
|
|
+ status: faker.helpers.arrayElement(["success", "error", "warning"]),
|
|
|
+ productName: faker.commerce.productName(),
|
|
|
+ price: faker.commerce.price(),
|
|
|
+ currency: faker.finance.currencyCode(),
|
|
|
+ quantity: faker.number.int({ min: 1, max: 100 }),
|
|
|
+ available: faker.datatype.boolean(),
|
|
|
+ category: faker.commerce.department(),
|
|
|
+ releaseDate: faker.date.past(),
|
|
|
+ rating: faker.number.float({ min: 1, max: 5 }),
|
|
|
+ description: faker.commerce.productDescription(),
|
|
|
+ weight: faker.number.float({ min: 0.1, max: 10 }),
|
|
|
+ color: faker.color.human(),
|
|
|
+ inProduction: faker.datatype.boolean(),
|
|
|
+ tags: Array.from({ length: 3 }, () => faker.commerce.productAdjective())
|
|
|
+ };
|
|
|
+ dataList.push(dataItem);
|
|
|
+ }
|
|
|
+ return dataList;
|
|
|
+}
|
|
|
+const mockData = generateMockDataList(100);
|
|
|
+const list = eventHandler(async (event) => {
|
|
|
+ const userinfo = verifyAccessToken(event);
|
|
|
+ if (!userinfo) {
|
|
|
+ return unAuthorizedResponse(event);
|
|
|
+ }
|
|
|
+ await sleep(600);
|
|
|
+ const { page, pageSize, sortBy, sortOrder } = getQuery$1(event);
|
|
|
+ const listData = structuredClone(mockData);
|
|
|
+ if (sortBy && Reflect.has(listData[0], sortBy)) {
|
|
|
+ listData.sort((a, b) => {
|
|
|
+ if (sortOrder === "asc") {
|
|
|
+ if (sortBy === "price") {
|
|
|
+ return Number.parseFloat(a[sortBy]) - Number.parseFloat(b[sortBy]);
|
|
|
+ } else {
|
|
|
+ return a[sortBy] > b[sortBy] ? 1 : -1;
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ if (sortBy === "price") {
|
|
|
+ return Number.parseFloat(b[sortBy]) - Number.parseFloat(a[sortBy]);
|
|
|
+ } else {
|
|
|
+ return a[sortBy] < b[sortBy] ? 1 : -1;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ return usePageResponseSuccess(page, pageSize, listData);
|
|
|
+});
|
|
|
+
|
|
|
+const list$1 = /*#__PURE__*/Object.freeze({
|
|
|
+ __proto__: null,
|
|
|
+ default: list
|
|
|
+});
|
|
|
+
|
|
|
+const test_get = defineEventHandler(() => "Test get handler");
|
|
|
+
|
|
|
+const test_get$1 = /*#__PURE__*/Object.freeze({
|
|
|
+ __proto__: null,
|
|
|
+ default: test_get
|
|
|
+});
|
|
|
+
|
|
|
+const test_post = defineEventHandler(() => "Test post handler");
|
|
|
+
|
|
|
+const test_post$1 = /*#__PURE__*/Object.freeze({
|
|
|
+ __proto__: null,
|
|
|
+ default: test_post
|
|
|
+});
|
|
|
+
|
|
|
+const upload = eventHandler((event) => {
|
|
|
+ const userinfo = verifyAccessToken(event);
|
|
|
+ if (!userinfo) {
|
|
|
+ return unAuthorizedResponse(event);
|
|
|
+ }
|
|
|
+ return useResponseSuccess({
|
|
|
+ url: "https://unpkg.com/@vbenjs/static-source@0.1.7/source/logo-v1.webp"
|
|
|
+ });
|
|
|
+});
|
|
|
+
|
|
|
+const upload$1 = /*#__PURE__*/Object.freeze({
|
|
|
+ __proto__: null,
|
|
|
+ default: upload
|
|
|
+});
|
|
|
+
|
|
|
+const info = eventHandler((event) => {
|
|
|
+ const userinfo = verifyAccessToken(event);
|
|
|
+ if (!userinfo) {
|
|
|
+ return unAuthorizedResponse(event);
|
|
|
+ }
|
|
|
+ return useResponseSuccess(userinfo);
|
|
|
+});
|
|
|
+
|
|
|
+const info$1 = /*#__PURE__*/Object.freeze({
|
|
|
+ __proto__: null,
|
|
|
+ default: info
|
|
|
+});
|
|
|
+
|
|
|
+const _____ = defineEventHandler(() => {
|
|
|
+ return `
|
|
|
+<h1>Hello Vben Admin</h1>
|
|
|
+<h2>Mock service is starting</h2>
|
|
|
+<ul>
|
|
|
+<li><a href="/api/user">/api/user/info</a></li>
|
|
|
+<li><a href="/api/menu">/api/menu/all</a></li>
|
|
|
+<li><a href="/api/auth/codes">/api/auth/codes</a></li>
|
|
|
+<li><a href="/api/auth/login">/api/auth/login</a></li>
|
|
|
+<li><a href="/api/upload">/api/upload</a></li>
|
|
|
+</ul>
|
|
|
+`;
|
|
|
+});
|
|
|
+
|
|
|
+const _____$1 = /*#__PURE__*/Object.freeze({
|
|
|
+ __proto__: null,
|
|
|
+ default: _____
|
|
|
+});
|
|
|
+//# sourceMappingURL=index.mjs.map
|