Skip to content

Commit

Permalink
Short link feature
Browse files Browse the repository at this point in the history
  • Loading branch information
Sendouc committed Dec 26, 2024
1 parent c418b8c commit ca972ec
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 0 deletions.
5 changes: 5 additions & 0 deletions app/features/info/routes/support.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@ const PERKS = [
name: "prioritySupport",
extraInfo: true,
},
{
tier: 2,
name: "userShortLink",
extraInfo: true,
},
{
tier: 2,
name: "customizedColorsUser",
Expand Down
8 changes: 8 additions & 0 deletions app/features/user-page/UserRepository.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,14 @@ export async function findProfileByIdentifier(
};
}

export function findByCustomUrl(customUrl: string) {
return db
.selectFrom("User")
.select(["User.id", "User.discordId", "User.customUrl", "User.patronTier"])
.where("customUrl", "=", customUrl)
.executeTakeFirst();
}

export function findBannedStatusByUserId(userId: number) {
return db
.selectFrom("User")
Expand Down
15 changes: 15 additions & 0 deletions app/features/user-page/routes/short.$customUrl.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import type { LoaderFunction } from "@remix-run/node";
import { redirect } from "react-router-dom";
import * as UserRepository from "~/features/user-page/UserRepository.server";
import { userPage } from "~/utils/urls";
import { isAtLeastFiveDollarTierPatreon } from "~/utils/users";

export const loader: LoaderFunction = async ({ params }) => {
const user = await UserRepository.findByCustomUrl(params.customUrl!);

if (!user || !isAtLeastFiveDollarTierPatreon(user)) {
return redirect("/");
}

return redirect(userPage(user));
};
1 change: 1 addition & 0 deletions app/features/user-page/routes/u.$identifier.edit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,7 @@ function CustomUrlInput({
maxLength={USER.CUSTOM_URL_MAX_LENGTH}
defaultValue={parentRouteData.user.customUrl ?? undefined}
/>
<FormMessage type="info">{t("user:forms.info.customUrl")}</FormMessage>
</div>
);
}
Expand Down
2 changes: 2 additions & 0 deletions app/routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,8 @@ export default [
route("/org/:id", "features/api-public/routes/org.$id.ts"),
]),

route("/short/:customUrl", "features/user-page/routes/short.$customUrl.tsx"),

route("/theme", "features/theme/routes/theme.ts"),

...prefix("/auth", [
Expand Down
2 changes: 2 additions & 0 deletions locales/en/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,8 @@
"support.perk.seePlusPercentage.extra": "Normally only failed suggests see their voting percentage. With this, you can always see your own percentage.",
"support.perk.autoValidatePictures": "Auto validate uploaded pictures",
"support.perk.autoValidatePictures.extra": "Any images you upload (e.g. team profile/banner picture) get automatically validated. Normally it needs a moderator's approval first. Note that this doesn't apply to images that were already submitted.",
"support.perk.userShortLink": "User page short link",
"support.perk.userShortLink.extra": "Instead of e.g. sendou.ink/u/sendou you can also use snd.ink/sendou when linking to your user profile.",
"support.perk.customizedColorsUser": "Customize colors (user page)",
"support.perk.customizedColorsTeam": "Customize colors (team page)",
"support.perk.customizedColorsTeam.extra": "It is enough that one member of the team is a patron to get this perk.",
Expand Down
1 change: 1 addition & 0 deletions locales/en/user.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
"forms.errors.invalidCustomUrl.strangeCharacter": "Custom URL can't contain special characters",
"forms.errors.invalidCustomUrl.duplicate": "Someone is already using this custom URL",
"forms.errors.invalidSens": "Motion sens can't be set if R-stick sens isn't",
"forms.info.customUrl": "For patrons (Supporter & above) short link is available. E.g. instead of sendou.ink/u/sendou, snd.ink/sendou can be used.",
"forms.info.favoriteBadge": "Your favorite badge is shown as big by default on your profile.",
"forms.info.battlefy": "Battlefy account name is used for seeding and verification in some tournaments",

Expand Down

0 comments on commit ca972ec

Please sign in to comment.