Skip to content

Commit

Permalink
Don't create routes for drafts
Browse files Browse the repository at this point in the history
  • Loading branch information
zephraph authored and gitbutler-client committed Sep 16, 2024
1 parent acb404f commit b0e3939
Showing 1 changed file with 22 additions and 19 deletions.
41 changes: 22 additions & 19 deletions src/pages/api/[...path].ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,27 +26,30 @@ const app = new Hono<{ Bindings: AstroContext }>()
.post("/notes/:id", async (c) => {
const id = c.req.param("id");
const props: Record<string, any> = c.req.query();
let slug = props.slug || slugify(props.title);
if (isULID(slug)) {
throw new Error("Title or H1s should not be a ULID");
}
if (!props.draft && !props.homepage) {
let slug = props.slug || slugify(props.title);
if (isULID(slug)) {
throw new Error("Title or H1s should not be a ULID");
}

const primaryTag = props.tags?.split(",")[0];
// Set the prefix URL to the first tag (or it's mapped value) if it exists
if (primaryTag && primaryTag !== slug) {
slug = `${
tagMap[primaryTag as keyof typeof tagMap] ?? props.tags[0]
}/${slug}`;
}
await c.env.KV_MAPPINGS.get(slug).then((mappedID) => {
if (mappedID && mappedID !== id) {
throw new Error(`Slug ${slug} is already mapped to ${mappedID}`);
const primaryTag = props.tags?.split(",")[0];
// Set the prefix URL to the first tag (or it's mapped value) if it exists
if (primaryTag && primaryTag !== slug) {
slug = `${
tagMap[primaryTag as keyof typeof tagMap] ?? props.tags[0]
}/${slug}`;
}
return Promise.all([
c.env.KV_MAPPINGS.put(slug, id),
c.env.KV_MAPPINGS.put(id, slug),
]);
});
await c.env.KV_MAPPINGS.get(slug).then((mappedID) => {
if (mappedID && mappedID !== id) {
throw new Error(`Slug ${slug} is already mapped to ${mappedID}`);
}
return Promise.all([
c.env.KV_MAPPINGS.put(slug, id),
c.env.KV_MAPPINGS.put(id, slug),
]);
});
}

const result = await c.env.R2_BUCKET.put(id, await c.req.blob(), {
onlyIf: { etagDoesNotMatch: c.req.header("If-None-Match") },
});
Expand Down

0 comments on commit b0e3939

Please sign in to comment.