Skip to content

Commit

Permalink
✨ shorten story URLs with URI-coded base64 (#101)
Browse files Browse the repository at this point in the history
  • Loading branch information
haliphax committed Sep 20, 2023
1 parent a071e6e commit 87e0ce1
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/models/story.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,18 @@ import { Vote } from "./vote";
const ownerOnly = (e?: Story, remult?: Remult) =>
!e?.owner || remult?.user?.id === e?.owner;

const generateId = () =>
encodeURIComponent(
Buffer.from(v4().replace("-", ""), "hex").toString("base64"),
);

@Entity<Story>("story", {
allowApiCrud: true,
saved: (r) => updateStory(r),
})
export class Story {
@Fields.string({ allowApiUpdate: false, validate: Validators.unique })
id: string = v4();
id: string = generateId();

@Fields.string<Story>({ allowApiUpdate: ownerOnly })
owner!: string;
Expand Down

0 comments on commit 87e0ce1

Please sign in to comment.