Compare commits

..

No commits in common. "8a67f4fbdbbabe9d8f8b2e9baba1df92e415a9c4" and "750c81f4cb3d23e3f479e1514e1a280af39c3aa3" have entirely different histories.

2 changed files with 12 additions and 30 deletions

38
app.ts
View File

@ -1,4 +1,4 @@
import { Application, Router, isHttpError } from "https://deno.land/x/oak@v12.1.0/mod.ts"; import { Application, Router, HttpError, 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();
@ -46,7 +46,7 @@ router.get("/.well-known/deno-import-intellisense.json", (ctx) => {
"variables": [ "variables": [
{ {
"key": "package", "key": "package",
// "documentation": "/docs/packages/${package}", // "documentation": "/docs/packages/${package}",
"url": "/packages/${package}" "url": "/packages/${package}"
}, },
{ {
@ -55,7 +55,7 @@ router.get("/.well-known/deno-import-intellisense.json", (ctx) => {
}, },
{ {
"key": "path", "key": "path",
// "documentation": "/docs/packages/${package}/${{version}}/paths/${path}", // "documentation": "/docs/packages/${package}/${{version}}/paths/${path}",
"url": "/packages/${package}/${{version}}/paths/${path}" "url": "/packages/${package}/${{version}}/paths/${path}"
} }
] ]
@ -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,27 +156,9 @@ 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();
//}); //});

View File

@ -43,8 +43,8 @@ export async function getRepositoryContent(owner:string,
} }
if (import.meta.main) { if (import.meta.main) {
const results = await searchRepositoryWithTopic("denolib"); const results = await searchRepositoryWithTopic("deno");
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));
} }