Skip to content

Commit 2aac3b7

Browse files
committed
Improve canvas handling
1 parent 6c7692e commit 2aac3b7

2 files changed

Lines changed: 37 additions & 0 deletions

File tree

features/quilts/service.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,19 @@ export async function submitQuiltPixels({
303303
if (quilt.endsAt.getTime() <= Date.now()) {
304304
throw new BadRequestError("This quilt has ended.");
305305
}
306+
const existingPending = await db.quiltSubmission.findFirst({
307+
where: {
308+
quiltId: quilt.id,
309+
authorId: actor.id,
310+
status: QuiltSubmissionStatus.PENDING,
311+
},
312+
select: { id: true },
313+
});
314+
if (existingPending) {
315+
throw new BadRequestError(
316+
"You already have a pending quilt change. Edit it instead of submitting another one.",
317+
);
318+
}
306319
const unique = new Map<string, QuiltPixel>();
307320
for (const pixel of input.pixels) {
308321
if (pixel.x >= quilt.width || pixel.y >= quilt.height) {

features/users/profile.assets.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,36 @@
11
import { appConfig } from "../../config/app.js";
22
import { env } from "../../config/env.js";
33

4+
function isUploadApiPath(pathname: string) {
5+
const apiBasePath = appConfig.uploads.apiBasePath.replace(/\/$/, "");
6+
return (
7+
pathname.startsWith(
8+
`${apiBasePath}/${appConfig.uploads.imageRoute}/`,
9+
) ||
10+
pathname.startsWith(
11+
`${apiBasePath}/${appConfig.uploads.profileImageRoute}/`,
12+
)
13+
);
14+
}
15+
416
export function isAllowedAssetUrl(value: unknown): boolean {
517
if (value === null || value === undefined || value === "") return true;
618
if (typeof value !== "string") return false;
19+
if (isUploadApiPath(value)) return true;
720
if (value.startsWith(appConfig.uploads.staticImagesPath)) {
821
return true;
922
}
23+
try {
24+
const parsed = new URL(value);
25+
if (
26+
(parsed.protocol === "http:" || parsed.protocol === "https:") &&
27+
isUploadApiPath(parsed.pathname)
28+
) {
29+
return true;
30+
}
31+
} catch {
32+
// Relative URLs are handled above.
33+
}
1034
if (value.startsWith(`${appConfig.publicOrigin}${appConfig.uploads.staticImagesPath}`)) {
1135
return true;
1236
}

0 commit comments

Comments
 (0)