lvin
lvin
DDeno
Created by lvin on 7/16/2023 in #help
not sure why this code is erroring
the name parameter for Deno.writefile was undefined instead of a string so thats why shit borked
13 replies
DDeno
Created by lvin on 7/16/2023 in #help
not sure why this code is erroring
nah, functions only need to be tagged w/ async if im using await inside them. the map converts all the urls Array<string> to Array<Promise<{name:string,videos:Array<Video>}>> hence why i can use promise.all with it
13 replies
DDeno
Created by lvin on 7/16/2023 in #help
not sure why this code is erroring
horrible error message
13 replies
DDeno
Created by lvin on 7/16/2023 in #help
not sure why this code is erroring
no that function is synchrous, and using writeTextFileSync doesn't help either
13 replies
DDeno
Created by lvin on 2/10/2023 in #help
importing packages breaks types
7 replies
DDeno
Created by lvin on 2/10/2023 in #help
importing packages breaks types
7 replies
DDeno
Created by lvin on 2/10/2023 in #help
importing packages breaks types
here is all the code
import { Status } from "https://deno.land/std@0.177.0/http/http_status.ts";
import { Application, Router } from "https://deno.land/x/oak@v11.1.0/mod.ts";
import { loadManifest } from "./manifestloader.ts";
import { Receiver } from "https://deno.land/x/upstash_qstash@v0.3.6/mod.ts";

const app = new Application();
const router = new Router();

router.get("/items/:itemType", async (ctx) => {
const name = `${ctx.params.itemType}.json`;
const jsonFiles = [];
for await (const path of Deno.readDir("./assets")) {
jsonFiles.push(path.name);
}
for (const file of jsonFiles) {
if (file === name) {
const fileName = `assets/${name}`;
console.log(file, fileName);
ctx.response.status = 200;
ctx.response.headers.set("Content-Type", "application/json");
ctx.response.body = JSON.parse(await Deno.readTextFile(fileName));
}
}
ctx.response.status = Status.NotFound;
});

router.get("/process-manifest", async (ctx) => {
const token = ctx.request.headers.get("authorization");
if (token === "123") {
ctx.response.status = Status.Unauthorized;
ctx.response.body = JSON.stringify({ error: "unauthorised" });
return;
}
await loadManifest().then(() => {
ctx.response.status = 200;
ctx.response.body = JSON.stringify({ message: "success" });
});
});

app.use(router.routes());
await app.listen({ port: 8000 });
import { Status } from "https://deno.land/std@0.177.0/http/http_status.ts";
import { Application, Router } from "https://deno.land/x/oak@v11.1.0/mod.ts";
import { loadManifest } from "./manifestloader.ts";
import { Receiver } from "https://deno.land/x/upstash_qstash@v0.3.6/mod.ts";

const app = new Application();
const router = new Router();

router.get("/items/:itemType", async (ctx) => {
const name = `${ctx.params.itemType}.json`;
const jsonFiles = [];
for await (const path of Deno.readDir("./assets")) {
jsonFiles.push(path.name);
}
for (const file of jsonFiles) {
if (file === name) {
const fileName = `assets/${name}`;
console.log(file, fileName);
ctx.response.status = 200;
ctx.response.headers.set("Content-Type", "application/json");
ctx.response.body = JSON.parse(await Deno.readTextFile(fileName));
}
}
ctx.response.status = Status.NotFound;
});

router.get("/process-manifest", async (ctx) => {
const token = ctx.request.headers.get("authorization");
if (token === "123") {
ctx.response.status = Status.Unauthorized;
ctx.response.body = JSON.stringify({ error: "unauthorised" });
return;
}
await loadManifest().then(() => {
ctx.response.status = 200;
ctx.response.body = JSON.stringify({ message: "success" });
});
});

app.use(router.routes());
await app.listen({ port: 8000 });
7 replies
DDeno
Created by lvin on 12/16/2022 in #help
i think the language server is broken
seems to have fixed it thanks
5 replies
DDeno
Created by lvin on 12/16/2022 in #help
i think the language server is broken
5 replies
DDeno
Created by lvin on 11/21/2022 in #help
types not inferred from npm packages
import { effect } from "@preact/signals";
import { deepSignal } from "npm:@deepsignal/preact";
type UserNameStore = {
first: string;
last: string;
};

const getInitialUserNameStore = (): UserNameStore => {
const storedUserStore = localStorage.getItem("USER_NAME_STORE_KEY");
return storedUserStore
? JSON.parse(storedUserStore)
: { first: "", last: "" };
};

const userStore = deepSignal({
name: getInitialUserNameStore(),
email: "",
});

effect(() =>
localStorage.setItem(
"USER_NAME_STORE_KEY",
JSON.stringify(userStore.name.value)
)
);
import { effect } from "@preact/signals";
import { deepSignal } from "npm:@deepsignal/preact";
type UserNameStore = {
first: string;
last: string;
};

const getInitialUserNameStore = (): UserNameStore => {
const storedUserStore = localStorage.getItem("USER_NAME_STORE_KEY");
return storedUserStore
? JSON.parse(storedUserStore)
: { first: "", last: "" };
};

const userStore = deepSignal({
name: getInitialUserNameStore(),
email: "",
});

effect(() =>
localStorage.setItem(
"USER_NAME_STORE_KEY",
JSON.stringify(userStore.name.value)
)
);
3 replies