Skip to content

Commit

Permalink
Merge branch 'dev' into ci-test
Browse files Browse the repository at this point in the history
Signed-off-by: Souma <[email protected]>
  • Loading branch information
5ouma authored Jun 12, 2024
2 parents 0e52fb6 + e1ea1aa commit 00b304f
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 19 deletions.
2 changes: 1 addition & 1 deletion deno.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"@std/fmt": "jsr:@std/[email protected]",
"@std/http": "jsr:@std/[email protected]",
"@std/http/user-agent": "jsr:@std/http@~0.223/user-agent",
"@std/path": "jsr:@std/path@0.225.2"
"@std/url": "jsr:@std/url@0.224.1"
},
"deploy": {
"project": "reproxy",
Expand Down
20 changes: 14 additions & 6 deletions deno.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 10 additions & 11 deletions src/libs/redirect.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,23 @@
import type { RouterContext } from "@oak/oak";
import { STATUS_CODE } from "@std/http/status";
import { UserAgent } from "@std/http/user-agent";
import { join } from "@std/path";
import { join } from "@std/url";
import { getRepository } from "./env.ts";

export function redirect<R extends string>(
ctx: RouterContext<R>,
userAgent: UserAgent,
ref: string = "HEAD",
ref: string = "master",
): void {
const repository = getRepository();
const url: string = "https://" +
join(
"github.com",
repository.owner,
repository.name,
"blob",
ref,
repository.path,
);
const url = join(
new URL("https://github.com"),
repository.owner,
repository.name,
"blob",
ref,
repository.path,
);

if (userAgent?.browser.name) {
ctx.response.status = STATUS_CODE.PermanentRedirect;
Expand Down
2 changes: 1 addition & 1 deletion test/libs/redirect_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Deno.test("Redirect Detection", <R extends string>() => {
assertEquals(ctx.response.status, STATUS_CODE.PermanentRedirect);
assertEquals(
ctx.response.headers.get("location"),
`https://github.com/${testRepo.owner}/${testRepo.name}/blob/HEAD/${testRepo.path}`,
`https://github.com/${testRepo.owner}/${testRepo.name}/blob/master/${testRepo.path}`,
);
});

Expand Down

0 comments on commit 00b304f

Please sign in to comment.