mirror of
https://github.com/trafficlunar/tomodachi-share.git
synced 2026-05-13 13:17:45 +00:00
Compare commits
5 commits
90c2f4dc94
...
0d11b41a45
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0d11b41a45 | ||
| a000447b0a | |||
| 0ede4c7260 | |||
| ed9a480385 | |||
| c24cc3dc01 |
9 changed files with 53 additions and 14 deletions
|
|
@ -30,5 +30,14 @@ export async function POST(request: NextRequest) {
|
||||||
return rateLimit.sendResponse({ error: "Failed to update description" }, 500);
|
return rateLimit.sendResponse({ error: "Failed to update description" }, 500);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Tell Cloudflare to purge cache
|
||||||
|
fetch(`https://api.cloudflare.com/client/v4/zones/${process.env.CLOUDFLARE_ZONE_ID}/purge_cache`, {
|
||||||
|
method: "POST",
|
||||||
|
headers: { Authorization: `Bearer ${process.env.CLOUDFLARE_API_TOKEN}`, "Content-Type": "application/json" },
|
||||||
|
body: JSON.stringify({
|
||||||
|
files: [`${process.env.NEXT_PUBLIC_BASE_URL}/api/profile/${session.user?.id}/info`],
|
||||||
|
}),
|
||||||
|
});
|
||||||
|
|
||||||
return rateLimit.sendResponse({ success: true });
|
return rateLimit.sendResponse({ success: true });
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -33,5 +33,14 @@ export async function POST(request: NextRequest) {
|
||||||
return rateLimit.sendResponse({ error: "Failed to update name" }, 500);
|
return rateLimit.sendResponse({ error: "Failed to update name" }, 500);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Tell Cloudflare to purge cache
|
||||||
|
fetch(`https://api.cloudflare.com/client/v4/zones/${process.env.CLOUDFLARE_ZONE_ID}/purge_cache`, {
|
||||||
|
method: "POST",
|
||||||
|
headers: { Authorization: `Bearer ${process.env.CLOUDFLARE_API_TOKEN}`, "Content-Type": "application/json" },
|
||||||
|
body: JSON.stringify({
|
||||||
|
files: [`${process.env.NEXT_PUBLIC_BASE_URL}/api/profile/${session.user.id}/info`],
|
||||||
|
}),
|
||||||
|
});
|
||||||
|
|
||||||
return rateLimit.sendResponse({ success: true });
|
return rateLimit.sendResponse({ success: true });
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -81,5 +81,17 @@ export async function POST(request: NextRequest) {
|
||||||
return rateLimit.sendResponse({ error: "Failed to update profile picture" }, 500);
|
return rateLimit.sendResponse({ error: "Failed to update profile picture" }, 500);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Tell Cloudflare to purge cache
|
||||||
|
fetch(`https://api.cloudflare.com/client/v4/zones/${process.env.CLOUDFLARE_ZONE_ID}/purge_cache`, {
|
||||||
|
method: "POST",
|
||||||
|
headers: { Authorization: `Bearer ${process.env.CLOUDFLARE_API_TOKEN}`, "Content-Type": "application/json" },
|
||||||
|
body: JSON.stringify({
|
||||||
|
files: [
|
||||||
|
`${process.env.NEXT_PUBLIC_BASE_URL}/api/profile/${session.user?.id}/info`,
|
||||||
|
`${process.env.NEXT_PUBLIC_BASE_URL}/profile/${session.user?.id}/picture`,
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
});
|
||||||
|
|
||||||
return rateLimit.sendResponse({ success: true });
|
return rateLimit.sendResponse({ success: true });
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -156,6 +156,8 @@ export async function POST(request: NextRequest, { params }: { params: Promise<{
|
||||||
if (quarantined && needsFixingReason && session.user?.id?.toString() !== process.env.NEXT_PUBLIC_ADMIN_USER_ID)
|
if (quarantined && needsFixingReason && session.user?.id?.toString() !== process.env.NEXT_PUBLIC_ADMIN_USER_ID)
|
||||||
return rateLimit.sendResponse({ error: `You're not an admin!` }, 401);
|
return rateLimit.sendResponse({ error: `You're not an admin!` }, 401);
|
||||||
|
|
||||||
|
const clearImages = formData.get("clearImages") === "true";
|
||||||
|
|
||||||
// Edit Mii in database
|
// Edit Mii in database
|
||||||
const updateData: Prisma.MiiUpdateInput = {};
|
const updateData: Prisma.MiiUpdateInput = {};
|
||||||
if (name !== undefined) updateData.name = profanity.censor(name); // Censor potentially inappropriate words
|
if (name !== undefined) updateData.name = profanity.censor(name); // Censor potentially inappropriate words
|
||||||
|
|
@ -168,8 +170,9 @@ export async function POST(request: NextRequest, { params }: { params: Promise<{
|
||||||
if (youtubeId !== undefined) updateData.youtubeId = youtubeId;
|
if (youtubeId !== undefined) updateData.youtubeId = youtubeId;
|
||||||
if (instructions !== undefined) updateData.instructions = instructions;
|
if (instructions !== undefined) updateData.instructions = instructions;
|
||||||
if (customImages.length > 0) updateData.imageCount = customImages.length;
|
if (customImages.length > 0) updateData.imageCount = customImages.length;
|
||||||
|
else if (clearImages) updateData.imageCount = 0;
|
||||||
|
|
||||||
const imagesChanged = customImages.length > 0 || miiPortraitImage || miiFeaturesImage;
|
const imagesChanged = customImages.length > 0 || clearImages || miiPortraitImage || miiFeaturesImage;
|
||||||
if (settings.queueEnabled && imagesChanged) updateData.in_queue = true;
|
if (settings.queueEnabled && imagesChanged) updateData.in_queue = true;
|
||||||
|
|
||||||
if (Object.keys(updateData).length === 0) return rateLimit.sendResponse({ error: "Nothing was changed" }, 400);
|
if (Object.keys(updateData).length === 0) return rateLimit.sendResponse({ error: "Nothing was changed" }, 400);
|
||||||
|
|
@ -192,7 +195,7 @@ export async function POST(request: NextRequest, { params }: { params: Promise<{
|
||||||
await fs.mkdir(miiUploadsDirectory, { recursive: true });
|
await fs.mkdir(miiUploadsDirectory, { recursive: true });
|
||||||
|
|
||||||
// Only touch files if new images were uploaded
|
// Only touch files if new images were uploaded
|
||||||
if (customImages.length > 0) {
|
if (customImages.length > 0 || clearImages) {
|
||||||
// Delete all custom images
|
// Delete all custom images
|
||||||
const files = await fs.readdir(miiUploadsDirectory);
|
const files = await fs.readdir(miiUploadsDirectory);
|
||||||
await Promise.all(files.filter((file) => file.startsWith("image")).map((file) => fs.unlink(path.join(miiUploadsDirectory, file))));
|
await Promise.all(files.filter((file) => file.startsWith("image")).map((file) => fs.unlink(path.join(miiUploadsDirectory, file))));
|
||||||
|
|
@ -266,9 +269,12 @@ export async function POST(request: NextRequest, { params }: { params: Promise<{
|
||||||
headers: { Authorization: `Bearer ${process.env.CLOUDFLARE_API_TOKEN}`, "Content-Type": "application/json" },
|
headers: { Authorization: `Bearer ${process.env.CLOUDFLARE_API_TOKEN}`, "Content-Type": "application/json" },
|
||||||
body: JSON.stringify({
|
body: JSON.stringify({
|
||||||
files: [
|
files: [
|
||||||
`${process.env.NEXT_PUBLIC_BASE_URL}/mii/${miiId}`,
|
`${process.env.NEXT_PUBLIC_BASE_URL}/api/mii/${miiId}/info`,
|
||||||
`${process.env.NEXT_PUBLIC_BASE_URL}/mii/${miiId}/image?type=mii`,
|
`${process.env.NEXT_PUBLIC_BASE_URL}/mii/${miiId}/image?type=mii`,
|
||||||
`${process.env.NEXT_PUBLIC_BASE_URL}/mii/${miiId}/image?type=features`,
|
`${process.env.NEXT_PUBLIC_BASE_URL}/mii/${miiId}/image?type=features`,
|
||||||
|
`${process.env.NEXT_PUBLIC_BASE_URL}/mii/${miiId}/image?type=image0`,
|
||||||
|
`${process.env.NEXT_PUBLIC_BASE_URL}/mii/${miiId}/image?type=image1`,
|
||||||
|
`${process.env.NEXT_PUBLIC_BASE_URL}/mii/${miiId}/image?type=image2`,
|
||||||
],
|
],
|
||||||
}),
|
}),
|
||||||
}).catch((err) => {
|
}).catch((err) => {
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,7 @@ export default async function RandomPage() {
|
||||||
|
|
||||||
const randomIndex = Math.floor(Math.random() * count);
|
const randomIndex = Math.floor(Math.random() * count);
|
||||||
const randomMii = await prisma.mii.findFirst({
|
const randomMii = await prisma.mii.findFirst({
|
||||||
where: { in_queue: false, quarantined: false, needsFixing: { not: null } },
|
where: { in_queue: false, quarantined: false, needsFixing: null },
|
||||||
skip: randomIndex,
|
skip: randomIndex,
|
||||||
take: 1,
|
take: 1,
|
||||||
select: { id: true },
|
select: { id: true },
|
||||||
|
|
|
||||||
|
|
@ -69,7 +69,13 @@ export default function Header() {
|
||||||
data-tooltip="Your Profile"
|
data-tooltip="Your Profile"
|
||||||
>
|
>
|
||||||
<img
|
<img
|
||||||
src={$session.user.image.startsWith("/profile") ? `${import.meta.env.VITE_API_URL}${$session.user.image}` : $session.user.image}
|
src={
|
||||||
|
$session?.user?.image
|
||||||
|
? $session.user.image.startsWith("/profile")
|
||||||
|
? `${import.meta.env.VITE_API_URL}${$session.user.image}`
|
||||||
|
: $session.user.image
|
||||||
|
: "/guest.png"
|
||||||
|
}
|
||||||
onError={(e) => {
|
onError={(e) => {
|
||||||
e.currentTarget.onerror = null; // Prevent infinite loops
|
e.currentTarget.onerror = null; // Prevent infinite loops
|
||||||
e.currentTarget.src = "/guest.png";
|
e.currentTarget.src = "/guest.png";
|
||||||
|
|
|
||||||
|
|
@ -87,10 +87,9 @@ export default function EditMiiPage() {
|
||||||
formData.append("instructions", JSON.stringify(instructions.current));
|
formData.append("instructions", JSON.stringify(instructions.current));
|
||||||
|
|
||||||
if (hasCustomImagesChanged.current) {
|
if (hasCustomImagesChanged.current) {
|
||||||
files.forEach((file, index) => {
|
// image1, image2, etc.
|
||||||
// image1, image2, etc.
|
files.forEach((file, index) => formData.append(`image${index + 1}`, file));
|
||||||
formData.append(`image${index + 1}`, file);
|
if (files.length === 0) formData.append("clearImages", "true");
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Switch pictures
|
// Switch pictures
|
||||||
|
|
|
||||||
|
|
@ -51,9 +51,7 @@ export default function ProfileLayout() {
|
||||||
const joinDate = new Date(user.createdAt).toLocaleDateString("en-US", { month: "long", year: "numeric" });
|
const joinDate = new Date(user.createdAt).toLocaleDateString("en-US", { month: "long", year: "numeric" });
|
||||||
const metaTitle = `${user.name} - TomodachiShare`;
|
const metaTitle = `${user.name} - TomodachiShare`;
|
||||||
const metaDescription = `View ${user.name}'s profile on TomodachiShare. Creator of ${user._count.miis} Miis. Member since ${joinDate}.`;
|
const metaDescription = `View ${user.name}'s profile on TomodachiShare. Creator of ${user._count.miis} Miis. Member since ${joinDate}.`;
|
||||||
const metaImage = user.image.startsWith("/profile")
|
const metaImage = user.image ? (user.image.startsWith("/profile") ? `${import.meta.env.VITE_API_URL}${user.image}` : user.image) : "/guest.png";
|
||||||
? `${import.meta.env.VITE_API_URL}${user.image}`
|
|
||||||
: (user.image ?? `${import.meta.env.VITE_API_URL}/guest.png`);
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
|
|
@ -81,7 +79,7 @@ export default function ProfileLayout() {
|
||||||
{/* Profile picture */}
|
{/* Profile picture */}
|
||||||
<Link to={`/profile/${user.id}`} className="size-28 aspect-square">
|
<Link to={`/profile/${user.id}`} className="size-28 aspect-square">
|
||||||
<img
|
<img
|
||||||
src={user.image.startsWith("/profile") ? `${import.meta.env.VITE_API_URL}${user.image}` : user.image}
|
src={user.image ? (user.image.startsWith("/profile") ? `${import.meta.env.VITE_API_URL}${user.image}` : user.image) : "/guest.png"}
|
||||||
onError={(e) => {
|
onError={(e) => {
|
||||||
e.currentTarget.onerror = null; // Prevent infinite loops
|
e.currentTarget.onerror = null; // Prevent infinite loops
|
||||||
e.currentTarget.src = "/guest.png";
|
e.currentTarget.src = "/guest.png";
|
||||||
|
|
|
||||||
|
|
@ -65,7 +65,7 @@ export default function ReportUserPage() {
|
||||||
|
|
||||||
<div className="bg-orange-100 rounded-xl border-2 border-orange-400 flex p-4 gap-4">
|
<div className="bg-orange-100 rounded-xl border-2 border-orange-400 flex p-4 gap-4">
|
||||||
<img
|
<img
|
||||||
src={user.image.startsWith("/profile") ? `${import.meta.env.VITE_API_URL}${user.image}` : user.image}
|
src={user.image ? (user.image.startsWith("/profile") ? `${import.meta.env.VITE_API_URL}${user.image}` : user.image) : "/guest.png"}
|
||||||
onError={(e) => {
|
onError={(e) => {
|
||||||
e.currentTarget.onerror = null; // Prevent infinite loops
|
e.currentTarget.onerror = null; // Prevent infinite loops
|
||||||
e.currentTarget.src = "/guest.png";
|
e.currentTarget.src = "/guest.png";
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue