Compare commits
3 Commits
750c81f4cb
...
8a67f4fbdb
Author | SHA1 | Date | |
---|---|---|---|
8a67f4fbdb | |||
a208c40e06 | |||
073bc9f8e3 |
34
app.ts
34
app.ts
@ -1,4 +1,4 @@
|
|||||||
import { Application, Router, HttpError, isHttpError } from "https://deno.land/x/oak@v12.1.0/mod.ts";
|
import { Application, Router, isHttpError } from "https://deno.land/x/oak@v12.1.0/mod.ts";
|
||||||
import {
|
import {
|
||||||
searchRepositoryWithTopic,
|
searchRepositoryWithTopic,
|
||||||
getRepositoryTags,
|
getRepositoryTags,
|
||||||
@ -11,12 +11,12 @@ import { Command } from "https://deno.land/x/cliffy@v0.25.7/mod.ts";
|
|||||||
import { load } from "https://deno.land/std@0.191.0/dotenv/mod.ts";
|
import { load } from "https://deno.land/std@0.191.0/dotenv/mod.ts";
|
||||||
const env = await load();
|
const env = await load();
|
||||||
|
|
||||||
function getGiteaOptions(): GiteaOption| undefined{
|
function getGiteaOptions(): GiteaOption | undefined {
|
||||||
const token = env.TOKEN;
|
const token = env.TOKEN;
|
||||||
if (token === undefined){
|
if (token === undefined) {
|
||||||
return undefined
|
return undefined
|
||||||
}
|
}
|
||||||
return {token: token};
|
return { token: token };
|
||||||
}
|
}
|
||||||
|
|
||||||
const app = new Application();
|
const app = new Application();
|
||||||
@ -71,7 +71,7 @@ router.get("/packages/:package", async (ctx) => {
|
|||||||
const repositories = await searchRepositoryWithTopic(RelativeTopic, options);
|
const repositories = await searchRepositoryWithTopic(RelativeTopic, options);
|
||||||
const repo_name = repositories.data?.map((repo) => repo.full_name)
|
const repo_name = repositories.data?.map((repo) => repo.full_name)
|
||||||
.filter(x => x !== undefined)
|
.filter(x => x !== undefined)
|
||||||
.map(x=> x?.replace("/","@")) ?? [];
|
.map(x => x?.replace("/", "@")) ?? [];
|
||||||
const completionList: CompletionList = {
|
const completionList: CompletionList = {
|
||||||
items: repo_name as string[],
|
items: repo_name as string[],
|
||||||
isIncomplete: true, // TODO: check if there are more than max results
|
isIncomplete: true, // TODO: check if there are more than max results
|
||||||
@ -127,7 +127,7 @@ router.get("/:package([a-z0-9_]*@[a-z0-9_]*)/:version?/:path*", async (ctx) => {
|
|||||||
ctx.response.body = entries;
|
ctx.response.body = entries;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if ("errors" in entries){
|
if ("errors" in entries) {
|
||||||
ctx.throw(404);
|
ctx.throw(404);
|
||||||
}
|
}
|
||||||
// TODO: check if the file is text file or not (e.g. image)
|
// TODO: check if the file is text file or not (e.g. image)
|
||||||
@ -138,7 +138,7 @@ router.get("/:package([a-z0-9_]*@[a-z0-9_]*)/:version?/:path*", async (ctx) => {
|
|||||||
|
|
||||||
|
|
||||||
app.use(async (ctx, next) => {
|
app.use(async (ctx, next) => {
|
||||||
try{
|
try {
|
||||||
await next();
|
await next();
|
||||||
}
|
}
|
||||||
catch (err) {
|
catch (err) {
|
||||||
@ -156,9 +156,27 @@ app.use(async (ctx, next) => {
|
|||||||
app.use(router.routes());
|
app.use(router.routes());
|
||||||
app.use(router.allowedMethods());
|
app.use(router.allowedMethods());
|
||||||
|
|
||||||
|
app.use(async (ctx, next) => {
|
||||||
|
try {
|
||||||
|
await next();
|
||||||
|
}
|
||||||
|
catch (err) {
|
||||||
|
console.log(err);
|
||||||
|
if (isHttpError(err)) {
|
||||||
|
ctx.response.status = err.status;
|
||||||
|
const { message, status, stack } = err;
|
||||||
|
ctx.response.body = { message, status, stack };
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
throw err;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//app.use(async (ctx, next) => {
|
//app.use(async (ctx, next) => {
|
||||||
// ctx.throw(404);
|
// ctx.throw(404);
|
||||||
// //ctx.response.status = 404;
|
|
||||||
// //ctx.response.body = "Not Found";
|
// //ctx.response.body = "Not Found";
|
||||||
// //await next();
|
// //await next();
|
||||||
//});
|
//});
|
||||||
|
2
gitea.ts
2
gitea.ts
@ -43,7 +43,7 @@ export async function getRepositoryContent(owner:string,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (import.meta.main) {
|
if (import.meta.main) {
|
||||||
const results = await searchRepositoryWithTopic("deno");
|
const results = await searchRepositoryWithTopic("denolib");
|
||||||
console.log(results.data?.map((repo) => repo.full_name));
|
console.log(results.data?.map((repo) => repo.full_name));
|
||||||
const s = await getRepositoryContent("monoid", "script", "", "");
|
const s = await getRepositoryContent("monoid", "script", "", "");
|
||||||
console.log((s as ContentsResponse[]).map((x) => x.name));
|
console.log((s as ContentsResponse[]).map((x) => x.name));
|
||||||
|
Loading…
Reference in New Issue
Block a user