mirror of
https://github.com/placeholder-soft/Babylong.git
synced 2026-04-30 04:25:41 +08:00
feat: function setup
This commit is contained in:
30
.wrangler/tmp/bundle-EUTT79/checked-fetch.js
Normal file
30
.wrangler/tmp/bundle-EUTT79/checked-fetch.js
Normal file
@@ -0,0 +1,30 @@
|
||||
const urls = new Set();
|
||||
|
||||
function checkURL(request, init) {
|
||||
const url =
|
||||
request instanceof URL
|
||||
? request
|
||||
: new URL(
|
||||
(typeof request === "string"
|
||||
? new Request(request, init)
|
||||
: request
|
||||
).url
|
||||
);
|
||||
if (url.port && url.port !== "443" && url.protocol === "https:") {
|
||||
if (!urls.has(url.toString())) {
|
||||
urls.add(url.toString());
|
||||
console.warn(
|
||||
`WARNING: known issue with \`fetch()\` requests to custom HTTPS ports in published Workers:\n` +
|
||||
` - ${url.toString()} - the custom port will be ignored when the Worker is published using the \`wrangler deploy\` command.\n`
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
globalThis.fetch = new Proxy(globalThis.fetch, {
|
||||
apply(target, thisArg, argArray) {
|
||||
const [request, init] = argArray;
|
||||
checkURL(request, init);
|
||||
return Reflect.apply(target, thisArg, argArray);
|
||||
},
|
||||
});
|
||||
11
.wrangler/tmp/bundle-EUTT79/middleware-insertion-facade.js
Normal file
11
.wrangler/tmp/bundle-EUTT79/middleware-insertion-facade.js
Normal file
@@ -0,0 +1,11 @@
|
||||
import worker, * as OTHER_EXPORTS from "/Users/chuan_yu/Desktop/work/satlayer-hackathon/node_modules/.pnpm/wrangler@3.85.0/node_modules/wrangler/templates/pages-template-worker.ts";
|
||||
import * as __MIDDLEWARE_0__ from "/Users/chuan_yu/Desktop/work/satlayer-hackathon/node_modules/.pnpm/wrangler@3.85.0/node_modules/wrangler/templates/middleware/middleware-ensure-req-body-drained.ts";
|
||||
import * as __MIDDLEWARE_1__ from "/Users/chuan_yu/Desktop/work/satlayer-hackathon/node_modules/.pnpm/wrangler@3.85.0/node_modules/wrangler/templates/middleware/middleware-miniflare3-json-error.ts";
|
||||
|
||||
export * from "/Users/chuan_yu/Desktop/work/satlayer-hackathon/node_modules/.pnpm/wrangler@3.85.0/node_modules/wrangler/templates/pages-template-worker.ts";
|
||||
|
||||
export const __INTERNAL_WRANGLER_MIDDLEWARE__ = [
|
||||
|
||||
__MIDDLEWARE_0__.default,__MIDDLEWARE_1__.default
|
||||
]
|
||||
export default worker;
|
||||
134
.wrangler/tmp/bundle-EUTT79/middleware-loader.entry.ts
Normal file
134
.wrangler/tmp/bundle-EUTT79/middleware-loader.entry.ts
Normal file
@@ -0,0 +1,134 @@
|
||||
// This loads all middlewares exposed on the middleware object and then starts
|
||||
// the invocation chain. The big idea is that we can add these to the middleware
|
||||
// export dynamically through wrangler, or we can potentially let users directly
|
||||
// add them as a sort of "plugin" system.
|
||||
|
||||
import ENTRY, { __INTERNAL_WRANGLER_MIDDLEWARE__ } from "/Users/chuan_yu/Desktop/work/satlayer-hackathon/.wrangler/tmp/bundle-EUTT79/middleware-insertion-facade.js";
|
||||
import { __facade_invoke__, __facade_register__, Dispatcher } from "/Users/chuan_yu/Desktop/work/satlayer-hackathon/node_modules/.pnpm/wrangler@3.85.0/node_modules/wrangler/templates/middleware/common.ts";
|
||||
import type { WorkerEntrypointConstructor } from "/Users/chuan_yu/Desktop/work/satlayer-hackathon/.wrangler/tmp/bundle-EUTT79/middleware-insertion-facade.js";
|
||||
|
||||
// Preserve all the exports from the worker
|
||||
export * from "/Users/chuan_yu/Desktop/work/satlayer-hackathon/.wrangler/tmp/bundle-EUTT79/middleware-insertion-facade.js";
|
||||
|
||||
class __Facade_ScheduledController__ implements ScheduledController {
|
||||
readonly #noRetry: ScheduledController["noRetry"];
|
||||
|
||||
constructor(
|
||||
readonly scheduledTime: number,
|
||||
readonly cron: string,
|
||||
noRetry: ScheduledController["noRetry"]
|
||||
) {
|
||||
this.#noRetry = noRetry;
|
||||
}
|
||||
|
||||
noRetry() {
|
||||
if (!(this instanceof __Facade_ScheduledController__)) {
|
||||
throw new TypeError("Illegal invocation");
|
||||
}
|
||||
// Need to call native method immediately in case uncaught error thrown
|
||||
this.#noRetry();
|
||||
}
|
||||
}
|
||||
|
||||
function wrapExportedHandler(worker: ExportedHandler): ExportedHandler {
|
||||
// If we don't have any middleware defined, just return the handler as is
|
||||
if (
|
||||
__INTERNAL_WRANGLER_MIDDLEWARE__ === undefined ||
|
||||
__INTERNAL_WRANGLER_MIDDLEWARE__.length === 0
|
||||
) {
|
||||
return worker;
|
||||
}
|
||||
// Otherwise, register all middleware once
|
||||
for (const middleware of __INTERNAL_WRANGLER_MIDDLEWARE__) {
|
||||
__facade_register__(middleware);
|
||||
}
|
||||
|
||||
const fetchDispatcher: ExportedHandlerFetchHandler = function (
|
||||
request,
|
||||
env,
|
||||
ctx
|
||||
) {
|
||||
if (worker.fetch === undefined) {
|
||||
throw new Error("Handler does not export a fetch() function.");
|
||||
}
|
||||
return worker.fetch(request, env, ctx);
|
||||
};
|
||||
|
||||
return {
|
||||
...worker,
|
||||
fetch(request, env, ctx) {
|
||||
const dispatcher: Dispatcher = function (type, init) {
|
||||
if (type === "scheduled" && worker.scheduled !== undefined) {
|
||||
const controller = new __Facade_ScheduledController__(
|
||||
Date.now(),
|
||||
init.cron ?? "",
|
||||
() => {}
|
||||
);
|
||||
return worker.scheduled(controller, env, ctx);
|
||||
}
|
||||
};
|
||||
return __facade_invoke__(request, env, ctx, dispatcher, fetchDispatcher);
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
function wrapWorkerEntrypoint(
|
||||
klass: WorkerEntrypointConstructor
|
||||
): WorkerEntrypointConstructor {
|
||||
// If we don't have any middleware defined, just return the handler as is
|
||||
if (
|
||||
__INTERNAL_WRANGLER_MIDDLEWARE__ === undefined ||
|
||||
__INTERNAL_WRANGLER_MIDDLEWARE__.length === 0
|
||||
) {
|
||||
return klass;
|
||||
}
|
||||
// Otherwise, register all middleware once
|
||||
for (const middleware of __INTERNAL_WRANGLER_MIDDLEWARE__) {
|
||||
__facade_register__(middleware);
|
||||
}
|
||||
|
||||
// `extend`ing `klass` here so other RPC methods remain callable
|
||||
return class extends klass {
|
||||
#fetchDispatcher: ExportedHandlerFetchHandler<Record<string, unknown>> = (
|
||||
request,
|
||||
env,
|
||||
ctx
|
||||
) => {
|
||||
this.env = env;
|
||||
this.ctx = ctx;
|
||||
if (super.fetch === undefined) {
|
||||
throw new Error("Entrypoint class does not define a fetch() function.");
|
||||
}
|
||||
return super.fetch(request);
|
||||
};
|
||||
|
||||
#dispatcher: Dispatcher = (type, init) => {
|
||||
if (type === "scheduled" && super.scheduled !== undefined) {
|
||||
const controller = new __Facade_ScheduledController__(
|
||||
Date.now(),
|
||||
init.cron ?? "",
|
||||
() => {}
|
||||
);
|
||||
return super.scheduled(controller);
|
||||
}
|
||||
};
|
||||
|
||||
fetch(request: Request<unknown, IncomingRequestCfProperties>) {
|
||||
return __facade_invoke__(
|
||||
request,
|
||||
this.env,
|
||||
this.ctx,
|
||||
this.#dispatcher,
|
||||
this.#fetchDispatcher
|
||||
);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
let WRAPPED_ENTRY: ExportedHandler | WorkerEntrypointConstructor | undefined;
|
||||
if (typeof ENTRY === "object") {
|
||||
WRAPPED_ENTRY = wrapExportedHandler(ENTRY);
|
||||
} else if (typeof ENTRY === "function") {
|
||||
WRAPPED_ENTRY = wrapWorkerEntrypoint(ENTRY);
|
||||
}
|
||||
export default WRAPPED_ENTRY;
|
||||
30
.wrangler/tmp/bundle-ooiDol/checked-fetch.js
Normal file
30
.wrangler/tmp/bundle-ooiDol/checked-fetch.js
Normal file
@@ -0,0 +1,30 @@
|
||||
const urls = new Set();
|
||||
|
||||
function checkURL(request, init) {
|
||||
const url =
|
||||
request instanceof URL
|
||||
? request
|
||||
: new URL(
|
||||
(typeof request === "string"
|
||||
? new Request(request, init)
|
||||
: request
|
||||
).url
|
||||
);
|
||||
if (url.port && url.port !== "443" && url.protocol === "https:") {
|
||||
if (!urls.has(url.toString())) {
|
||||
urls.add(url.toString());
|
||||
console.warn(
|
||||
`WARNING: known issue with \`fetch()\` requests to custom HTTPS ports in published Workers:\n` +
|
||||
` - ${url.toString()} - the custom port will be ignored when the Worker is published using the \`wrangler deploy\` command.\n`
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
globalThis.fetch = new Proxy(globalThis.fetch, {
|
||||
apply(target, thisArg, argArray) {
|
||||
const [request, init] = argArray;
|
||||
checkURL(request, init);
|
||||
return Reflect.apply(target, thisArg, argArray);
|
||||
},
|
||||
});
|
||||
11
.wrangler/tmp/bundle-ooiDol/middleware-insertion-facade.js
Normal file
11
.wrangler/tmp/bundle-ooiDol/middleware-insertion-facade.js
Normal file
@@ -0,0 +1,11 @@
|
||||
import worker, * as OTHER_EXPORTS from "/Users/chuan_yu/Desktop/work/satlayer-hackathon/.wrangler/tmp/pages-r4dXCe/functionsWorker-0.9817993910801683.mjs";
|
||||
import * as __MIDDLEWARE_0__ from "/Users/chuan_yu/Desktop/work/satlayer-hackathon/node_modules/.pnpm/wrangler@3.85.0/node_modules/wrangler/templates/middleware/middleware-ensure-req-body-drained.ts";
|
||||
import * as __MIDDLEWARE_1__ from "/Users/chuan_yu/Desktop/work/satlayer-hackathon/node_modules/.pnpm/wrangler@3.85.0/node_modules/wrangler/templates/middleware/middleware-miniflare3-json-error.ts";
|
||||
|
||||
export * from "/Users/chuan_yu/Desktop/work/satlayer-hackathon/.wrangler/tmp/pages-r4dXCe/functionsWorker-0.9817993910801683.mjs";
|
||||
|
||||
export const __INTERNAL_WRANGLER_MIDDLEWARE__ = [
|
||||
|
||||
__MIDDLEWARE_0__.default,__MIDDLEWARE_1__.default
|
||||
]
|
||||
export default worker;
|
||||
134
.wrangler/tmp/bundle-ooiDol/middleware-loader.entry.ts
Normal file
134
.wrangler/tmp/bundle-ooiDol/middleware-loader.entry.ts
Normal file
@@ -0,0 +1,134 @@
|
||||
// This loads all middlewares exposed on the middleware object and then starts
|
||||
// the invocation chain. The big idea is that we can add these to the middleware
|
||||
// export dynamically through wrangler, or we can potentially let users directly
|
||||
// add them as a sort of "plugin" system.
|
||||
|
||||
import ENTRY, { __INTERNAL_WRANGLER_MIDDLEWARE__ } from "/Users/chuan_yu/Desktop/work/satlayer-hackathon/.wrangler/tmp/bundle-ooiDol/middleware-insertion-facade.js";
|
||||
import { __facade_invoke__, __facade_register__, Dispatcher } from "/Users/chuan_yu/Desktop/work/satlayer-hackathon/node_modules/.pnpm/wrangler@3.85.0/node_modules/wrangler/templates/middleware/common.ts";
|
||||
import type { WorkerEntrypointConstructor } from "/Users/chuan_yu/Desktop/work/satlayer-hackathon/.wrangler/tmp/bundle-ooiDol/middleware-insertion-facade.js";
|
||||
|
||||
// Preserve all the exports from the worker
|
||||
export * from "/Users/chuan_yu/Desktop/work/satlayer-hackathon/.wrangler/tmp/bundle-ooiDol/middleware-insertion-facade.js";
|
||||
|
||||
class __Facade_ScheduledController__ implements ScheduledController {
|
||||
readonly #noRetry: ScheduledController["noRetry"];
|
||||
|
||||
constructor(
|
||||
readonly scheduledTime: number,
|
||||
readonly cron: string,
|
||||
noRetry: ScheduledController["noRetry"]
|
||||
) {
|
||||
this.#noRetry = noRetry;
|
||||
}
|
||||
|
||||
noRetry() {
|
||||
if (!(this instanceof __Facade_ScheduledController__)) {
|
||||
throw new TypeError("Illegal invocation");
|
||||
}
|
||||
// Need to call native method immediately in case uncaught error thrown
|
||||
this.#noRetry();
|
||||
}
|
||||
}
|
||||
|
||||
function wrapExportedHandler(worker: ExportedHandler): ExportedHandler {
|
||||
// If we don't have any middleware defined, just return the handler as is
|
||||
if (
|
||||
__INTERNAL_WRANGLER_MIDDLEWARE__ === undefined ||
|
||||
__INTERNAL_WRANGLER_MIDDLEWARE__.length === 0
|
||||
) {
|
||||
return worker;
|
||||
}
|
||||
// Otherwise, register all middleware once
|
||||
for (const middleware of __INTERNAL_WRANGLER_MIDDLEWARE__) {
|
||||
__facade_register__(middleware);
|
||||
}
|
||||
|
||||
const fetchDispatcher: ExportedHandlerFetchHandler = function (
|
||||
request,
|
||||
env,
|
||||
ctx
|
||||
) {
|
||||
if (worker.fetch === undefined) {
|
||||
throw new Error("Handler does not export a fetch() function.");
|
||||
}
|
||||
return worker.fetch(request, env, ctx);
|
||||
};
|
||||
|
||||
return {
|
||||
...worker,
|
||||
fetch(request, env, ctx) {
|
||||
const dispatcher: Dispatcher = function (type, init) {
|
||||
if (type === "scheduled" && worker.scheduled !== undefined) {
|
||||
const controller = new __Facade_ScheduledController__(
|
||||
Date.now(),
|
||||
init.cron ?? "",
|
||||
() => {}
|
||||
);
|
||||
return worker.scheduled(controller, env, ctx);
|
||||
}
|
||||
};
|
||||
return __facade_invoke__(request, env, ctx, dispatcher, fetchDispatcher);
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
function wrapWorkerEntrypoint(
|
||||
klass: WorkerEntrypointConstructor
|
||||
): WorkerEntrypointConstructor {
|
||||
// If we don't have any middleware defined, just return the handler as is
|
||||
if (
|
||||
__INTERNAL_WRANGLER_MIDDLEWARE__ === undefined ||
|
||||
__INTERNAL_WRANGLER_MIDDLEWARE__.length === 0
|
||||
) {
|
||||
return klass;
|
||||
}
|
||||
// Otherwise, register all middleware once
|
||||
for (const middleware of __INTERNAL_WRANGLER_MIDDLEWARE__) {
|
||||
__facade_register__(middleware);
|
||||
}
|
||||
|
||||
// `extend`ing `klass` here so other RPC methods remain callable
|
||||
return class extends klass {
|
||||
#fetchDispatcher: ExportedHandlerFetchHandler<Record<string, unknown>> = (
|
||||
request,
|
||||
env,
|
||||
ctx
|
||||
) => {
|
||||
this.env = env;
|
||||
this.ctx = ctx;
|
||||
if (super.fetch === undefined) {
|
||||
throw new Error("Entrypoint class does not define a fetch() function.");
|
||||
}
|
||||
return super.fetch(request);
|
||||
};
|
||||
|
||||
#dispatcher: Dispatcher = (type, init) => {
|
||||
if (type === "scheduled" && super.scheduled !== undefined) {
|
||||
const controller = new __Facade_ScheduledController__(
|
||||
Date.now(),
|
||||
init.cron ?? "",
|
||||
() => {}
|
||||
);
|
||||
return super.scheduled(controller);
|
||||
}
|
||||
};
|
||||
|
||||
fetch(request: Request<unknown, IncomingRequestCfProperties>) {
|
||||
return __facade_invoke__(
|
||||
request,
|
||||
this.env,
|
||||
this.ctx,
|
||||
this.#dispatcher,
|
||||
this.#fetchDispatcher
|
||||
);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
let WRAPPED_ENTRY: ExportedHandler | WorkerEntrypointConstructor | undefined;
|
||||
if (typeof ENTRY === "object") {
|
||||
WRAPPED_ENTRY = wrapExportedHandler(ENTRY);
|
||||
} else if (typeof ENTRY === "function") {
|
||||
WRAPPED_ENTRY = wrapWorkerEntrypoint(ENTRY);
|
||||
}
|
||||
export default WRAPPED_ENTRY;
|
||||
884
.wrangler/tmp/dev-qtpsgs/functionsWorker-0.9817993910801683.js
Normal file
884
.wrangler/tmp/dev-qtpsgs/functionsWorker-0.9817993910801683.js
Normal file
@@ -0,0 +1,884 @@
|
||||
var __defProp = Object.defineProperty;
|
||||
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
||||
|
||||
// .wrangler/tmp/bundle-ooiDol/checked-fetch.js
|
||||
var urls = /* @__PURE__ */ new Set();
|
||||
function checkURL(request, init) {
|
||||
const url = request instanceof URL ? request : new URL(
|
||||
(typeof request === "string" ? new Request(request, init) : request).url
|
||||
);
|
||||
if (url.port && url.port !== "443" && url.protocol === "https:") {
|
||||
if (!urls.has(url.toString())) {
|
||||
urls.add(url.toString());
|
||||
console.warn(
|
||||
`WARNING: known issue with \`fetch()\` requests to custom HTTPS ports in published Workers:
|
||||
- ${url.toString()} - the custom port will be ignored when the Worker is published using the \`wrangler deploy\` command.
|
||||
`
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
__name(checkURL, "checkURL");
|
||||
globalThis.fetch = new Proxy(globalThis.fetch, {
|
||||
apply(target, thisArg, argArray) {
|
||||
const [request, init] = argArray;
|
||||
checkURL(request, init);
|
||||
return Reflect.apply(target, thisArg, argArray);
|
||||
}
|
||||
});
|
||||
|
||||
// .wrangler/tmp/pages-r4dXCe/functionsWorker-0.9817993910801683.mjs
|
||||
var __defProp2 = Object.defineProperty;
|
||||
var __name2 = /* @__PURE__ */ __name((target, value) => __defProp2(target, "name", { value, configurable: true }), "__name");
|
||||
var urls2 = /* @__PURE__ */ new Set();
|
||||
function checkURL2(request, init) {
|
||||
const url = request instanceof URL ? request : new URL(
|
||||
(typeof request === "string" ? new Request(request, init) : request).url
|
||||
);
|
||||
if (url.port && url.port !== "443" && url.protocol === "https:") {
|
||||
if (!urls2.has(url.toString())) {
|
||||
urls2.add(url.toString());
|
||||
console.warn(
|
||||
`WARNING: known issue with \`fetch()\` requests to custom HTTPS ports in published Workers:
|
||||
- ${url.toString()} - the custom port will be ignored when the Worker is published using the \`wrangler deploy\` command.
|
||||
`
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
__name(checkURL2, "checkURL");
|
||||
__name2(checkURL2, "checkURL");
|
||||
globalThis.fetch = new Proxy(globalThis.fetch, {
|
||||
apply(target, thisArg, argArray) {
|
||||
const [request, init] = argArray;
|
||||
checkURL2(request, init);
|
||||
return Reflect.apply(target, thisArg, argArray);
|
||||
}
|
||||
});
|
||||
var CloudflareResponse = /* @__PURE__ */ __name(class extends Response {
|
||||
}, "CloudflareResponse");
|
||||
__name2(CloudflareResponse, "CloudflareResponse");
|
||||
function makePagesFunction(fn) {
|
||||
return async (context) => makeResponse(await fn(context));
|
||||
}
|
||||
__name(makePagesFunction, "makePagesFunction");
|
||||
__name2(makePagesFunction, "makePagesFunction");
|
||||
function makeResponse(body, init = {}) {
|
||||
if (body instanceof Response || body instanceof CloudflareResponse) {
|
||||
return body;
|
||||
} else {
|
||||
return new CloudflareResponse(JSON.stringify(body), {
|
||||
...init,
|
||||
headers: { "Content-Type": "application/json", ...init.headers }
|
||||
});
|
||||
}
|
||||
}
|
||||
__name(makeResponse, "makeResponse");
|
||||
__name2(makeResponse, "makeResponse");
|
||||
var onRequestGet = makePagesFunction(
|
||||
async ({ params, env }) => {
|
||||
return {
|
||||
message: "Hello, World!"
|
||||
};
|
||||
}
|
||||
);
|
||||
var routes = [
|
||||
{
|
||||
routePath: "/api/create",
|
||||
mountPath: "/api",
|
||||
method: "GET",
|
||||
middlewares: [],
|
||||
modules: [onRequestGet]
|
||||
}
|
||||
];
|
||||
function lexer(str) {
|
||||
var tokens = [];
|
||||
var i = 0;
|
||||
while (i < str.length) {
|
||||
var char = str[i];
|
||||
if (char === "*" || char === "+" || char === "?") {
|
||||
tokens.push({ type: "MODIFIER", index: i, value: str[i++] });
|
||||
continue;
|
||||
}
|
||||
if (char === "\\") {
|
||||
tokens.push({ type: "ESCAPED_CHAR", index: i++, value: str[i++] });
|
||||
continue;
|
||||
}
|
||||
if (char === "{") {
|
||||
tokens.push({ type: "OPEN", index: i, value: str[i++] });
|
||||
continue;
|
||||
}
|
||||
if (char === "}") {
|
||||
tokens.push({ type: "CLOSE", index: i, value: str[i++] });
|
||||
continue;
|
||||
}
|
||||
if (char === ":") {
|
||||
var name = "";
|
||||
var j = i + 1;
|
||||
while (j < str.length) {
|
||||
var code = str.charCodeAt(j);
|
||||
if (
|
||||
// `0-9`
|
||||
code >= 48 && code <= 57 || // `A-Z`
|
||||
code >= 65 && code <= 90 || // `a-z`
|
||||
code >= 97 && code <= 122 || // `_`
|
||||
code === 95
|
||||
) {
|
||||
name += str[j++];
|
||||
continue;
|
||||
}
|
||||
break;
|
||||
}
|
||||
if (!name)
|
||||
throw new TypeError("Missing parameter name at ".concat(i));
|
||||
tokens.push({ type: "NAME", index: i, value: name });
|
||||
i = j;
|
||||
continue;
|
||||
}
|
||||
if (char === "(") {
|
||||
var count = 1;
|
||||
var pattern = "";
|
||||
var j = i + 1;
|
||||
if (str[j] === "?") {
|
||||
throw new TypeError('Pattern cannot start with "?" at '.concat(j));
|
||||
}
|
||||
while (j < str.length) {
|
||||
if (str[j] === "\\") {
|
||||
pattern += str[j++] + str[j++];
|
||||
continue;
|
||||
}
|
||||
if (str[j] === ")") {
|
||||
count--;
|
||||
if (count === 0) {
|
||||
j++;
|
||||
break;
|
||||
}
|
||||
} else if (str[j] === "(") {
|
||||
count++;
|
||||
if (str[j + 1] !== "?") {
|
||||
throw new TypeError("Capturing groups are not allowed at ".concat(j));
|
||||
}
|
||||
}
|
||||
pattern += str[j++];
|
||||
}
|
||||
if (count)
|
||||
throw new TypeError("Unbalanced pattern at ".concat(i));
|
||||
if (!pattern)
|
||||
throw new TypeError("Missing pattern at ".concat(i));
|
||||
tokens.push({ type: "PATTERN", index: i, value: pattern });
|
||||
i = j;
|
||||
continue;
|
||||
}
|
||||
tokens.push({ type: "CHAR", index: i, value: str[i++] });
|
||||
}
|
||||
tokens.push({ type: "END", index: i, value: "" });
|
||||
return tokens;
|
||||
}
|
||||
__name(lexer, "lexer");
|
||||
__name2(lexer, "lexer");
|
||||
function parse(str, options) {
|
||||
if (options === void 0) {
|
||||
options = {};
|
||||
}
|
||||
var tokens = lexer(str);
|
||||
var _a = options.prefixes, prefixes = _a === void 0 ? "./" : _a, _b = options.delimiter, delimiter = _b === void 0 ? "/#?" : _b;
|
||||
var result = [];
|
||||
var key = 0;
|
||||
var i = 0;
|
||||
var path = "";
|
||||
var tryConsume = /* @__PURE__ */ __name2(function(type) {
|
||||
if (i < tokens.length && tokens[i].type === type)
|
||||
return tokens[i++].value;
|
||||
}, "tryConsume");
|
||||
var mustConsume = /* @__PURE__ */ __name2(function(type) {
|
||||
var value2 = tryConsume(type);
|
||||
if (value2 !== void 0)
|
||||
return value2;
|
||||
var _a2 = tokens[i], nextType = _a2.type, index = _a2.index;
|
||||
throw new TypeError("Unexpected ".concat(nextType, " at ").concat(index, ", expected ").concat(type));
|
||||
}, "mustConsume");
|
||||
var consumeText = /* @__PURE__ */ __name2(function() {
|
||||
var result2 = "";
|
||||
var value2;
|
||||
while (value2 = tryConsume("CHAR") || tryConsume("ESCAPED_CHAR")) {
|
||||
result2 += value2;
|
||||
}
|
||||
return result2;
|
||||
}, "consumeText");
|
||||
var isSafe = /* @__PURE__ */ __name2(function(value2) {
|
||||
for (var _i = 0, delimiter_1 = delimiter; _i < delimiter_1.length; _i++) {
|
||||
var char2 = delimiter_1[_i];
|
||||
if (value2.indexOf(char2) > -1)
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}, "isSafe");
|
||||
var safePattern = /* @__PURE__ */ __name2(function(prefix2) {
|
||||
var prev = result[result.length - 1];
|
||||
var prevText = prefix2 || (prev && typeof prev === "string" ? prev : "");
|
||||
if (prev && !prevText) {
|
||||
throw new TypeError('Must have text between two parameters, missing text after "'.concat(prev.name, '"'));
|
||||
}
|
||||
if (!prevText || isSafe(prevText))
|
||||
return "[^".concat(escapeString(delimiter), "]+?");
|
||||
return "(?:(?!".concat(escapeString(prevText), ")[^").concat(escapeString(delimiter), "])+?");
|
||||
}, "safePattern");
|
||||
while (i < tokens.length) {
|
||||
var char = tryConsume("CHAR");
|
||||
var name = tryConsume("NAME");
|
||||
var pattern = tryConsume("PATTERN");
|
||||
if (name || pattern) {
|
||||
var prefix = char || "";
|
||||
if (prefixes.indexOf(prefix) === -1) {
|
||||
path += prefix;
|
||||
prefix = "";
|
||||
}
|
||||
if (path) {
|
||||
result.push(path);
|
||||
path = "";
|
||||
}
|
||||
result.push({
|
||||
name: name || key++,
|
||||
prefix,
|
||||
suffix: "",
|
||||
pattern: pattern || safePattern(prefix),
|
||||
modifier: tryConsume("MODIFIER") || ""
|
||||
});
|
||||
continue;
|
||||
}
|
||||
var value = char || tryConsume("ESCAPED_CHAR");
|
||||
if (value) {
|
||||
path += value;
|
||||
continue;
|
||||
}
|
||||
if (path) {
|
||||
result.push(path);
|
||||
path = "";
|
||||
}
|
||||
var open = tryConsume("OPEN");
|
||||
if (open) {
|
||||
var prefix = consumeText();
|
||||
var name_1 = tryConsume("NAME") || "";
|
||||
var pattern_1 = tryConsume("PATTERN") || "";
|
||||
var suffix = consumeText();
|
||||
mustConsume("CLOSE");
|
||||
result.push({
|
||||
name: name_1 || (pattern_1 ? key++ : ""),
|
||||
pattern: name_1 && !pattern_1 ? safePattern(prefix) : pattern_1,
|
||||
prefix,
|
||||
suffix,
|
||||
modifier: tryConsume("MODIFIER") || ""
|
||||
});
|
||||
continue;
|
||||
}
|
||||
mustConsume("END");
|
||||
}
|
||||
return result;
|
||||
}
|
||||
__name(parse, "parse");
|
||||
__name2(parse, "parse");
|
||||
function match(str, options) {
|
||||
var keys = [];
|
||||
var re = pathToRegexp(str, keys, options);
|
||||
return regexpToFunction(re, keys, options);
|
||||
}
|
||||
__name(match, "match");
|
||||
__name2(match, "match");
|
||||
function regexpToFunction(re, keys, options) {
|
||||
if (options === void 0) {
|
||||
options = {};
|
||||
}
|
||||
var _a = options.decode, decode = _a === void 0 ? function(x) {
|
||||
return x;
|
||||
} : _a;
|
||||
return function(pathname) {
|
||||
var m = re.exec(pathname);
|
||||
if (!m)
|
||||
return false;
|
||||
var path = m[0], index = m.index;
|
||||
var params = /* @__PURE__ */ Object.create(null);
|
||||
var _loop_1 = /* @__PURE__ */ __name2(function(i2) {
|
||||
if (m[i2] === void 0)
|
||||
return "continue";
|
||||
var key = keys[i2 - 1];
|
||||
if (key.modifier === "*" || key.modifier === "+") {
|
||||
params[key.name] = m[i2].split(key.prefix + key.suffix).map(function(value) {
|
||||
return decode(value, key);
|
||||
});
|
||||
} else {
|
||||
params[key.name] = decode(m[i2], key);
|
||||
}
|
||||
}, "_loop_1");
|
||||
for (var i = 1; i < m.length; i++) {
|
||||
_loop_1(i);
|
||||
}
|
||||
return { path, index, params };
|
||||
};
|
||||
}
|
||||
__name(regexpToFunction, "regexpToFunction");
|
||||
__name2(regexpToFunction, "regexpToFunction");
|
||||
function escapeString(str) {
|
||||
return str.replace(/([.+*?=^!:${}()[\]|/\\])/g, "\\$1");
|
||||
}
|
||||
__name(escapeString, "escapeString");
|
||||
__name2(escapeString, "escapeString");
|
||||
function flags(options) {
|
||||
return options && options.sensitive ? "" : "i";
|
||||
}
|
||||
__name(flags, "flags");
|
||||
__name2(flags, "flags");
|
||||
function regexpToRegexp(path, keys) {
|
||||
if (!keys)
|
||||
return path;
|
||||
var groupsRegex = /\((?:\?<(.*?)>)?(?!\?)/g;
|
||||
var index = 0;
|
||||
var execResult = groupsRegex.exec(path.source);
|
||||
while (execResult) {
|
||||
keys.push({
|
||||
// Use parenthesized substring match if available, index otherwise
|
||||
name: execResult[1] || index++,
|
||||
prefix: "",
|
||||
suffix: "",
|
||||
modifier: "",
|
||||
pattern: ""
|
||||
});
|
||||
execResult = groupsRegex.exec(path.source);
|
||||
}
|
||||
return path;
|
||||
}
|
||||
__name(regexpToRegexp, "regexpToRegexp");
|
||||
__name2(regexpToRegexp, "regexpToRegexp");
|
||||
function arrayToRegexp(paths, keys, options) {
|
||||
var parts = paths.map(function(path) {
|
||||
return pathToRegexp(path, keys, options).source;
|
||||
});
|
||||
return new RegExp("(?:".concat(parts.join("|"), ")"), flags(options));
|
||||
}
|
||||
__name(arrayToRegexp, "arrayToRegexp");
|
||||
__name2(arrayToRegexp, "arrayToRegexp");
|
||||
function stringToRegexp(path, keys, options) {
|
||||
return tokensToRegexp(parse(path, options), keys, options);
|
||||
}
|
||||
__name(stringToRegexp, "stringToRegexp");
|
||||
__name2(stringToRegexp, "stringToRegexp");
|
||||
function tokensToRegexp(tokens, keys, options) {
|
||||
if (options === void 0) {
|
||||
options = {};
|
||||
}
|
||||
var _a = options.strict, strict = _a === void 0 ? false : _a, _b = options.start, start = _b === void 0 ? true : _b, _c = options.end, end = _c === void 0 ? true : _c, _d = options.encode, encode = _d === void 0 ? function(x) {
|
||||
return x;
|
||||
} : _d, _e = options.delimiter, delimiter = _e === void 0 ? "/#?" : _e, _f = options.endsWith, endsWith = _f === void 0 ? "" : _f;
|
||||
var endsWithRe = "[".concat(escapeString(endsWith), "]|$");
|
||||
var delimiterRe = "[".concat(escapeString(delimiter), "]");
|
||||
var route = start ? "^" : "";
|
||||
for (var _i = 0, tokens_1 = tokens; _i < tokens_1.length; _i++) {
|
||||
var token = tokens_1[_i];
|
||||
if (typeof token === "string") {
|
||||
route += escapeString(encode(token));
|
||||
} else {
|
||||
var prefix = escapeString(encode(token.prefix));
|
||||
var suffix = escapeString(encode(token.suffix));
|
||||
if (token.pattern) {
|
||||
if (keys)
|
||||
keys.push(token);
|
||||
if (prefix || suffix) {
|
||||
if (token.modifier === "+" || token.modifier === "*") {
|
||||
var mod = token.modifier === "*" ? "?" : "";
|
||||
route += "(?:".concat(prefix, "((?:").concat(token.pattern, ")(?:").concat(suffix).concat(prefix, "(?:").concat(token.pattern, "))*)").concat(suffix, ")").concat(mod);
|
||||
} else {
|
||||
route += "(?:".concat(prefix, "(").concat(token.pattern, ")").concat(suffix, ")").concat(token.modifier);
|
||||
}
|
||||
} else {
|
||||
if (token.modifier === "+" || token.modifier === "*") {
|
||||
throw new TypeError('Can not repeat "'.concat(token.name, '" without a prefix and suffix'));
|
||||
}
|
||||
route += "(".concat(token.pattern, ")").concat(token.modifier);
|
||||
}
|
||||
} else {
|
||||
route += "(?:".concat(prefix).concat(suffix, ")").concat(token.modifier);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (end) {
|
||||
if (!strict)
|
||||
route += "".concat(delimiterRe, "?");
|
||||
route += !options.endsWith ? "$" : "(?=".concat(endsWithRe, ")");
|
||||
} else {
|
||||
var endToken = tokens[tokens.length - 1];
|
||||
var isEndDelimited = typeof endToken === "string" ? delimiterRe.indexOf(endToken[endToken.length - 1]) > -1 : endToken === void 0;
|
||||
if (!strict) {
|
||||
route += "(?:".concat(delimiterRe, "(?=").concat(endsWithRe, "))?");
|
||||
}
|
||||
if (!isEndDelimited) {
|
||||
route += "(?=".concat(delimiterRe, "|").concat(endsWithRe, ")");
|
||||
}
|
||||
}
|
||||
return new RegExp(route, flags(options));
|
||||
}
|
||||
__name(tokensToRegexp, "tokensToRegexp");
|
||||
__name2(tokensToRegexp, "tokensToRegexp");
|
||||
function pathToRegexp(path, keys, options) {
|
||||
if (path instanceof RegExp)
|
||||
return regexpToRegexp(path, keys);
|
||||
if (Array.isArray(path))
|
||||
return arrayToRegexp(path, keys, options);
|
||||
return stringToRegexp(path, keys, options);
|
||||
}
|
||||
__name(pathToRegexp, "pathToRegexp");
|
||||
__name2(pathToRegexp, "pathToRegexp");
|
||||
var escapeRegex = /[.+?^${}()|[\]\\]/g;
|
||||
function* executeRequest(request) {
|
||||
const requestPath = new URL(request.url).pathname;
|
||||
for (const route of [...routes].reverse()) {
|
||||
if (route.method && route.method !== request.method) {
|
||||
continue;
|
||||
}
|
||||
const routeMatcher = match(route.routePath.replace(escapeRegex, "\\$&"), {
|
||||
end: false
|
||||
});
|
||||
const mountMatcher = match(route.mountPath.replace(escapeRegex, "\\$&"), {
|
||||
end: false
|
||||
});
|
||||
const matchResult = routeMatcher(requestPath);
|
||||
const mountMatchResult = mountMatcher(requestPath);
|
||||
if (matchResult && mountMatchResult) {
|
||||
for (const handler of route.middlewares.flat()) {
|
||||
yield {
|
||||
handler,
|
||||
params: matchResult.params,
|
||||
path: mountMatchResult.path
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
for (const route of routes) {
|
||||
if (route.method && route.method !== request.method) {
|
||||
continue;
|
||||
}
|
||||
const routeMatcher = match(route.routePath.replace(escapeRegex, "\\$&"), {
|
||||
end: true
|
||||
});
|
||||
const mountMatcher = match(route.mountPath.replace(escapeRegex, "\\$&"), {
|
||||
end: false
|
||||
});
|
||||
const matchResult = routeMatcher(requestPath);
|
||||
const mountMatchResult = mountMatcher(requestPath);
|
||||
if (matchResult && mountMatchResult && route.modules.length) {
|
||||
for (const handler of route.modules.flat()) {
|
||||
yield {
|
||||
handler,
|
||||
params: matchResult.params,
|
||||
path: matchResult.path
|
||||
};
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
__name(executeRequest, "executeRequest");
|
||||
__name2(executeRequest, "executeRequest");
|
||||
var pages_template_worker_default = {
|
||||
async fetch(originalRequest, env, workerContext) {
|
||||
let request = originalRequest;
|
||||
const handlerIterator = executeRequest(request);
|
||||
let data = {};
|
||||
let isFailOpen = false;
|
||||
const next = /* @__PURE__ */ __name2(async (input, init) => {
|
||||
if (input !== void 0) {
|
||||
let url = input;
|
||||
if (typeof input === "string") {
|
||||
url = new URL(input, request.url).toString();
|
||||
}
|
||||
request = new Request(url, init);
|
||||
}
|
||||
const result = handlerIterator.next();
|
||||
if (result.done === false) {
|
||||
const { handler, params, path } = result.value;
|
||||
const context = {
|
||||
request: new Request(request.clone()),
|
||||
functionPath: path,
|
||||
next,
|
||||
params,
|
||||
get data() {
|
||||
return data;
|
||||
},
|
||||
set data(value) {
|
||||
if (typeof value !== "object" || value === null) {
|
||||
throw new Error("context.data must be an object");
|
||||
}
|
||||
data = value;
|
||||
},
|
||||
env,
|
||||
waitUntil: workerContext.waitUntil.bind(workerContext),
|
||||
passThroughOnException: () => {
|
||||
isFailOpen = true;
|
||||
}
|
||||
};
|
||||
const response = await handler(context);
|
||||
if (!(response instanceof Response)) {
|
||||
throw new Error("Your Pages function should return a Response");
|
||||
}
|
||||
return cloneResponse(response);
|
||||
} else if ("ASSETS") {
|
||||
const response = await env["ASSETS"].fetch(request);
|
||||
return cloneResponse(response);
|
||||
} else {
|
||||
const response = await fetch(request);
|
||||
return cloneResponse(response);
|
||||
}
|
||||
}, "next");
|
||||
try {
|
||||
return await next();
|
||||
} catch (error) {
|
||||
if (isFailOpen) {
|
||||
const response = await env["ASSETS"].fetch(request);
|
||||
return cloneResponse(response);
|
||||
}
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
};
|
||||
var cloneResponse = /* @__PURE__ */ __name2((response) => (
|
||||
// https://fetch.spec.whatwg.org/#null-body-status
|
||||
new Response(
|
||||
[101, 204, 205, 304].includes(response.status) ? null : response.body,
|
||||
response
|
||||
)
|
||||
), "cloneResponse");
|
||||
var drainBody = /* @__PURE__ */ __name2(async (request, env, _ctx, middlewareCtx) => {
|
||||
try {
|
||||
return await middlewareCtx.next(request, env);
|
||||
} finally {
|
||||
try {
|
||||
if (request.body !== null && !request.bodyUsed) {
|
||||
const reader = request.body.getReader();
|
||||
while (!(await reader.read()).done) {
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
console.error("Failed to drain the unused request body.", e);
|
||||
}
|
||||
}
|
||||
}, "drainBody");
|
||||
var middleware_ensure_req_body_drained_default = drainBody;
|
||||
function reduceError(e) {
|
||||
return {
|
||||
name: e?.name,
|
||||
message: e?.message ?? String(e),
|
||||
stack: e?.stack,
|
||||
cause: e?.cause === void 0 ? void 0 : reduceError(e.cause)
|
||||
};
|
||||
}
|
||||
__name(reduceError, "reduceError");
|
||||
__name2(reduceError, "reduceError");
|
||||
var jsonError = /* @__PURE__ */ __name2(async (request, env, _ctx, middlewareCtx) => {
|
||||
try {
|
||||
return await middlewareCtx.next(request, env);
|
||||
} catch (e) {
|
||||
const error = reduceError(e);
|
||||
return Response.json(error, {
|
||||
status: 500,
|
||||
headers: { "MF-Experimental-Error-Stack": "true" }
|
||||
});
|
||||
}
|
||||
}, "jsonError");
|
||||
var middleware_miniflare3_json_error_default = jsonError;
|
||||
var __INTERNAL_WRANGLER_MIDDLEWARE__ = [
|
||||
middleware_ensure_req_body_drained_default,
|
||||
middleware_miniflare3_json_error_default
|
||||
];
|
||||
var middleware_insertion_facade_default = pages_template_worker_default;
|
||||
var __facade_middleware__ = [];
|
||||
function __facade_register__(...args) {
|
||||
__facade_middleware__.push(...args.flat());
|
||||
}
|
||||
__name(__facade_register__, "__facade_register__");
|
||||
__name2(__facade_register__, "__facade_register__");
|
||||
function __facade_invokeChain__(request, env, ctx, dispatch, middlewareChain) {
|
||||
const [head, ...tail] = middlewareChain;
|
||||
const middlewareCtx = {
|
||||
dispatch,
|
||||
next(newRequest, newEnv) {
|
||||
return __facade_invokeChain__(newRequest, newEnv, ctx, dispatch, tail);
|
||||
}
|
||||
};
|
||||
return head(request, env, ctx, middlewareCtx);
|
||||
}
|
||||
__name(__facade_invokeChain__, "__facade_invokeChain__");
|
||||
__name2(__facade_invokeChain__, "__facade_invokeChain__");
|
||||
function __facade_invoke__(request, env, ctx, dispatch, finalMiddleware) {
|
||||
return __facade_invokeChain__(request, env, ctx, dispatch, [
|
||||
...__facade_middleware__,
|
||||
finalMiddleware
|
||||
]);
|
||||
}
|
||||
__name(__facade_invoke__, "__facade_invoke__");
|
||||
__name2(__facade_invoke__, "__facade_invoke__");
|
||||
var __Facade_ScheduledController__ = /* @__PURE__ */ __name(class {
|
||||
constructor(scheduledTime, cron, noRetry) {
|
||||
this.scheduledTime = scheduledTime;
|
||||
this.cron = cron;
|
||||
this.#noRetry = noRetry;
|
||||
}
|
||||
#noRetry;
|
||||
noRetry() {
|
||||
if (!(this instanceof __Facade_ScheduledController__)) {
|
||||
throw new TypeError("Illegal invocation");
|
||||
}
|
||||
this.#noRetry();
|
||||
}
|
||||
}, "__Facade_ScheduledController__");
|
||||
__name2(__Facade_ScheduledController__, "__Facade_ScheduledController__");
|
||||
function wrapExportedHandler(worker) {
|
||||
if (__INTERNAL_WRANGLER_MIDDLEWARE__ === void 0 || __INTERNAL_WRANGLER_MIDDLEWARE__.length === 0) {
|
||||
return worker;
|
||||
}
|
||||
for (const middleware of __INTERNAL_WRANGLER_MIDDLEWARE__) {
|
||||
__facade_register__(middleware);
|
||||
}
|
||||
const fetchDispatcher = /* @__PURE__ */ __name2(function(request, env, ctx) {
|
||||
if (worker.fetch === void 0) {
|
||||
throw new Error("Handler does not export a fetch() function.");
|
||||
}
|
||||
return worker.fetch(request, env, ctx);
|
||||
}, "fetchDispatcher");
|
||||
return {
|
||||
...worker,
|
||||
fetch(request, env, ctx) {
|
||||
const dispatcher = /* @__PURE__ */ __name2(function(type, init) {
|
||||
if (type === "scheduled" && worker.scheduled !== void 0) {
|
||||
const controller = new __Facade_ScheduledController__(
|
||||
Date.now(),
|
||||
init.cron ?? "",
|
||||
() => {
|
||||
}
|
||||
);
|
||||
return worker.scheduled(controller, env, ctx);
|
||||
}
|
||||
}, "dispatcher");
|
||||
return __facade_invoke__(request, env, ctx, dispatcher, fetchDispatcher);
|
||||
}
|
||||
};
|
||||
}
|
||||
__name(wrapExportedHandler, "wrapExportedHandler");
|
||||
__name2(wrapExportedHandler, "wrapExportedHandler");
|
||||
function wrapWorkerEntrypoint(klass) {
|
||||
if (__INTERNAL_WRANGLER_MIDDLEWARE__ === void 0 || __INTERNAL_WRANGLER_MIDDLEWARE__.length === 0) {
|
||||
return klass;
|
||||
}
|
||||
for (const middleware of __INTERNAL_WRANGLER_MIDDLEWARE__) {
|
||||
__facade_register__(middleware);
|
||||
}
|
||||
return class extends klass {
|
||||
#fetchDispatcher = (request, env, ctx) => {
|
||||
this.env = env;
|
||||
this.ctx = ctx;
|
||||
if (super.fetch === void 0) {
|
||||
throw new Error("Entrypoint class does not define a fetch() function.");
|
||||
}
|
||||
return super.fetch(request);
|
||||
};
|
||||
#dispatcher = (type, init) => {
|
||||
if (type === "scheduled" && super.scheduled !== void 0) {
|
||||
const controller = new __Facade_ScheduledController__(
|
||||
Date.now(),
|
||||
init.cron ?? "",
|
||||
() => {
|
||||
}
|
||||
);
|
||||
return super.scheduled(controller);
|
||||
}
|
||||
};
|
||||
fetch(request) {
|
||||
return __facade_invoke__(
|
||||
request,
|
||||
this.env,
|
||||
this.ctx,
|
||||
this.#dispatcher,
|
||||
this.#fetchDispatcher
|
||||
);
|
||||
}
|
||||
};
|
||||
}
|
||||
__name(wrapWorkerEntrypoint, "wrapWorkerEntrypoint");
|
||||
__name2(wrapWorkerEntrypoint, "wrapWorkerEntrypoint");
|
||||
var WRAPPED_ENTRY;
|
||||
if (typeof middleware_insertion_facade_default === "object") {
|
||||
WRAPPED_ENTRY = wrapExportedHandler(middleware_insertion_facade_default);
|
||||
} else if (typeof middleware_insertion_facade_default === "function") {
|
||||
WRAPPED_ENTRY = wrapWorkerEntrypoint(middleware_insertion_facade_default);
|
||||
}
|
||||
var middleware_loader_entry_default = WRAPPED_ENTRY;
|
||||
|
||||
// node_modules/.pnpm/wrangler@3.85.0/node_modules/wrangler/templates/middleware/middleware-ensure-req-body-drained.ts
|
||||
var drainBody2 = /* @__PURE__ */ __name(async (request, env, _ctx, middlewareCtx) => {
|
||||
try {
|
||||
return await middlewareCtx.next(request, env);
|
||||
} finally {
|
||||
try {
|
||||
if (request.body !== null && !request.bodyUsed) {
|
||||
const reader = request.body.getReader();
|
||||
while (!(await reader.read()).done) {
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
console.error("Failed to drain the unused request body.", e);
|
||||
}
|
||||
}
|
||||
}, "drainBody");
|
||||
var middleware_ensure_req_body_drained_default2 = drainBody2;
|
||||
|
||||
// node_modules/.pnpm/wrangler@3.85.0/node_modules/wrangler/templates/middleware/middleware-miniflare3-json-error.ts
|
||||
function reduceError2(e) {
|
||||
return {
|
||||
name: e?.name,
|
||||
message: e?.message ?? String(e),
|
||||
stack: e?.stack,
|
||||
cause: e?.cause === void 0 ? void 0 : reduceError2(e.cause)
|
||||
};
|
||||
}
|
||||
__name(reduceError2, "reduceError");
|
||||
var jsonError2 = /* @__PURE__ */ __name(async (request, env, _ctx, middlewareCtx) => {
|
||||
try {
|
||||
return await middlewareCtx.next(request, env);
|
||||
} catch (e) {
|
||||
const error = reduceError2(e);
|
||||
return Response.json(error, {
|
||||
status: 500,
|
||||
headers: { "MF-Experimental-Error-Stack": "true" }
|
||||
});
|
||||
}
|
||||
}, "jsonError");
|
||||
var middleware_miniflare3_json_error_default2 = jsonError2;
|
||||
|
||||
// .wrangler/tmp/bundle-ooiDol/middleware-insertion-facade.js
|
||||
var __INTERNAL_WRANGLER_MIDDLEWARE__2 = [
|
||||
middleware_ensure_req_body_drained_default2,
|
||||
middleware_miniflare3_json_error_default2
|
||||
];
|
||||
var middleware_insertion_facade_default2 = middleware_loader_entry_default;
|
||||
|
||||
// node_modules/.pnpm/wrangler@3.85.0/node_modules/wrangler/templates/middleware/common.ts
|
||||
var __facade_middleware__2 = [];
|
||||
function __facade_register__2(...args) {
|
||||
__facade_middleware__2.push(...args.flat());
|
||||
}
|
||||
__name(__facade_register__2, "__facade_register__");
|
||||
function __facade_invokeChain__2(request, env, ctx, dispatch, middlewareChain) {
|
||||
const [head, ...tail] = middlewareChain;
|
||||
const middlewareCtx = {
|
||||
dispatch,
|
||||
next(newRequest, newEnv) {
|
||||
return __facade_invokeChain__2(newRequest, newEnv, ctx, dispatch, tail);
|
||||
}
|
||||
};
|
||||
return head(request, env, ctx, middlewareCtx);
|
||||
}
|
||||
__name(__facade_invokeChain__2, "__facade_invokeChain__");
|
||||
function __facade_invoke__2(request, env, ctx, dispatch, finalMiddleware) {
|
||||
return __facade_invokeChain__2(request, env, ctx, dispatch, [
|
||||
...__facade_middleware__2,
|
||||
finalMiddleware
|
||||
]);
|
||||
}
|
||||
__name(__facade_invoke__2, "__facade_invoke__");
|
||||
|
||||
// .wrangler/tmp/bundle-ooiDol/middleware-loader.entry.ts
|
||||
var __Facade_ScheduledController__2 = class {
|
||||
constructor(scheduledTime, cron, noRetry) {
|
||||
this.scheduledTime = scheduledTime;
|
||||
this.cron = cron;
|
||||
this.#noRetry = noRetry;
|
||||
}
|
||||
#noRetry;
|
||||
noRetry() {
|
||||
if (!(this instanceof __Facade_ScheduledController__2)) {
|
||||
throw new TypeError("Illegal invocation");
|
||||
}
|
||||
this.#noRetry();
|
||||
}
|
||||
};
|
||||
__name(__Facade_ScheduledController__2, "__Facade_ScheduledController__");
|
||||
function wrapExportedHandler2(worker) {
|
||||
if (__INTERNAL_WRANGLER_MIDDLEWARE__2 === void 0 || __INTERNAL_WRANGLER_MIDDLEWARE__2.length === 0) {
|
||||
return worker;
|
||||
}
|
||||
for (const middleware of __INTERNAL_WRANGLER_MIDDLEWARE__2) {
|
||||
__facade_register__2(middleware);
|
||||
}
|
||||
const fetchDispatcher = /* @__PURE__ */ __name(function(request, env, ctx) {
|
||||
if (worker.fetch === void 0) {
|
||||
throw new Error("Handler does not export a fetch() function.");
|
||||
}
|
||||
return worker.fetch(request, env, ctx);
|
||||
}, "fetchDispatcher");
|
||||
return {
|
||||
...worker,
|
||||
fetch(request, env, ctx) {
|
||||
const dispatcher = /* @__PURE__ */ __name(function(type, init) {
|
||||
if (type === "scheduled" && worker.scheduled !== void 0) {
|
||||
const controller = new __Facade_ScheduledController__2(
|
||||
Date.now(),
|
||||
init.cron ?? "",
|
||||
() => {
|
||||
}
|
||||
);
|
||||
return worker.scheduled(controller, env, ctx);
|
||||
}
|
||||
}, "dispatcher");
|
||||
return __facade_invoke__2(request, env, ctx, dispatcher, fetchDispatcher);
|
||||
}
|
||||
};
|
||||
}
|
||||
__name(wrapExportedHandler2, "wrapExportedHandler");
|
||||
function wrapWorkerEntrypoint2(klass) {
|
||||
if (__INTERNAL_WRANGLER_MIDDLEWARE__2 === void 0 || __INTERNAL_WRANGLER_MIDDLEWARE__2.length === 0) {
|
||||
return klass;
|
||||
}
|
||||
for (const middleware of __INTERNAL_WRANGLER_MIDDLEWARE__2) {
|
||||
__facade_register__2(middleware);
|
||||
}
|
||||
return class extends klass {
|
||||
#fetchDispatcher = (request, env, ctx) => {
|
||||
this.env = env;
|
||||
this.ctx = ctx;
|
||||
if (super.fetch === void 0) {
|
||||
throw new Error("Entrypoint class does not define a fetch() function.");
|
||||
}
|
||||
return super.fetch(request);
|
||||
};
|
||||
#dispatcher = (type, init) => {
|
||||
if (type === "scheduled" && super.scheduled !== void 0) {
|
||||
const controller = new __Facade_ScheduledController__2(
|
||||
Date.now(),
|
||||
init.cron ?? "",
|
||||
() => {
|
||||
}
|
||||
);
|
||||
return super.scheduled(controller);
|
||||
}
|
||||
};
|
||||
fetch(request) {
|
||||
return __facade_invoke__2(
|
||||
request,
|
||||
this.env,
|
||||
this.ctx,
|
||||
this.#dispatcher,
|
||||
this.#fetchDispatcher
|
||||
);
|
||||
}
|
||||
};
|
||||
}
|
||||
__name(wrapWorkerEntrypoint2, "wrapWorkerEntrypoint");
|
||||
var WRAPPED_ENTRY2;
|
||||
if (typeof middleware_insertion_facade_default2 === "object") {
|
||||
WRAPPED_ENTRY2 = wrapExportedHandler2(middleware_insertion_facade_default2);
|
||||
} else if (typeof middleware_insertion_facade_default2 === "function") {
|
||||
WRAPPED_ENTRY2 = wrapWorkerEntrypoint2(middleware_insertion_facade_default2);
|
||||
}
|
||||
var middleware_loader_entry_default2 = WRAPPED_ENTRY2;
|
||||
export {
|
||||
__INTERNAL_WRANGLER_MIDDLEWARE__2 as __INTERNAL_WRANGLER_MIDDLEWARE__,
|
||||
middleware_loader_entry_default2 as default
|
||||
};
|
||||
//# sourceMappingURL=functionsWorker-0.9817993910801683.js.map
|
||||
File diff suppressed because one or more lines are too long
@@ -0,0 +1,11 @@
|
||||
import { onRequestGet as __api_create_ts_onRequestGet } from "/Users/chuan_yu/Desktop/work/satlayer-hackathon/functions/api/create.ts"
|
||||
|
||||
export const routes = [
|
||||
{
|
||||
routePath: "/api/create",
|
||||
mountPath: "/api",
|
||||
method: "GET",
|
||||
middlewares: [],
|
||||
modules: [__api_create_ts_onRequestGet],
|
||||
},
|
||||
]
|
||||
@@ -0,0 +1,687 @@
|
||||
var __defProp = Object.defineProperty;
|
||||
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
||||
|
||||
// ../.wrangler/tmp/bundle-EUTT79/checked-fetch.js
|
||||
var urls = /* @__PURE__ */ new Set();
|
||||
function checkURL(request, init) {
|
||||
const url = request instanceof URL ? request : new URL(
|
||||
(typeof request === "string" ? new Request(request, init) : request).url
|
||||
);
|
||||
if (url.port && url.port !== "443" && url.protocol === "https:") {
|
||||
if (!urls.has(url.toString())) {
|
||||
urls.add(url.toString());
|
||||
console.warn(
|
||||
`WARNING: known issue with \`fetch()\` requests to custom HTTPS ports in published Workers:
|
||||
- ${url.toString()} - the custom port will be ignored when the Worker is published using the \`wrangler deploy\` command.
|
||||
`
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
__name(checkURL, "checkURL");
|
||||
globalThis.fetch = new Proxy(globalThis.fetch, {
|
||||
apply(target, thisArg, argArray) {
|
||||
const [request, init] = argArray;
|
||||
checkURL(request, init);
|
||||
return Reflect.apply(target, thisArg, argArray);
|
||||
}
|
||||
});
|
||||
|
||||
// ../node_modules/.pnpm/vite-plugin-cloudflare-functions@0.8.0_axios@0.27.2_vite@5.4.10_wrangler@3.85.0/node_modules/vite-plugin-cloudflare-functions/dist/worker.mjs
|
||||
var CloudflareResponse = class extends Response {
|
||||
};
|
||||
__name(CloudflareResponse, "CloudflareResponse");
|
||||
function makePagesFunction(fn) {
|
||||
return async (context) => makeResponse(await fn(context));
|
||||
}
|
||||
__name(makePagesFunction, "makePagesFunction");
|
||||
function makeResponse(body, init = {}) {
|
||||
if (body instanceof Response || body instanceof CloudflareResponse) {
|
||||
return body;
|
||||
} else {
|
||||
return new CloudflareResponse(JSON.stringify(body), {
|
||||
...init,
|
||||
headers: { "Content-Type": "application/json", ...init.headers }
|
||||
});
|
||||
}
|
||||
}
|
||||
__name(makeResponse, "makeResponse");
|
||||
|
||||
// api/create.ts
|
||||
var onRequestGet = makePagesFunction(
|
||||
async ({ params, env }) => {
|
||||
return {
|
||||
message: "Hello, World!"
|
||||
};
|
||||
}
|
||||
);
|
||||
|
||||
// ../.wrangler/tmp/pages-r4dXCe/functionsRoutes-0.6627960299070452.mjs
|
||||
var routes = [
|
||||
{
|
||||
routePath: "/api/create",
|
||||
mountPath: "/api",
|
||||
method: "GET",
|
||||
middlewares: [],
|
||||
modules: [onRequestGet]
|
||||
}
|
||||
];
|
||||
|
||||
// ../node_modules/.pnpm/path-to-regexp@6.3.0/node_modules/path-to-regexp/dist.es2015/index.js
|
||||
function lexer(str) {
|
||||
var tokens = [];
|
||||
var i = 0;
|
||||
while (i < str.length) {
|
||||
var char = str[i];
|
||||
if (char === "*" || char === "+" || char === "?") {
|
||||
tokens.push({ type: "MODIFIER", index: i, value: str[i++] });
|
||||
continue;
|
||||
}
|
||||
if (char === "\\") {
|
||||
tokens.push({ type: "ESCAPED_CHAR", index: i++, value: str[i++] });
|
||||
continue;
|
||||
}
|
||||
if (char === "{") {
|
||||
tokens.push({ type: "OPEN", index: i, value: str[i++] });
|
||||
continue;
|
||||
}
|
||||
if (char === "}") {
|
||||
tokens.push({ type: "CLOSE", index: i, value: str[i++] });
|
||||
continue;
|
||||
}
|
||||
if (char === ":") {
|
||||
var name = "";
|
||||
var j = i + 1;
|
||||
while (j < str.length) {
|
||||
var code = str.charCodeAt(j);
|
||||
if (
|
||||
// `0-9`
|
||||
code >= 48 && code <= 57 || // `A-Z`
|
||||
code >= 65 && code <= 90 || // `a-z`
|
||||
code >= 97 && code <= 122 || // `_`
|
||||
code === 95
|
||||
) {
|
||||
name += str[j++];
|
||||
continue;
|
||||
}
|
||||
break;
|
||||
}
|
||||
if (!name)
|
||||
throw new TypeError("Missing parameter name at ".concat(i));
|
||||
tokens.push({ type: "NAME", index: i, value: name });
|
||||
i = j;
|
||||
continue;
|
||||
}
|
||||
if (char === "(") {
|
||||
var count = 1;
|
||||
var pattern = "";
|
||||
var j = i + 1;
|
||||
if (str[j] === "?") {
|
||||
throw new TypeError('Pattern cannot start with "?" at '.concat(j));
|
||||
}
|
||||
while (j < str.length) {
|
||||
if (str[j] === "\\") {
|
||||
pattern += str[j++] + str[j++];
|
||||
continue;
|
||||
}
|
||||
if (str[j] === ")") {
|
||||
count--;
|
||||
if (count === 0) {
|
||||
j++;
|
||||
break;
|
||||
}
|
||||
} else if (str[j] === "(") {
|
||||
count++;
|
||||
if (str[j + 1] !== "?") {
|
||||
throw new TypeError("Capturing groups are not allowed at ".concat(j));
|
||||
}
|
||||
}
|
||||
pattern += str[j++];
|
||||
}
|
||||
if (count)
|
||||
throw new TypeError("Unbalanced pattern at ".concat(i));
|
||||
if (!pattern)
|
||||
throw new TypeError("Missing pattern at ".concat(i));
|
||||
tokens.push({ type: "PATTERN", index: i, value: pattern });
|
||||
i = j;
|
||||
continue;
|
||||
}
|
||||
tokens.push({ type: "CHAR", index: i, value: str[i++] });
|
||||
}
|
||||
tokens.push({ type: "END", index: i, value: "" });
|
||||
return tokens;
|
||||
}
|
||||
__name(lexer, "lexer");
|
||||
function parse(str, options) {
|
||||
if (options === void 0) {
|
||||
options = {};
|
||||
}
|
||||
var tokens = lexer(str);
|
||||
var _a = options.prefixes, prefixes = _a === void 0 ? "./" : _a, _b = options.delimiter, delimiter = _b === void 0 ? "/#?" : _b;
|
||||
var result = [];
|
||||
var key = 0;
|
||||
var i = 0;
|
||||
var path = "";
|
||||
var tryConsume = /* @__PURE__ */ __name(function(type) {
|
||||
if (i < tokens.length && tokens[i].type === type)
|
||||
return tokens[i++].value;
|
||||
}, "tryConsume");
|
||||
var mustConsume = /* @__PURE__ */ __name(function(type) {
|
||||
var value2 = tryConsume(type);
|
||||
if (value2 !== void 0)
|
||||
return value2;
|
||||
var _a2 = tokens[i], nextType = _a2.type, index = _a2.index;
|
||||
throw new TypeError("Unexpected ".concat(nextType, " at ").concat(index, ", expected ").concat(type));
|
||||
}, "mustConsume");
|
||||
var consumeText = /* @__PURE__ */ __name(function() {
|
||||
var result2 = "";
|
||||
var value2;
|
||||
while (value2 = tryConsume("CHAR") || tryConsume("ESCAPED_CHAR")) {
|
||||
result2 += value2;
|
||||
}
|
||||
return result2;
|
||||
}, "consumeText");
|
||||
var isSafe = /* @__PURE__ */ __name(function(value2) {
|
||||
for (var _i = 0, delimiter_1 = delimiter; _i < delimiter_1.length; _i++) {
|
||||
var char2 = delimiter_1[_i];
|
||||
if (value2.indexOf(char2) > -1)
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}, "isSafe");
|
||||
var safePattern = /* @__PURE__ */ __name(function(prefix2) {
|
||||
var prev = result[result.length - 1];
|
||||
var prevText = prefix2 || (prev && typeof prev === "string" ? prev : "");
|
||||
if (prev && !prevText) {
|
||||
throw new TypeError('Must have text between two parameters, missing text after "'.concat(prev.name, '"'));
|
||||
}
|
||||
if (!prevText || isSafe(prevText))
|
||||
return "[^".concat(escapeString(delimiter), "]+?");
|
||||
return "(?:(?!".concat(escapeString(prevText), ")[^").concat(escapeString(delimiter), "])+?");
|
||||
}, "safePattern");
|
||||
while (i < tokens.length) {
|
||||
var char = tryConsume("CHAR");
|
||||
var name = tryConsume("NAME");
|
||||
var pattern = tryConsume("PATTERN");
|
||||
if (name || pattern) {
|
||||
var prefix = char || "";
|
||||
if (prefixes.indexOf(prefix) === -1) {
|
||||
path += prefix;
|
||||
prefix = "";
|
||||
}
|
||||
if (path) {
|
||||
result.push(path);
|
||||
path = "";
|
||||
}
|
||||
result.push({
|
||||
name: name || key++,
|
||||
prefix,
|
||||
suffix: "",
|
||||
pattern: pattern || safePattern(prefix),
|
||||
modifier: tryConsume("MODIFIER") || ""
|
||||
});
|
||||
continue;
|
||||
}
|
||||
var value = char || tryConsume("ESCAPED_CHAR");
|
||||
if (value) {
|
||||
path += value;
|
||||
continue;
|
||||
}
|
||||
if (path) {
|
||||
result.push(path);
|
||||
path = "";
|
||||
}
|
||||
var open = tryConsume("OPEN");
|
||||
if (open) {
|
||||
var prefix = consumeText();
|
||||
var name_1 = tryConsume("NAME") || "";
|
||||
var pattern_1 = tryConsume("PATTERN") || "";
|
||||
var suffix = consumeText();
|
||||
mustConsume("CLOSE");
|
||||
result.push({
|
||||
name: name_1 || (pattern_1 ? key++ : ""),
|
||||
pattern: name_1 && !pattern_1 ? safePattern(prefix) : pattern_1,
|
||||
prefix,
|
||||
suffix,
|
||||
modifier: tryConsume("MODIFIER") || ""
|
||||
});
|
||||
continue;
|
||||
}
|
||||
mustConsume("END");
|
||||
}
|
||||
return result;
|
||||
}
|
||||
__name(parse, "parse");
|
||||
function match(str, options) {
|
||||
var keys = [];
|
||||
var re = pathToRegexp(str, keys, options);
|
||||
return regexpToFunction(re, keys, options);
|
||||
}
|
||||
__name(match, "match");
|
||||
function regexpToFunction(re, keys, options) {
|
||||
if (options === void 0) {
|
||||
options = {};
|
||||
}
|
||||
var _a = options.decode, decode = _a === void 0 ? function(x) {
|
||||
return x;
|
||||
} : _a;
|
||||
return function(pathname) {
|
||||
var m = re.exec(pathname);
|
||||
if (!m)
|
||||
return false;
|
||||
var path = m[0], index = m.index;
|
||||
var params = /* @__PURE__ */ Object.create(null);
|
||||
var _loop_1 = /* @__PURE__ */ __name(function(i2) {
|
||||
if (m[i2] === void 0)
|
||||
return "continue";
|
||||
var key = keys[i2 - 1];
|
||||
if (key.modifier === "*" || key.modifier === "+") {
|
||||
params[key.name] = m[i2].split(key.prefix + key.suffix).map(function(value) {
|
||||
return decode(value, key);
|
||||
});
|
||||
} else {
|
||||
params[key.name] = decode(m[i2], key);
|
||||
}
|
||||
}, "_loop_1");
|
||||
for (var i = 1; i < m.length; i++) {
|
||||
_loop_1(i);
|
||||
}
|
||||
return { path, index, params };
|
||||
};
|
||||
}
|
||||
__name(regexpToFunction, "regexpToFunction");
|
||||
function escapeString(str) {
|
||||
return str.replace(/([.+*?=^!:${}()[\]|/\\])/g, "\\$1");
|
||||
}
|
||||
__name(escapeString, "escapeString");
|
||||
function flags(options) {
|
||||
return options && options.sensitive ? "" : "i";
|
||||
}
|
||||
__name(flags, "flags");
|
||||
function regexpToRegexp(path, keys) {
|
||||
if (!keys)
|
||||
return path;
|
||||
var groupsRegex = /\((?:\?<(.*?)>)?(?!\?)/g;
|
||||
var index = 0;
|
||||
var execResult = groupsRegex.exec(path.source);
|
||||
while (execResult) {
|
||||
keys.push({
|
||||
// Use parenthesized substring match if available, index otherwise
|
||||
name: execResult[1] || index++,
|
||||
prefix: "",
|
||||
suffix: "",
|
||||
modifier: "",
|
||||
pattern: ""
|
||||
});
|
||||
execResult = groupsRegex.exec(path.source);
|
||||
}
|
||||
return path;
|
||||
}
|
||||
__name(regexpToRegexp, "regexpToRegexp");
|
||||
function arrayToRegexp(paths, keys, options) {
|
||||
var parts = paths.map(function(path) {
|
||||
return pathToRegexp(path, keys, options).source;
|
||||
});
|
||||
return new RegExp("(?:".concat(parts.join("|"), ")"), flags(options));
|
||||
}
|
||||
__name(arrayToRegexp, "arrayToRegexp");
|
||||
function stringToRegexp(path, keys, options) {
|
||||
return tokensToRegexp(parse(path, options), keys, options);
|
||||
}
|
||||
__name(stringToRegexp, "stringToRegexp");
|
||||
function tokensToRegexp(tokens, keys, options) {
|
||||
if (options === void 0) {
|
||||
options = {};
|
||||
}
|
||||
var _a = options.strict, strict = _a === void 0 ? false : _a, _b = options.start, start = _b === void 0 ? true : _b, _c = options.end, end = _c === void 0 ? true : _c, _d = options.encode, encode = _d === void 0 ? function(x) {
|
||||
return x;
|
||||
} : _d, _e = options.delimiter, delimiter = _e === void 0 ? "/#?" : _e, _f = options.endsWith, endsWith = _f === void 0 ? "" : _f;
|
||||
var endsWithRe = "[".concat(escapeString(endsWith), "]|$");
|
||||
var delimiterRe = "[".concat(escapeString(delimiter), "]");
|
||||
var route = start ? "^" : "";
|
||||
for (var _i = 0, tokens_1 = tokens; _i < tokens_1.length; _i++) {
|
||||
var token = tokens_1[_i];
|
||||
if (typeof token === "string") {
|
||||
route += escapeString(encode(token));
|
||||
} else {
|
||||
var prefix = escapeString(encode(token.prefix));
|
||||
var suffix = escapeString(encode(token.suffix));
|
||||
if (token.pattern) {
|
||||
if (keys)
|
||||
keys.push(token);
|
||||
if (prefix || suffix) {
|
||||
if (token.modifier === "+" || token.modifier === "*") {
|
||||
var mod = token.modifier === "*" ? "?" : "";
|
||||
route += "(?:".concat(prefix, "((?:").concat(token.pattern, ")(?:").concat(suffix).concat(prefix, "(?:").concat(token.pattern, "))*)").concat(suffix, ")").concat(mod);
|
||||
} else {
|
||||
route += "(?:".concat(prefix, "(").concat(token.pattern, ")").concat(suffix, ")").concat(token.modifier);
|
||||
}
|
||||
} else {
|
||||
if (token.modifier === "+" || token.modifier === "*") {
|
||||
throw new TypeError('Can not repeat "'.concat(token.name, '" without a prefix and suffix'));
|
||||
}
|
||||
route += "(".concat(token.pattern, ")").concat(token.modifier);
|
||||
}
|
||||
} else {
|
||||
route += "(?:".concat(prefix).concat(suffix, ")").concat(token.modifier);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (end) {
|
||||
if (!strict)
|
||||
route += "".concat(delimiterRe, "?");
|
||||
route += !options.endsWith ? "$" : "(?=".concat(endsWithRe, ")");
|
||||
} else {
|
||||
var endToken = tokens[tokens.length - 1];
|
||||
var isEndDelimited = typeof endToken === "string" ? delimiterRe.indexOf(endToken[endToken.length - 1]) > -1 : endToken === void 0;
|
||||
if (!strict) {
|
||||
route += "(?:".concat(delimiterRe, "(?=").concat(endsWithRe, "))?");
|
||||
}
|
||||
if (!isEndDelimited) {
|
||||
route += "(?=".concat(delimiterRe, "|").concat(endsWithRe, ")");
|
||||
}
|
||||
}
|
||||
return new RegExp(route, flags(options));
|
||||
}
|
||||
__name(tokensToRegexp, "tokensToRegexp");
|
||||
function pathToRegexp(path, keys, options) {
|
||||
if (path instanceof RegExp)
|
||||
return regexpToRegexp(path, keys);
|
||||
if (Array.isArray(path))
|
||||
return arrayToRegexp(path, keys, options);
|
||||
return stringToRegexp(path, keys, options);
|
||||
}
|
||||
__name(pathToRegexp, "pathToRegexp");
|
||||
|
||||
// ../node_modules/.pnpm/wrangler@3.85.0/node_modules/wrangler/templates/pages-template-worker.ts
|
||||
var escapeRegex = /[.+?^${}()|[\]\\]/g;
|
||||
function* executeRequest(request) {
|
||||
const requestPath = new URL(request.url).pathname;
|
||||
for (const route of [...routes].reverse()) {
|
||||
if (route.method && route.method !== request.method) {
|
||||
continue;
|
||||
}
|
||||
const routeMatcher = match(route.routePath.replace(escapeRegex, "\\$&"), {
|
||||
end: false
|
||||
});
|
||||
const mountMatcher = match(route.mountPath.replace(escapeRegex, "\\$&"), {
|
||||
end: false
|
||||
});
|
||||
const matchResult = routeMatcher(requestPath);
|
||||
const mountMatchResult = mountMatcher(requestPath);
|
||||
if (matchResult && mountMatchResult) {
|
||||
for (const handler of route.middlewares.flat()) {
|
||||
yield {
|
||||
handler,
|
||||
params: matchResult.params,
|
||||
path: mountMatchResult.path
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
for (const route of routes) {
|
||||
if (route.method && route.method !== request.method) {
|
||||
continue;
|
||||
}
|
||||
const routeMatcher = match(route.routePath.replace(escapeRegex, "\\$&"), {
|
||||
end: true
|
||||
});
|
||||
const mountMatcher = match(route.mountPath.replace(escapeRegex, "\\$&"), {
|
||||
end: false
|
||||
});
|
||||
const matchResult = routeMatcher(requestPath);
|
||||
const mountMatchResult = mountMatcher(requestPath);
|
||||
if (matchResult && mountMatchResult && route.modules.length) {
|
||||
for (const handler of route.modules.flat()) {
|
||||
yield {
|
||||
handler,
|
||||
params: matchResult.params,
|
||||
path: matchResult.path
|
||||
};
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
__name(executeRequest, "executeRequest");
|
||||
var pages_template_worker_default = {
|
||||
async fetch(originalRequest, env, workerContext) {
|
||||
let request = originalRequest;
|
||||
const handlerIterator = executeRequest(request);
|
||||
let data = {};
|
||||
let isFailOpen = false;
|
||||
const next = /* @__PURE__ */ __name(async (input, init) => {
|
||||
if (input !== void 0) {
|
||||
let url = input;
|
||||
if (typeof input === "string") {
|
||||
url = new URL(input, request.url).toString();
|
||||
}
|
||||
request = new Request(url, init);
|
||||
}
|
||||
const result = handlerIterator.next();
|
||||
if (result.done === false) {
|
||||
const { handler, params, path } = result.value;
|
||||
const context = {
|
||||
request: new Request(request.clone()),
|
||||
functionPath: path,
|
||||
next,
|
||||
params,
|
||||
get data() {
|
||||
return data;
|
||||
},
|
||||
set data(value) {
|
||||
if (typeof value !== "object" || value === null) {
|
||||
throw new Error("context.data must be an object");
|
||||
}
|
||||
data = value;
|
||||
},
|
||||
env,
|
||||
waitUntil: workerContext.waitUntil.bind(workerContext),
|
||||
passThroughOnException: () => {
|
||||
isFailOpen = true;
|
||||
}
|
||||
};
|
||||
const response = await handler(context);
|
||||
if (!(response instanceof Response)) {
|
||||
throw new Error("Your Pages function should return a Response");
|
||||
}
|
||||
return cloneResponse(response);
|
||||
} else if ("ASSETS") {
|
||||
const response = await env["ASSETS"].fetch(request);
|
||||
return cloneResponse(response);
|
||||
} else {
|
||||
const response = await fetch(request);
|
||||
return cloneResponse(response);
|
||||
}
|
||||
}, "next");
|
||||
try {
|
||||
return await next();
|
||||
} catch (error) {
|
||||
if (isFailOpen) {
|
||||
const response = await env["ASSETS"].fetch(request);
|
||||
return cloneResponse(response);
|
||||
}
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
};
|
||||
var cloneResponse = /* @__PURE__ */ __name((response) => (
|
||||
// https://fetch.spec.whatwg.org/#null-body-status
|
||||
new Response(
|
||||
[101, 204, 205, 304].includes(response.status) ? null : response.body,
|
||||
response
|
||||
)
|
||||
), "cloneResponse");
|
||||
|
||||
// ../node_modules/.pnpm/wrangler@3.85.0/node_modules/wrangler/templates/middleware/middleware-ensure-req-body-drained.ts
|
||||
var drainBody = /* @__PURE__ */ __name(async (request, env, _ctx, middlewareCtx) => {
|
||||
try {
|
||||
return await middlewareCtx.next(request, env);
|
||||
} finally {
|
||||
try {
|
||||
if (request.body !== null && !request.bodyUsed) {
|
||||
const reader = request.body.getReader();
|
||||
while (!(await reader.read()).done) {
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
console.error("Failed to drain the unused request body.", e);
|
||||
}
|
||||
}
|
||||
}, "drainBody");
|
||||
var middleware_ensure_req_body_drained_default = drainBody;
|
||||
|
||||
// ../node_modules/.pnpm/wrangler@3.85.0/node_modules/wrangler/templates/middleware/middleware-miniflare3-json-error.ts
|
||||
function reduceError(e) {
|
||||
return {
|
||||
name: e?.name,
|
||||
message: e?.message ?? String(e),
|
||||
stack: e?.stack,
|
||||
cause: e?.cause === void 0 ? void 0 : reduceError(e.cause)
|
||||
};
|
||||
}
|
||||
__name(reduceError, "reduceError");
|
||||
var jsonError = /* @__PURE__ */ __name(async (request, env, _ctx, middlewareCtx) => {
|
||||
try {
|
||||
return await middlewareCtx.next(request, env);
|
||||
} catch (e) {
|
||||
const error = reduceError(e);
|
||||
return Response.json(error, {
|
||||
status: 500,
|
||||
headers: { "MF-Experimental-Error-Stack": "true" }
|
||||
});
|
||||
}
|
||||
}, "jsonError");
|
||||
var middleware_miniflare3_json_error_default = jsonError;
|
||||
|
||||
// ../.wrangler/tmp/bundle-EUTT79/middleware-insertion-facade.js
|
||||
var __INTERNAL_WRANGLER_MIDDLEWARE__ = [
|
||||
middleware_ensure_req_body_drained_default,
|
||||
middleware_miniflare3_json_error_default
|
||||
];
|
||||
var middleware_insertion_facade_default = pages_template_worker_default;
|
||||
|
||||
// ../node_modules/.pnpm/wrangler@3.85.0/node_modules/wrangler/templates/middleware/common.ts
|
||||
var __facade_middleware__ = [];
|
||||
function __facade_register__(...args) {
|
||||
__facade_middleware__.push(...args.flat());
|
||||
}
|
||||
__name(__facade_register__, "__facade_register__");
|
||||
function __facade_invokeChain__(request, env, ctx, dispatch, middlewareChain) {
|
||||
const [head, ...tail] = middlewareChain;
|
||||
const middlewareCtx = {
|
||||
dispatch,
|
||||
next(newRequest, newEnv) {
|
||||
return __facade_invokeChain__(newRequest, newEnv, ctx, dispatch, tail);
|
||||
}
|
||||
};
|
||||
return head(request, env, ctx, middlewareCtx);
|
||||
}
|
||||
__name(__facade_invokeChain__, "__facade_invokeChain__");
|
||||
function __facade_invoke__(request, env, ctx, dispatch, finalMiddleware) {
|
||||
return __facade_invokeChain__(request, env, ctx, dispatch, [
|
||||
...__facade_middleware__,
|
||||
finalMiddleware
|
||||
]);
|
||||
}
|
||||
__name(__facade_invoke__, "__facade_invoke__");
|
||||
|
||||
// ../.wrangler/tmp/bundle-EUTT79/middleware-loader.entry.ts
|
||||
var __Facade_ScheduledController__ = class {
|
||||
constructor(scheduledTime, cron, noRetry) {
|
||||
this.scheduledTime = scheduledTime;
|
||||
this.cron = cron;
|
||||
this.#noRetry = noRetry;
|
||||
}
|
||||
#noRetry;
|
||||
noRetry() {
|
||||
if (!(this instanceof __Facade_ScheduledController__)) {
|
||||
throw new TypeError("Illegal invocation");
|
||||
}
|
||||
this.#noRetry();
|
||||
}
|
||||
};
|
||||
__name(__Facade_ScheduledController__, "__Facade_ScheduledController__");
|
||||
function wrapExportedHandler(worker) {
|
||||
if (__INTERNAL_WRANGLER_MIDDLEWARE__ === void 0 || __INTERNAL_WRANGLER_MIDDLEWARE__.length === 0) {
|
||||
return worker;
|
||||
}
|
||||
for (const middleware of __INTERNAL_WRANGLER_MIDDLEWARE__) {
|
||||
__facade_register__(middleware);
|
||||
}
|
||||
const fetchDispatcher = /* @__PURE__ */ __name(function(request, env, ctx) {
|
||||
if (worker.fetch === void 0) {
|
||||
throw new Error("Handler does not export a fetch() function.");
|
||||
}
|
||||
return worker.fetch(request, env, ctx);
|
||||
}, "fetchDispatcher");
|
||||
return {
|
||||
...worker,
|
||||
fetch(request, env, ctx) {
|
||||
const dispatcher = /* @__PURE__ */ __name(function(type, init) {
|
||||
if (type === "scheduled" && worker.scheduled !== void 0) {
|
||||
const controller = new __Facade_ScheduledController__(
|
||||
Date.now(),
|
||||
init.cron ?? "",
|
||||
() => {
|
||||
}
|
||||
);
|
||||
return worker.scheduled(controller, env, ctx);
|
||||
}
|
||||
}, "dispatcher");
|
||||
return __facade_invoke__(request, env, ctx, dispatcher, fetchDispatcher);
|
||||
}
|
||||
};
|
||||
}
|
||||
__name(wrapExportedHandler, "wrapExportedHandler");
|
||||
function wrapWorkerEntrypoint(klass) {
|
||||
if (__INTERNAL_WRANGLER_MIDDLEWARE__ === void 0 || __INTERNAL_WRANGLER_MIDDLEWARE__.length === 0) {
|
||||
return klass;
|
||||
}
|
||||
for (const middleware of __INTERNAL_WRANGLER_MIDDLEWARE__) {
|
||||
__facade_register__(middleware);
|
||||
}
|
||||
return class extends klass {
|
||||
#fetchDispatcher = (request, env, ctx) => {
|
||||
this.env = env;
|
||||
this.ctx = ctx;
|
||||
if (super.fetch === void 0) {
|
||||
throw new Error("Entrypoint class does not define a fetch() function.");
|
||||
}
|
||||
return super.fetch(request);
|
||||
};
|
||||
#dispatcher = (type, init) => {
|
||||
if (type === "scheduled" && super.scheduled !== void 0) {
|
||||
const controller = new __Facade_ScheduledController__(
|
||||
Date.now(),
|
||||
init.cron ?? "",
|
||||
() => {
|
||||
}
|
||||
);
|
||||
return super.scheduled(controller);
|
||||
}
|
||||
};
|
||||
fetch(request) {
|
||||
return __facade_invoke__(
|
||||
request,
|
||||
this.env,
|
||||
this.ctx,
|
||||
this.#dispatcher,
|
||||
this.#fetchDispatcher
|
||||
);
|
||||
}
|
||||
};
|
||||
}
|
||||
__name(wrapWorkerEntrypoint, "wrapWorkerEntrypoint");
|
||||
var WRAPPED_ENTRY;
|
||||
if (typeof middleware_insertion_facade_default === "object") {
|
||||
WRAPPED_ENTRY = wrapExportedHandler(middleware_insertion_facade_default);
|
||||
} else if (typeof middleware_insertion_facade_default === "function") {
|
||||
WRAPPED_ENTRY = wrapWorkerEntrypoint(middleware_insertion_facade_default);
|
||||
}
|
||||
var middleware_loader_entry_default = WRAPPED_ENTRY;
|
||||
export {
|
||||
__INTERNAL_WRANGLER_MIDDLEWARE__,
|
||||
middleware_loader_entry_default as default
|
||||
};
|
||||
//# sourceMappingURL=functionsWorker-0.9817993910801683.mjs.map
|
||||
File diff suppressed because one or more lines are too long
11
cloudflare.d.ts
vendored
Normal file
11
cloudflare.d.ts
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
import type { CloudflareResponseBody } from 'vite-plugin-cloudflare-functions/worker';
|
||||
|
||||
import 'vite-plugin-cloudflare-functions/client';
|
||||
|
||||
declare module 'vite-plugin-cloudflare-functions/client' {
|
||||
interface PagesResponseBody {
|
||||
'/api/create': {
|
||||
GET: CloudflareResponseBody<typeof import('functions/api/create')['onRequestGet']>;
|
||||
};
|
||||
}
|
||||
}
|
||||
1
functions/.gitignore
vendored
Normal file
1
functions/.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
||||
.wrangler
|
||||
9
functions/api/create.ts
Normal file
9
functions/api/create.ts
Normal file
@@ -0,0 +1,9 @@
|
||||
import { makePagesFunction } from "vite-plugin-cloudflare-functions/worker"
|
||||
|
||||
export const onRequestGet = makePagesFunction(
|
||||
async ({ params, env }) => {
|
||||
return ({
|
||||
message: "Hello, World!"
|
||||
})
|
||||
},
|
||||
)
|
||||
0
functions/types.ts
Normal file
0
functions/types.ts
Normal file
@@ -11,12 +11,14 @@
|
||||
"prettier": "prettier --write 'src/**/*.{ts,tsx}'"
|
||||
},
|
||||
"dependencies": {
|
||||
"@aws-sdk/client-s3": "^3.687.0",
|
||||
"@cosmjs/cosmwasm-stargate": "^0.32.4",
|
||||
"@cosmjs/launchpad": "^0.27.1",
|
||||
"@cosmjs/proto-signing": "^0.32.4",
|
||||
"@cosmjs/stargate": "^0.32.4",
|
||||
"@cosmjs/tendermint-rpc": "^0.32.4",
|
||||
"@t3-oss/env-core": "^0.11.1",
|
||||
"@tailwindcss/forms": "^0.5.9",
|
||||
"graz": "^0.1.25",
|
||||
"long": "^5.2.3",
|
||||
"nanoid": "^5.0.8",
|
||||
@@ -45,7 +47,9 @@
|
||||
"typescript": "~5.6.2",
|
||||
"typescript-eslint": "^8.11.0",
|
||||
"vite": "^5.4.10",
|
||||
"vite-plugin-cloudflare-functions": "^0.8.0",
|
||||
"vite-plugin-node-polyfills": "^0.22.0",
|
||||
"vite-plugin-svgr": "^4.3.0"
|
||||
"vite-plugin-svgr": "^4.3.0",
|
||||
"wrangler": "^3.85.0"
|
||||
}
|
||||
}
|
||||
|
||||
2071
pnpm-lock.yaml
generated
2071
pnpm-lock.yaml
generated
File diff suppressed because it is too large
Load Diff
229
src/pages/crateToken/index.tsx
Normal file
229
src/pages/crateToken/index.tsx
Normal file
@@ -0,0 +1,229 @@
|
||||
import { FC, useState, ChangeEvent } from "react"
|
||||
import { useCosmWasmSigningClient, useExecuteContract } from "graz"
|
||||
import { toast } from "react-toastify"
|
||||
import { signingOpts } from "../../constant"
|
||||
import { env } from "../../env"
|
||||
import { uploadToFilebase } from "../../utils/filebase"
|
||||
|
||||
interface FormData {
|
||||
name: string
|
||||
symbol: string
|
||||
description: string
|
||||
image: File | null
|
||||
}
|
||||
|
||||
const initialFormState: FormData = {
|
||||
name: '',
|
||||
symbol: '',
|
||||
description: '',
|
||||
image: null
|
||||
}
|
||||
|
||||
export const CrateTokenPage: FC = () => {
|
||||
const [formData, setFormData] = useState<FormData>(initialFormState)
|
||||
const [imagePreview, setImagePreview] = useState<string>('')
|
||||
const [isUploading, setIsUploading] = useState(false)
|
||||
|
||||
const { data: signingClient } = useCosmWasmSigningClient({
|
||||
opts: signingOpts,
|
||||
})
|
||||
const { executeContract } = useExecuteContract({
|
||||
contractAddress: env.VITE_FACTORY_ADDRESS,
|
||||
})
|
||||
|
||||
const handleInputChange = (e: ChangeEvent<HTMLInputElement | HTMLTextAreaElement>) => {
|
||||
const { name, value } = e.target
|
||||
setFormData(prev => ({ ...prev, [name]: value }))
|
||||
}
|
||||
|
||||
const handleImageChange = (e: ChangeEvent<HTMLInputElement>) => {
|
||||
const file = e.target.files?.[0]
|
||||
if (!file) return
|
||||
|
||||
// 验证文件大小(例如:最大 5MB)
|
||||
const maxSize = 5 * 1024 * 1024 // 5MB
|
||||
if (file.size > maxSize) {
|
||||
toast.error("File size exceeds 5MB limit")
|
||||
return
|
||||
}
|
||||
|
||||
// 验证文件类型
|
||||
const allowedTypes = ['image/jpeg', 'image/png', 'image/gif']
|
||||
if (!allowedTypes.includes(file.type)) {
|
||||
toast.error("Only JPG, PNG and GIF files are allowed")
|
||||
return
|
||||
}
|
||||
|
||||
setFormData(prev => ({ ...prev, image: file }))
|
||||
setImagePreview(URL.createObjectURL(file))
|
||||
}
|
||||
|
||||
const resetForm = () => {
|
||||
setFormData(initialFormState)
|
||||
setImagePreview('')
|
||||
if (imagePreview) {
|
||||
URL.revokeObjectURL(imagePreview)
|
||||
}
|
||||
}
|
||||
|
||||
const handleSubmit = async (e: React.FormEvent) => {
|
||||
e.preventDefault()
|
||||
|
||||
if (!signingClient) {
|
||||
toast.error("Please connect your wallet first")
|
||||
return
|
||||
}
|
||||
|
||||
setIsUploading(true)
|
||||
|
||||
try {
|
||||
let imageUrl = ''
|
||||
if (formData.image) {
|
||||
const uploadResult = await uploadToFilebase(formData.image)
|
||||
imageUrl = uploadResult.url
|
||||
console.log('Upload successful - CID:', uploadResult.cid)
|
||||
}
|
||||
|
||||
executeContract(
|
||||
{
|
||||
signingClient,
|
||||
msg: {
|
||||
create_bonding_token: {
|
||||
name: formData.name.trim(),
|
||||
symbol: formData.symbol.trim().toUpperCase(),
|
||||
description: formData.description.trim(),
|
||||
image: imageUrl,
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
onError: (err) => {
|
||||
console.error('Contract execution failed:', err)
|
||||
toast.error("Failed to create token")
|
||||
},
|
||||
onSuccess: (data) => {
|
||||
toast.success("Token created successfully")
|
||||
console.log('Contract execution successful:', data)
|
||||
resetForm()
|
||||
},
|
||||
},
|
||||
)
|
||||
} catch (error) {
|
||||
const errorMessage = error instanceof Error ? error.message : 'Unknown error occurred'
|
||||
console.error('Error creating token:', errorMessage)
|
||||
toast.error(errorMessage)
|
||||
} finally {
|
||||
setIsUploading(false)
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="max-w-2xl mx-auto p-6">
|
||||
<h2 className="text-2xl font-bold mb-6 font-SchibstedGrotesk">Create New Token</h2>
|
||||
|
||||
<form onSubmit={handleSubmit} className="space-y-6">
|
||||
{/* Name Input */}
|
||||
<div>
|
||||
<label htmlFor="name" className="block text-sm font-medium text-gray-700">
|
||||
Token Name
|
||||
</label>
|
||||
<input
|
||||
type="text"
|
||||
id="name"
|
||||
name="name"
|
||||
value={formData.name}
|
||||
onChange={handleInputChange}
|
||||
className="mt-1 block w-full rounded-md border-gray-300 shadow-sm focus:border-indigo-500 focus:ring-indigo-500 sm:text-sm"
|
||||
required
|
||||
/>
|
||||
</div>
|
||||
|
||||
{/* Symbol Input */}
|
||||
<div>
|
||||
<label htmlFor="symbol" className="block text-sm font-medium text-gray-700">
|
||||
Token Symbol
|
||||
</label>
|
||||
<input
|
||||
type="text"
|
||||
id="symbol"
|
||||
name="symbol"
|
||||
value={formData.symbol}
|
||||
onChange={handleInputChange}
|
||||
className="mt-1 block w-full rounded-md border-gray-300 shadow-sm focus:border-indigo-500 focus:ring-indigo-500 sm:text-sm"
|
||||
required
|
||||
/>
|
||||
</div>
|
||||
|
||||
{/* Description Input */}
|
||||
<div>
|
||||
<label htmlFor="description" className="block text-sm font-medium text-gray-700">
|
||||
Description
|
||||
</label>
|
||||
<textarea
|
||||
id="description"
|
||||
name="description"
|
||||
value={formData.description}
|
||||
onChange={handleInputChange}
|
||||
rows={4}
|
||||
className="mt-1 block w-full rounded-md border-gray-300 shadow-sm focus:border-indigo-500 focus:ring-indigo-500 sm:text-sm"
|
||||
/>
|
||||
</div>
|
||||
|
||||
{/* Image Upload */}
|
||||
<div>
|
||||
<label className="block text-sm font-medium text-gray-700">Token Image</label>
|
||||
<div className="mt-1 flex justify-center px-6 pt-5 pb-6 border-2 border-gray-300 border-dashed rounded-md">
|
||||
<div className="space-y-1 text-center">
|
||||
{imagePreview ? (
|
||||
<img src={imagePreview} alt="Preview" className="mx-auto h-32 w-32 object-cover" />
|
||||
) : (
|
||||
<svg
|
||||
className="mx-auto h-12 w-12 text-gray-400"
|
||||
stroke="currentColor"
|
||||
fill="none"
|
||||
viewBox="0 0 48 48"
|
||||
>
|
||||
<path
|
||||
d="M28 8H12a4 4 0 00-4 4v20m32-12v8m0 0v8a4 4 0 01-4 4H12a4 4 0 01-4-4v-4m32-4l-3.172-3.172a4 4 0 00-5.656 0L28 28M8 32l9.172-9.172a4 4 0 015.656 0L28 28m0 0l4 4m4-24h8m-4-4v8m-12 4h.02"
|
||||
strokeWidth={2}
|
||||
strokeLinecap="round"
|
||||
strokeLinejoin="round"
|
||||
/>
|
||||
</svg>
|
||||
)}
|
||||
<div className="flex text-sm text-gray-600">
|
||||
<label
|
||||
htmlFor="image-upload"
|
||||
className="relative cursor-pointer bg-white rounded-md font-medium text-indigo-600 hover:text-indigo-500 focus-within:outline-none focus-within:ring-2 focus-within:ring-offset-2 focus-within:ring-indigo-500"
|
||||
>
|
||||
<span>Upload a file</span>
|
||||
<input
|
||||
id="image-upload"
|
||||
name="image-upload"
|
||||
type="file"
|
||||
className="sr-only"
|
||||
accept="image/*"
|
||||
onChange={handleImageChange}
|
||||
/>
|
||||
</label>
|
||||
<p className="pl-1">or drag and drop</p>
|
||||
</div>
|
||||
<p className="text-xs text-gray-500">PNG, JPG, GIF up to 10MB</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Submit Button */}
|
||||
<div>
|
||||
<button
|
||||
type="submit"
|
||||
disabled={isUploading}
|
||||
className="w-full flex justify-center py-2 px-4 border border-transparent rounded-md shadow-sm text-sm font-medium text-white bg-indigo-600 hover:bg-indigo-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-indigo-500 disabled:bg-gray-400"
|
||||
>
|
||||
{isUploading ? 'Creating...' : 'Create Token'}
|
||||
</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -1,12 +1,14 @@
|
||||
import { Route } from "react-router"
|
||||
import Detail from "../pages/Detail"
|
||||
import { HomePage } from "../pages/Home"
|
||||
import { CrateTokenPage } from "../pages/crateToken"
|
||||
|
||||
export const createRoutes = (): JSX.Element => {
|
||||
return (
|
||||
<Route>
|
||||
<Route path="/" element={<HomePage />} />
|
||||
<Route path="/detail/:address" element={<Detail />} />
|
||||
<Route path="/crate-token" element={<CrateTokenPage />} />
|
||||
</Route>
|
||||
)
|
||||
}
|
||||
|
||||
83
src/utils/filebase.ts
Normal file
83
src/utils/filebase.ts
Normal file
@@ -0,0 +1,83 @@
|
||||
import { S3Client, PutObjectCommand, HeadObjectCommand } from "@aws-sdk/client-s3"
|
||||
|
||||
|
||||
interface FilebaseUploadResult {
|
||||
cid: string
|
||||
url: string
|
||||
fileName: string
|
||||
}
|
||||
|
||||
const FILEBASE_CONFIG = {
|
||||
accessKey: 'E8362FE47E1485D23F67',
|
||||
secretKey: '9wJiNNwDMShOQbUV7v4yau5Emvqh7qLHTyUXycmD',
|
||||
bucket: 'satlayer-hackathon',
|
||||
gateway: 'https://geographical-tomato-panther.myfilebase.com/ipfs',
|
||||
endpoint: 'https://s3.filebase.com',
|
||||
region: 'us-east-1'
|
||||
}
|
||||
|
||||
const getS3Client = (() => {
|
||||
let client: S3Client | null = null
|
||||
return () => {
|
||||
if (!client) {
|
||||
client = new S3Client({
|
||||
endpoint: FILEBASE_CONFIG.endpoint,
|
||||
credentials: {
|
||||
accessKeyId: FILEBASE_CONFIG.accessKey,
|
||||
secretAccessKey: FILEBASE_CONFIG.secretKey,
|
||||
},
|
||||
region: FILEBASE_CONFIG.region,
|
||||
forcePathStyle: true
|
||||
})
|
||||
}
|
||||
return client
|
||||
}
|
||||
})()
|
||||
|
||||
|
||||
const generateUniqueFileName = (file: File): string => {
|
||||
const timestamp = Date.now()
|
||||
const randomString = Math.random().toString(36).substring(2, 8)
|
||||
const extension = file.name.split('.').pop()
|
||||
return `${timestamp}-${randomString}.${extension}`
|
||||
}
|
||||
|
||||
|
||||
export async function uploadToFilebase(file: File | null): Promise<FilebaseUploadResult> {
|
||||
if (!file) {
|
||||
throw new Error("No file provided")
|
||||
}
|
||||
|
||||
try {
|
||||
const client = getS3Client()
|
||||
const fileName = generateUniqueFileName(file)
|
||||
|
||||
|
||||
await client.send(new PutObjectCommand({
|
||||
Bucket: FILEBASE_CONFIG.bucket,
|
||||
Key: fileName,
|
||||
Body: file,
|
||||
ContentType: file.type,
|
||||
ACL: 'public-read'
|
||||
}))
|
||||
|
||||
const headResponse = await client.send(new HeadObjectCommand({
|
||||
Bucket: FILEBASE_CONFIG.bucket,
|
||||
Key: fileName,
|
||||
}))
|
||||
|
||||
const cid = headResponse.Metadata?.['cid']
|
||||
if (!cid) {
|
||||
throw new Error('Failed to get IPFS CID')
|
||||
}
|
||||
|
||||
return {
|
||||
cid,
|
||||
fileName,
|
||||
url: `${FILEBASE_CONFIG.gateway}/${cid}`
|
||||
}
|
||||
} catch (error) {
|
||||
const errorMessage = error instanceof Error ? error.message : 'Unknown error occurred'
|
||||
throw new Error(`Failed to upload file: ${errorMessage}`)
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,8 @@
|
||||
/** @type {import('tailwindcss').Config} */
|
||||
export default {
|
||||
content: ["./index.html", "./src/**/*.{js,ts,jsx,tsx}"],
|
||||
module.exports = {
|
||||
content: [
|
||||
"./src/**/*.{js,jsx,ts,tsx}",
|
||||
],
|
||||
theme: {
|
||||
extend: {
|
||||
fontFamily: {
|
||||
@@ -8,5 +10,7 @@ export default {
|
||||
},
|
||||
},
|
||||
},
|
||||
plugins: [],
|
||||
plugins: [
|
||||
require('@tailwindcss/forms'),
|
||||
],
|
||||
};
|
||||
|
||||
@@ -2,10 +2,20 @@ import react from "@vitejs/plugin-react-swc"
|
||||
import { defineConfig } from "vite"
|
||||
import { nodePolyfills } from "vite-plugin-node-polyfills"
|
||||
import svgr from "vite-plugin-svgr"
|
||||
import CloudflarePagesFunctions from "vite-plugin-cloudflare-functions"
|
||||
|
||||
// https://vite.dev/config/
|
||||
export default defineConfig({
|
||||
plugins: [react(), svgr(), nodePolyfills()],
|
||||
plugins: [react(), svgr(), nodePolyfills(), CloudflarePagesFunctions({
|
||||
root: "./functions",
|
||||
outDir: undefined,
|
||||
dts: "./cloudflare.d.ts",
|
||||
wrangler: {
|
||||
log: true,
|
||||
kv: ["artworks"],
|
||||
},
|
||||
} as PluginOption)
|
||||
],
|
||||
resolve: {
|
||||
alias: {
|
||||
crypto: "crypto-browserify",
|
||||
|
||||
Reference in New Issue
Block a user