Add shell script for uploading files to drift

This commit is contained in:
Max Leiter 2023-02-26 01:15:17 -08:00
parent 806b173d22
commit 9c3375cbd0
4 changed files with 98 additions and 5 deletions

View file

@ -13,7 +13,6 @@ export async function GET(
}
}
) {
console.log("GET /api/file/raw/[fileId]/route.ts")
const id = params.fileId
const download = new URL(req.url).searchParams.get("download") === "true"
@ -34,7 +33,6 @@ export async function GET(
const { title, content: contentBuffer } = file
const content = contentBuffer.toString("utf-8")
console.log("title", title)
let headers: HeadersInit = {
"Content-Type": "text/plain; charset=utf-8",
"Cache-Control": "s-maxage=86400"

View file

@ -41,7 +41,6 @@ export default function HomePage({
<Item
shortcut="T"
onSelect={() => {
console.log("toggle theme", resolvedTheme)
setTheme(resolvedTheme === "dark" ? "light" : "dark")
}}
icon={resolvedTheme === "dark" ? <Sun /> : <Moon />}

View file

@ -8,12 +8,15 @@ import { getHtmlFromFile } from "@lib/server/get-html-from-drift-file"
import { verifyApiUser } from "@lib/server/verify-api-user"
async function handlePost(req: NextApiRequest, res: NextApiResponse<unknown>) {
console.log("Handling post request")
try {
const userId = await verifyApiUser(req, res)
if (!userId) {
return res.status(401).json({ error: "Unauthorized" })
}
console.log("User is authenticated")
const files = req.body.files as (Omit<ServerFile, "content" | "html"> & {
content: string
html: string
@ -23,9 +26,10 @@ async function handlePost(req: NextApiRequest, res: NextApiResponse<unknown>) {
if (missingTitles.length > 0) {
throw new Error("All files must have a title")
}
console.log("All files have titles")
if (files.length === 0) {
throw new Error("You must submit at least one file")
throw new Error("You must submit at lea st one file")
}
let hashedPassword = ""
@ -80,12 +84,17 @@ async function handlePost(req: NextApiRequest, res: NextApiResponse<unknown>) {
})
return res.json(post)
} catch (error) {
console.error(error)
return res.status(500).json(error)
}
}
const handler = async (req: NextApiRequest, res: NextApiResponse) => {
return await handlePost(req, res)
try {
return await handlePost(req, res)
} catch (error) {
return res.status(500).json(error)
}
}
export default withMethods(["POST"], handler)