Replaces the local homepage HTML with a redirect to an external static homepage at https://xixu-me.github.io/Xget-page/. Removes the now-unused homepage.js file and updates tests to reflect the new homepage behavior.
54 lines
1.7 KiB
JavaScript
54 lines
1.7 KiB
JavaScript
import {
|
|
createExecutionContext,
|
|
env,
|
|
waitOnExecutionContext,
|
|
} from "cloudflare:test";
|
|
import { describe, expect, it } from "vitest";
|
|
import worker from "../src";
|
|
|
|
describe("Xget Worker", () => {
|
|
it("serves homepage for root path", async () => {
|
|
const request = new Request("http://example.com/");
|
|
const ctx = createExecutionContext();
|
|
const response = await worker.fetch(request, env, ctx);
|
|
await waitOnExecutionContext(ctx);
|
|
|
|
// The homepage should redirect to the external page
|
|
expect(response.status).toBe(200);
|
|
});
|
|
|
|
it("handles invalid platform", async () => {
|
|
const request = new Request("http://example.com/invalid/test");
|
|
const ctx = createExecutionContext();
|
|
const response = await worker.fetch(request, env, ctx);
|
|
await waitOnExecutionContext(ctx);
|
|
|
|
expect(response.status).toBe(400);
|
|
expect(await response.text()).toBe("Invalid or missing platform");
|
|
});
|
|
|
|
it("detects Git clone requests", async () => {
|
|
const request = new Request(
|
|
"http://example.com/gh/user/repo/info/refs?service=git-upload-pack"
|
|
);
|
|
const ctx = createExecutionContext();
|
|
const response = await worker.fetch(request, env, ctx);
|
|
await waitOnExecutionContext(ctx);
|
|
|
|
// Should attempt to proxy the Git request (might fail due to network, but shouldn't be 400)
|
|
expect(response.status).not.toBe(400);
|
|
});
|
|
|
|
it("handles regular file downloads", async () => {
|
|
const request = new Request(
|
|
"http://example.com/gh/user/repo/archive/main.zip"
|
|
);
|
|
const ctx = createExecutionContext();
|
|
const response = await worker.fetch(request, env, ctx);
|
|
await waitOnExecutionContext(ctx);
|
|
|
|
// Should attempt to proxy the file request
|
|
expect(response.status).not.toBe(400);
|
|
});
|
|
});
|