Skip to content

Commit f813d2f

Browse files
committed
feat(*): handle edge cases and redirects
1 parent 13fd758 commit f813d2f

File tree

9 files changed

+74
-45
lines changed

9 files changed

+74
-45
lines changed

Cargo.lock

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

apps/backend/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "ryot"
3-
version = "6.1.5"
3+
version = "6.2.0"
44
edition = "2021"
55
repository = "https://github.com/IgnisDa/ryot"
66
license = "GPL-3.0"

apps/backend/src/miscellaneous/resolver.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -5888,8 +5888,10 @@ impl MiscellaneousService {
58885888
)
58895889
})
58905890
.join(JoinType::Join, genre::Relation::MetadataToGenre.def())
5891-
// fuck it. we ball. (extremely unsafe, guaranteed to fail if table names change)
5892-
.group_by(Expr::cust("genre.id, genre.name"))
5891+
.group_by(Expr::tuple([
5892+
Expr::col(genre::Column::Id).into(),
5893+
Expr::col(genre::Column::Name).into(),
5894+
]))
58935895
.order_by(Expr::col(Alias::new(num_items)), Order::Desc);
58945896
let paginator = query
58955897
.clone()

apps/backend/src/providers/anilist/media_details.graphql

+1
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ query MediaDetailsQuery($id: Int!) {
4848
id
4949
type
5050
title {
51+
english
5152
userPreferred
5253
}
5354
coverImage {

apps/backend/src/providers/anilist/mod.rs

+11-5
Original file line numberDiff line numberDiff line change
@@ -625,10 +625,15 @@ async fn media_details(client: &Client, id: &str, prefer_english: bool) -> Resul
625625
.unwrap()
626626
.into_iter()
627627
.flat_map(|r| {
628-
r.unwrap()
629-
.media_recommendation
630-
.map(|data| PartialMetadataWithoutId {
631-
title: data.title.unwrap().user_preferred.unwrap(),
628+
r.unwrap().media_recommendation.map(|data| {
629+
let title = data.title.unwrap();
630+
let title = if prefer_english {
631+
title.english.or(title.user_preferred).unwrap()
632+
} else {
633+
title.user_preferred.unwrap()
634+
};
635+
PartialMetadataWithoutId {
636+
title,
632637
identifier: data.id.to_string(),
633638
source: MediaSource::Anilist,
634639
lot: match data.type_.unwrap() {
@@ -637,7 +642,8 @@ async fn media_details(client: &Client, id: &str, prefer_english: bool) -> Resul
637642
media_details_query::MediaType::Other(_) => unreachable!(),
638643
},
639644
image: data.cover_image.unwrap().extra_large,
640-
})
645+
}
646+
})
641647
})
642648
.collect();
643649
let score = details.average_score.map(Decimal::from);

apps/frontend/app/lib/utilities.server.ts

+12-5
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
11
import { parseWithZod } from "@conform-to/zod";
22
import { $path } from "@ignisda/remix-routes";
3-
import {
4-
redirect,
5-
unstable_composeUploadHandlers,
6-
unstable_createMemoryUploadHandler,
7-
} from "@remix-run/node";
83
import {
94
type CookieOptions,
105
createCookie,
116
createCookieSessionStorage,
7+
redirect,
8+
unstable_composeUploadHandlers,
9+
unstable_createMemoryUploadHandler,
1210
} from "@remix-run/node";
1311
import {
1412
type CoreDetails,
@@ -400,3 +398,12 @@ export const getUserDetails = async (request: Request) => {
400398
);
401399
return details as ApplicationUser;
402400
};
401+
402+
export const extendResponseHeaders = (
403+
responseHeaders: Headers,
404+
headers: Headers,
405+
) => {
406+
for (const [key, value] of headers.entries())
407+
responseHeaders.append(key, value);
408+
return responseHeaders;
409+
};

apps/frontend/app/routes/actions.tsx

+41-28
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import {
2929
MetadataSpecificsSchema,
3030
colorSchemeCookie,
3131
createToastHeaders,
32+
extendResponseHeaders,
3233
getAuthorizationHeader,
3334
getLogoutCookies,
3435
gqlClient,
@@ -43,7 +44,8 @@ export const action = unstable_defineAction(async ({ request, response }) => {
4344
const url = new URL(request.url);
4445
const intent = url.searchParams.get("intent") as string;
4546
invariant(intent, "No intent provided");
46-
let redirectTo = formData.get(redirectToQueryParam);
47+
const redirectToForm = formData.get(redirectToQueryParam);
48+
let redirectTo = redirectToForm ? redirectToForm.toString() : undefined;
4749
let returnData = {};
4850
await match(intent)
4951
.with("commitMedia", async () => {
@@ -109,7 +111,10 @@ export const action = unstable_defineAction(async ({ request, response }) => {
109111
})
110112
.with("logout", async () => {
111113
redirectTo = $path("/auth");
112-
response.headers = await getLogoutCookies();
114+
response.headers = extendResponseHeaders(
115+
response.headers,
116+
await getLogoutCookies(),
117+
);
113118
})
114119
.with("createReviewComment", async () => {
115120
const submission = processSubmission(formData, reviewCommentSchema);
@@ -118,15 +123,18 @@ export const action = unstable_defineAction(async ({ request, response }) => {
118123
{ input: submission },
119124
await getAuthorizationHeader(request),
120125
);
121-
response.headers = await createToastHeaders({
122-
message:
123-
submission.incrementLikes || submission.decrementLikes
124-
? "Score changed successfully"
125-
: `Comment ${
126-
submission.shouldDelete ? "deleted" : "posted"
127-
} successfully`,
128-
type: "success",
129-
});
126+
response.headers = extendResponseHeaders(
127+
response.headers,
128+
await createToastHeaders({
129+
message:
130+
submission.incrementLikes || submission.decrementLikes
131+
? "Score changed successfully"
132+
: `Comment ${
133+
submission.shouldDelete ? "deleted" : "posted"
134+
} successfully`,
135+
type: "success",
136+
}),
137+
);
130138
})
131139
.with("addEntityToCollection", async () => {
132140
const [submission, input] =
@@ -147,10 +155,13 @@ export const action = unstable_defineAction(async ({ request, response }) => {
147155
await getAuthorizationHeader(request),
148156
);
149157
}
150-
response.headers = await createToastHeaders({
151-
message: "Media added to collection successfully",
152-
type: "success",
153-
});
158+
response.headers = extendResponseHeaders(
159+
response.headers,
160+
await createToastHeaders({
161+
message: "Media added to collection successfully",
162+
type: "success",
163+
}),
164+
);
154165
})
155166
.with("removeEntityFromCollection", async () => {
156167
const [submission, input] =
@@ -176,32 +187,34 @@ export const action = unstable_defineAction(async ({ request, response }) => {
176187
{ reviewId: submission.reviewId },
177188
await getAuthorizationHeader(request),
178189
);
179-
response.headers = await createToastHeaders({
180-
message: "Review deleted successfully",
181-
type: "success",
182-
});
190+
response.headers = extendResponseHeaders(
191+
response.headers,
192+
await createToastHeaders({
193+
message: "Review deleted successfully",
194+
type: "success",
195+
}),
196+
);
183197
} else {
184198
await gqlClient.request(
185199
PostReviewDocument,
186200
{ input: submission },
187201
await getAuthorizationHeader(request),
188202
);
189-
response.headers = await createToastHeaders({
190-
message: "Review submitted successfully",
191-
type: "success",
192-
});
203+
response.headers = extendResponseHeaders(
204+
response.headers,
205+
await createToastHeaders({
206+
message: "Review submitted successfully",
207+
type: "success",
208+
}),
209+
);
193210
}
194211
})
195212
.run();
196213
if (redirectTo) {
197214
response.headers.append("Location", redirectTo.toString());
198215
response.status = 302;
199216
}
200-
// FIXME Once https://discord.com/channels/770287896669978684/1251219797098762290 is resolved
201-
return Response.json(returnData, {
202-
headers: response.headers,
203-
status: response.status,
204-
});
217+
return Response.json(returnData);
205218
});
206219

207220
const commitMediaSchema = z.object({

apps/frontend/app/routes/api.auth.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,5 +43,5 @@ export const loader = unstable_defineLoader(async ({ request }) => {
4343
),
4444
});
4545
}
46-
return { input };
46+
return Response.json({ input });
4747
});

apps/frontend/app/routes/api.fitness.exercises.$id.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ export const loader = unstable_defineLoader(async ({ request, params }) => {
1717
await getAuthorizationHeader(request),
1818
),
1919
]);
20-
return {
20+
return Response.json({
2121
details: { images: exerciseDetails.attributes.images },
2222
history: userExerciseDetails.history,
23-
};
23+
});
2424
});

0 commit comments

Comments
 (0)