fix(posts): Decode URL-encoded post IDs in API routes
- Add decodeURIComponent() to handle URL-encoded characters in post IDs - Update like endpoint POST and DELETE handlers to decode rawId parameter - Update repost endpoint POST and DELETE handlers to decode rawId parameter - Update post retrieval GET handler to decode rawId parameter - Fixes issues with special characters (e.g., %3A for colons) in post identifiers
This commit is contained in:
@@ -34,7 +34,8 @@ function extractSwarmPostId(apId: string): string | null {
|
|||||||
export async function POST(request: Request, context: RouteContext) {
|
export async function POST(request: Request, context: RouteContext) {
|
||||||
try {
|
try {
|
||||||
const user = await requireAuth();
|
const user = await requireAuth();
|
||||||
const { id: postId } = await context.params;
|
const { id: rawId } = await context.params;
|
||||||
|
const postId = decodeURIComponent(rawId);
|
||||||
const nodeDomain = process.env.NEXT_PUBLIC_NODE_DOMAIN || 'localhost:3000';
|
const nodeDomain = process.env.NEXT_PUBLIC_NODE_DOMAIN || 'localhost:3000';
|
||||||
|
|
||||||
if (user.isSuspended || user.isSilenced) {
|
if (user.isSuspended || user.isSilenced) {
|
||||||
@@ -210,7 +211,8 @@ export async function POST(request: Request, context: RouteContext) {
|
|||||||
export async function DELETE(request: Request, context: RouteContext) {
|
export async function DELETE(request: Request, context: RouteContext) {
|
||||||
try {
|
try {
|
||||||
const user = await requireAuth();
|
const user = await requireAuth();
|
||||||
const { id: postId } = await context.params;
|
const { id: rawId } = await context.params;
|
||||||
|
const postId = decodeURIComponent(rawId);
|
||||||
const nodeDomain = process.env.NEXT_PUBLIC_NODE_DOMAIN || 'localhost:3000';
|
const nodeDomain = process.env.NEXT_PUBLIC_NODE_DOMAIN || 'localhost:3000';
|
||||||
|
|
||||||
if (user.isSuspended || user.isSilenced) {
|
if (user.isSuspended || user.isSilenced) {
|
||||||
|
|||||||
@@ -34,7 +34,8 @@ function extractSwarmPostId(apId: string): string | null {
|
|||||||
export async function POST(request: Request, context: RouteContext) {
|
export async function POST(request: Request, context: RouteContext) {
|
||||||
try {
|
try {
|
||||||
const user = await requireAuth();
|
const user = await requireAuth();
|
||||||
const { id: postId } = await context.params;
|
const { id: rawId } = await context.params;
|
||||||
|
const postId = decodeURIComponent(rawId);
|
||||||
const nodeDomain = process.env.NEXT_PUBLIC_NODE_DOMAIN || 'localhost:3000';
|
const nodeDomain = process.env.NEXT_PUBLIC_NODE_DOMAIN || 'localhost:3000';
|
||||||
|
|
||||||
if (user.isSuspended || user.isSilenced) {
|
if (user.isSuspended || user.isSilenced) {
|
||||||
@@ -229,7 +230,8 @@ export async function POST(request: Request, context: RouteContext) {
|
|||||||
export async function DELETE(request: Request, context: RouteContext) {
|
export async function DELETE(request: Request, context: RouteContext) {
|
||||||
try {
|
try {
|
||||||
const user = await requireAuth();
|
const user = await requireAuth();
|
||||||
const { id: postId } = await context.params;
|
const { id: rawId } = await context.params;
|
||||||
|
const postId = decodeURIComponent(rawId);
|
||||||
const nodeDomain = process.env.NEXT_PUBLIC_NODE_DOMAIN || 'localhost:3000';
|
const nodeDomain = process.env.NEXT_PUBLIC_NODE_DOMAIN || 'localhost:3000';
|
||||||
|
|
||||||
if (user.isSuspended || user.isSilenced) {
|
if (user.isSuspended || user.isSilenced) {
|
||||||
|
|||||||
@@ -8,7 +8,9 @@ export async function GET(
|
|||||||
{ params }: { params: Promise<{ id: string }> }
|
{ params }: { params: Promise<{ id: string }> }
|
||||||
) {
|
) {
|
||||||
try {
|
try {
|
||||||
const { id } = await params;
|
const { id: rawId } = await params;
|
||||||
|
// Decode URL-encoded characters (e.g., %3A -> :)
|
||||||
|
const id = decodeURIComponent(rawId);
|
||||||
|
|
||||||
const nodeDomain = process.env.NEXT_PUBLIC_NODE_DOMAIN || 'localhost:3000';
|
const nodeDomain = process.env.NEXT_PUBLIC_NODE_DOMAIN || 'localhost:3000';
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user