Skip to content

Commit

Permalink
feat: parametrize issue list
Browse files Browse the repository at this point in the history
as of issue #3
  • Loading branch information
eliseomartelli committed Jul 18, 2024
1 parent f14aae2 commit 5b6924f
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 13 deletions.
28 changes: 18 additions & 10 deletions routes/api/delete/[name]/index.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,23 @@
import { Handlers } from "$fresh/server.ts";
import { configurationRepository } from "../../../../data/configurationRepository.ts";
import {
configurationRepository,
fileConfigurationManager,
} from "../../../../data/configurationRepository.ts";
import { toolRepository } from "../../../../data/toolsrepository.ts";
import { TOOL_CONF } from "../../../../env.ts";

export const handler: Handlers = {
async DELETE(_, ctx) {
const { name } = ctx.params;
await toolRepository.delete(name).catch(() => {
return new Response("", { status: 404 });
}).then(() => {
configurationRepository(toolRepository).update();
});
return new Response(JSON.stringify(""), { status: 200 });
},
async DELETE(_, ctx) {
const cfgRepository = configurationRepository(
toolRepository,
fileConfigurationManager(TOOL_CONF),
);
const { name } = ctx.params;
await toolRepository.delete(name).catch(() => {
return new Response("", { status: 404 });
}).then(() => {
cfgRepository.update();
});
return new Response(JSON.stringify(""), { status: 200 });
},
};
14 changes: 11 additions & 3 deletions routes/api/upload/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,20 @@ import { Handlers, PageProps } from "$fresh/server.ts";
import { JSX } from "preact";
import { isXML, toolRepository } from "../../../data/toolsrepository.ts";
import { join } from "$std/path/join.ts";
import { TOOL_DIR } from "../../../env.ts";
import { TOOL_CONF, TOOL_DIR } from "../../../env.ts";
import { Head } from "$fresh/runtime.ts";
import { configurationRepository } from "../../../data/configurationRepository.ts";
import {
configurationRepository,
fileConfigurationManager,
} from "../../../data/configurationRepository.ts";

export const handler: Handlers = {
async POST(req, ctx) {
const cfgRepository = configurationRepository(
toolRepository,
fileConfigurationManager(TOOL_CONF),
);

const form = await req.formData();
const file = form.get("tool-file") as File;
if (!file) {
Expand All @@ -22,7 +30,7 @@ export const handler: Handlers = {
}
await Deno.writeTextFile(join(TOOL_DIR, name), await file.text()).then(
() => {
configurationRepository(toolRepository).update();
cfgRepository.update();
},
);
return ctx.render({ message: `${name} uploaded.`, status: Status.ok });
Expand Down

0 comments on commit 5b6924f

Please sign in to comment.