-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
135 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
# Fresh project | ||
# FreshPaste | ||
|
||
Simple pastebin-like made using deno fresh | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,78 @@ | ||
import { asset } from "$fresh/runtime.ts"; | ||
import { Head } from "$fresh/runtime.ts"; | ||
|
||
export default function Error404() { | ||
export default function API() { | ||
return ( | ||
<> | ||
<div class="px-4 py-8 mx-auto"> | ||
<div class="max-w-screen-md mx-auto flex flex-col items-center justify-center"> | ||
<img | ||
class="my-6" | ||
src="/logo.svg" | ||
width="128" | ||
height="128" | ||
alt="the Fresh logo: a sliced lemon dripping with juice" | ||
/> | ||
<h1 class="text-4xl font-bold">Not made yet</h1> | ||
<p class="my-4"> | ||
Come back later to see what we have to offer. | ||
<Head> | ||
<script src={asset("prism.js")}></script> | ||
<link | ||
href={asset("prism.css")} | ||
rel="stylesheet" | ||
> | ||
</link> | ||
</Head> | ||
|
||
<section class="mt-8"> | ||
<div class="flex flex-col justify-between items-center gap-16"> | ||
<div class="flex justify-center items-center flex-col gap-2 w-full"> | ||
<div class="flex gap-1 items-center justify-center w-full"> | ||
<p class="text-1xl font-bold bg-gray-300 rounded w-fit p-1"> | ||
POST | ||
</p> | ||
<input | ||
class="bg-white border-gray-500 border-2 rounded text-center p-1 w-96" | ||
disabled | ||
value="https://clear-cow-12.deno.dev/api/new/" | ||
/> | ||
</div> | ||
<p>Allows you to create a new paste.</p> | ||
<p> | ||
{'{"content":"Hi", "syntax":"plain"}'} | ||
</p> | ||
</div> | ||
|
||
<div class="flex justify-center items-center flex-col gap-2 w-full"> | ||
<div class="flex gap-1 items-center justify-center w-full"> | ||
<p class="text-1xl font-bold bg-gray-300 rounded w-fit p-1"> | ||
GET | ||
</p> | ||
<input | ||
class="bg-white border-gray-500 border-2 rounded text-center p-1 w-96" | ||
disabled | ||
value="https://clear-cow-12.deno.dev/api/{id}" | ||
/> | ||
</div> | ||
<p>Allows you to view the full data.</p> | ||
<p> | ||
{"{id} equals id of the paste"} | ||
</p> | ||
</div> | ||
|
||
<div class="flex justify-center items-center flex-col gap-2 w-full"> | ||
<div class="flex gap-1 items-center justify-center w-full"> | ||
<p class="text-1xl font-bold bg-gray-300 rounded w-fit p-1"> | ||
GET | ||
</p> | ||
<input | ||
class="bg-white border-gray-500 border-2 rounded text-center p-1 w-96" | ||
disabled | ||
value="https://clear-cow-12.deno.dev/api/raw/{id}" | ||
/> | ||
</div> | ||
<p>Allows you to view the raw content.</p> | ||
<p> | ||
{"{id} equals id of the paste"} | ||
</p> | ||
</div> | ||
|
||
<p class=" bg-gray-300 rounded w-fit p-1"> | ||
Pastes gets expired after 30 days! | ||
</p> | ||
<a href="/" class="underline">Go back home</a> | ||
</div> | ||
</div> | ||
<div> | ||
</div> | ||
</section> | ||
</> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,23 @@ | ||
import { FreshContext } from "$fresh/server.ts"; | ||
import { Handlers } from "$fresh/server.ts"; | ||
import { get } from "../../utils/db.ts"; | ||
|
||
// @ts-ignore | ||
export const handler = async (_req: Request, _ctx: FreshContext): Response => { | ||
const id = _ctx.params.paste; | ||
const paste = await get(id); | ||
if (!paste) { | ||
return new Response(null, { | ||
status: 404, | ||
}); | ||
} | ||
export const handler: Handlers = { | ||
async GET(_, ctx) { | ||
const id = ctx.params.paste; | ||
const paste = await get(id); | ||
if (!paste) { | ||
return new Response(JSON.stringify({ error: "paste not found" }), { | ||
status: 404, | ||
headers: { | ||
"content-type": "application/json", | ||
}, | ||
}); | ||
} | ||
|
||
// @ts-ignore | ||
return new Response(JSON.stringify(paste), { | ||
headers: { | ||
"content-type": "application/json", | ||
}, | ||
}); | ||
return new Response(JSON.stringify(paste), { | ||
headers: { | ||
"content-type": "application/json", | ||
}, | ||
}); | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { Handlers } from "$fresh/server.ts"; | ||
import { set } from "../../utils/db.ts"; | ||
|
||
export const handler: Handlers = { | ||
async POST(req) { | ||
const body = await req.json(); | ||
const [content, syntax] = [body.content, body.syntax]; | ||
if (!content || !syntax) { | ||
return new Response( | ||
JSON.stringify({ error: "content and syntax are required" }), | ||
{ | ||
status: 404, | ||
headers: { | ||
"content-type": "application/json", | ||
}, | ||
}, | ||
); | ||
} | ||
const id = set(content, syntax); | ||
return new Response(JSON.stringify({ id }), { | ||
headers: { | ||
"content-type": "application/json", | ||
}, | ||
}); | ||
}, | ||
}; |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,16 @@ | ||
import { FreshContext } from "$fresh/server.ts"; | ||
import { Handlers } from "$fresh/server.ts"; | ||
import { get } from "../../../utils/db.ts"; | ||
|
||
// @ts-ignore | ||
export const handler = async (_req: Request, _ctx: FreshContext): Response => { | ||
const id = _ctx.params.paste; | ||
const paste = await get(id); | ||
if (!paste) { | ||
return new Response(null, { | ||
status: 404, | ||
}); | ||
} | ||
|
||
// @ts-ignore | ||
return new Response(paste.content); | ||
export const handler: Handlers = { | ||
async GET(_, ctx) { | ||
const id = ctx.params.paste; | ||
const paste = await get(id); | ||
if (!paste) { | ||
return new Response("Paste not found!.", { | ||
status: 404, | ||
}); | ||
} | ||
// @ts-ignore | ||
return new Response(paste.content); | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters