mirror of
https://github.com/D4M13N-D3V/neroshitron.git
synced 2025-03-14 10:05:04 +00:00
fix
This commit is contained in:
parent
e7d5e54139
commit
75dad17afe
@ -17,7 +17,6 @@ export async function GET(
|
|||||||
request: Request,
|
request: Request,
|
||||||
{ params }: { params: { id: string } }
|
{ params }: { params: { id: string } }
|
||||||
) {
|
) {
|
||||||
const galleryId = params.id.toLowerCase().replace(/\s+/g, '_');
|
|
||||||
const supabase = createClient();
|
const supabase = createClient();
|
||||||
const user = await supabase.auth.getUser();
|
const user = await supabase.auth.getUser();
|
||||||
const url = new URL(request.url);
|
const url = new URL(request.url);
|
||||||
@ -29,16 +28,13 @@ export async function GET(
|
|||||||
.select('*')
|
.select('*')
|
||||||
.eq('name', params.id)
|
.eq('name', params.id)
|
||||||
.single();
|
.single();
|
||||||
|
let { data: files, error } = await supabase.storage.from('galleries').list(params.id);
|
||||||
let { data: files, error } = await supabase.storage.from('galleries').list(galleryId);
|
|
||||||
if (files == null || files?.length == 0) {
|
if (files == null || files?.length == 0) {
|
||||||
|
|
||||||
return NextResponse.error();
|
return NextResponse.error();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Loop through each file, download it, convert it to base64, and add the data URL to the array
|
// Loop through each file, download it, convert it to base64, and add the data URL to the array
|
||||||
let { data: blobdata, error: fileError } = await supabase.storage.from('galleries').download(galleryId + "/" + files[0].name);
|
let { data: blobdata, error: fileError } = await supabase.storage.from('galleries').download(params.id + "/" + files[0].name);
|
||||||
|
|
||||||
if (fileError || blobdata == null) {
|
if (fileError || blobdata == null) {
|
||||||
//console.error('Error downloading file:', error);
|
//console.error('Error downloading file:', error);
|
||||||
return NextResponse.error();
|
return NextResponse.error();
|
||||||
|
68
app/api/galleries/admin/[id]/route.ts
Normal file
68
app/api/galleries/admin/[id]/route.ts
Normal file
@ -0,0 +1,68 @@
|
|||||||
|
import { NextResponse } from "next/server";
|
||||||
|
import { createClient } from "@/utils/supabase/server";
|
||||||
|
import path from 'path';
|
||||||
|
|
||||||
|
export async function GET(
|
||||||
|
request: Request,
|
||||||
|
{ params }: { params: { id: string } }
|
||||||
|
) {
|
||||||
|
const id = params.id;
|
||||||
|
const supabase = createClient();
|
||||||
|
const { data: gallery, error } = await supabase.from('galleries').select("*").eq('name', id).single();
|
||||||
|
return NextResponse.json({ gallery });
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
export async function PUT(
|
||||||
|
request: Request,
|
||||||
|
{ params }: { params: { id: string } }
|
||||||
|
) {
|
||||||
|
const id = params.id;
|
||||||
|
const supabase = createClient();
|
||||||
|
const { files, tags, name, nsfw, tier}: { files: File[], tags: string[], name: string, nsfw:boolean, tier:string } = await request.json();
|
||||||
|
const { data: gallery, error } = await supabase.from('galleries').update({ name, tags, nsfw, tier }).eq('name', id).single();
|
||||||
|
let { data: galleries, error:galleriesError } = await supabase
|
||||||
|
.from('galleries')
|
||||||
|
.select('*');
|
||||||
|
return NextResponse.json({ success: true, galleries });
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function DELETE(
|
||||||
|
request: Request,
|
||||||
|
{ params }: { params: { id: string } }
|
||||||
|
) {
|
||||||
|
const id =params.id;
|
||||||
|
const supabase = createClient();
|
||||||
|
const { data: gallery, error } = await supabase.from('galleries').delete().eq('name', id).single();
|
||||||
|
let { data: galleries, error:galleriesError } = await supabase
|
||||||
|
.from('galleries')
|
||||||
|
.select('*');
|
||||||
|
return NextResponse.json({ success: true, galleries });
|
||||||
|
}
|
||||||
|
|
||||||
|
// const tagsResponse = await fetch(`/api/galleries/tags?search=${search}`);
|
||||||
|
// const tagsData = await tagsResponse.json();
|
||||||
|
// const galleriesWithTagData = galleriesData.map((gallery: any) => {
|
||||||
|
// const tags = tagsData.filter((tag: any) => gallery.tags.includes(tag.name));
|
||||||
|
// return { ...gallery, tags };
|
||||||
|
// });
|
||||||
|
|
||||||
|
|
||||||
|
// const formData = new FormData();
|
||||||
|
// formData.append('name', name);
|
||||||
|
// formData.append('tags', JSON.stringify(tags));
|
||||||
|
// files.forEach((file: File) => {
|
||||||
|
// formData.append('files', file);
|
||||||
|
// });
|
||||||
|
|
||||||
|
// const response = await fetch('/api/galleries', {
|
||||||
|
// method: 'POST',
|
||||||
|
// body: formData,
|
||||||
|
// });
|
||||||
|
|
||||||
|
// if (response.ok) {
|
||||||
|
// const data = await response.json();
|
||||||
|
// // Handle success
|
||||||
|
// } else {
|
||||||
|
// // Handle error
|
||||||
|
// }
|
26
app/api/galleries/admin/route.ts
Normal file
26
app/api/galleries/admin/route.ts
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
import { NextResponse } from "next/server";
|
||||||
|
import { createClient } from "@/utils/supabase/server";
|
||||||
|
import path from 'path';
|
||||||
|
|
||||||
|
|
||||||
|
export async function GET(request: Request) {
|
||||||
|
const supabase = createClient();
|
||||||
|
let { data: galleries, error } = await supabase
|
||||||
|
.from('galleries')
|
||||||
|
.select('*');
|
||||||
|
return NextResponse.json(galleries);
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function POST(request: Request) {
|
||||||
|
const supabase = createClient();
|
||||||
|
const { files, tags, name, nsfw, tier }: { files: File[], tags: string[], name: string, nsfw:boolean, tier:string } = await request.json();
|
||||||
|
for (let i = 0; i < files.length; i++) {
|
||||||
|
const file = files[i];
|
||||||
|
supabase.storage.from('galleries').upload(`${name}/${file.name}`, file);
|
||||||
|
}
|
||||||
|
const { data: gallery, error } = await supabase.from('galleries').insert({ name, tags, nsfw, tier, column_number:3 }).single();
|
||||||
|
let { data: galleries, error:galleriesError } = await supabase
|
||||||
|
.from('galleries')
|
||||||
|
.select('*');
|
||||||
|
return NextResponse.json({ success: true, galleries });
|
||||||
|
}
|
@ -15,7 +15,6 @@ export async function POST(request: Request) {
|
|||||||
const supabase = createClient();
|
const supabase = createClient();
|
||||||
const data = await request.json();
|
const data = await request.json();
|
||||||
const { data: tag, error } = await supabase.from('tags').insert({ name: data.tag }).single();
|
const { data: tag, error } = await supabase.from('tags').insert({ name: data.tag }).single();
|
||||||
console.log(error)
|
|
||||||
if (error) {
|
if (error) {
|
||||||
return NextResponse.error();
|
return NextResponse.error();
|
||||||
}
|
}
|
||||||
|
@ -68,7 +68,7 @@ function PageComponent() {
|
|||||||
placeholderTags={[
|
placeholderTags={[
|
||||||
{ value: "tags", label: "❗️ click here to add tags" },
|
{ value: "tags", label: "❗️ click here to add tags" },
|
||||||
]}
|
]}
|
||||||
nsfwButtonEnabled={false}
|
nsfwButtonEnabled={true}
|
||||||
searchChanged={(search) => {}}
|
searchChanged={(search) => {}}
|
||||||
nsfwChanged={(nsfw) => {}}
|
nsfwChanged={(nsfw) => {}}
|
||||||
tagsChanged={(tags) => {}}
|
tagsChanged={(tags) => {}}
|
||||||
|
@ -68,7 +68,7 @@ function PageComponent() {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="w-full h-1/2 text-white lg:flex justify-center items-center animate-in">
|
<div className="w-full h-1/2 text-white lg:flex justify-center items-center animate-in">
|
||||||
<div className="w-full lg:w-1/3 rounded-md bg-primary opacity-90 p-12 m-1 mt-32 shadow-lg backdrop-blur">
|
<div className="w-full lg:w-1/3 rounded-md bg-primary opacity-90 g- p-12 m-1 mt-32 shadow-lg backdrop-blur">
|
||||||
<div className="w-full flex">
|
<div className="w-full flex">
|
||||||
<input type="text" onChange={(e)=>{setNewTagName(e.target.value)}} className="hover:scale-105 focus:scale-95 mb-8 mr-2 rounded-md bg-info-bright p-2 w-1/2 text-white shadow-lg" placeholder="Tag Name" />
|
<input type="text" onChange={(e)=>{setNewTagName(e.target.value)}} className="hover:scale-105 focus:scale-95 mb-8 mr-2 rounded-md bg-info-bright p-2 w-1/2 text-white shadow-lg" placeholder="Tag Name" />
|
||||||
<button onClick={createTag} className="hover:scale-95 ml-2 shadow-lg w-1/2 h-10 text-center bg-success hover:bg-success-light text-white font-bold rounded flex items-center justify-center">
|
<button onClick={createTag} className="hover:scale-95 ml-2 shadow-lg w-1/2 h-10 text-center bg-success hover:bg-success-light text-white font-bold rounded flex items-center justify-center">
|
||||||
@ -100,7 +100,7 @@ function PageComponent() {
|
|||||||
</table>
|
</table>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div className="w-full lg:w-1/2 h-96 rounded-md bg-primary opacity-90 backdrop-blur-lg p-12 m-1 mt-32 shadow-lg">
|
<div className="w-full lg:w-1/2 h-max rounded-md bg-primary opacity-90 backdrop-blur-lg p-12 m-1 mt-32 shadow-lg">
|
||||||
<div className="w-full flex pb-2">
|
<div className="w-full flex pb-2">
|
||||||
<SearchInput placeholderTags={[
|
<SearchInput placeholderTags={[
|
||||||
{ value: "tags", label: "❗️ click here to add tags to search" }
|
{ value: "tags", label: "❗️ click here to add tags to search" }
|
||||||
@ -110,7 +110,7 @@ function PageComponent() {
|
|||||||
+ Gallery
|
+ Gallery
|
||||||
</a>
|
</a>
|
||||||
</div>
|
</div>
|
||||||
<div className="w-full h-64 overflow-y-scroll no-scrollbar">
|
<div className="w-full h-96 overflow-y-scroll no-scrollbar">
|
||||||
<table className="w-full mt-8 bg-primary-light rounded">
|
<table className="w-full mt-8 bg-primary-light rounded">
|
||||||
<tbody>
|
<tbody>
|
||||||
{/* Replace this with your data mapping logic */}
|
{/* Replace this with your data mapping logic */}
|
||||||
@ -120,7 +120,7 @@ function PageComponent() {
|
|||||||
<td className="px-4 py-2">{item.imageCount}</td>
|
<td className="px-4 py-2">{item.imageCount}</td>
|
||||||
<td className="px-4 py-2">{item.tier}</td>
|
<td className="px-4 py-2">{item.tier}</td>
|
||||||
<td className="px-4 py-2">
|
<td className="px-4 py-2">
|
||||||
<button className="bg-secondary hover:scale-95 shadow-lg hover:bg-secondary-light text-white font-bold py-2 px-4 rounded float-right">
|
<button onClick={()=>{ window.location.href=`/gallery/admin/view?id=${encodeURIComponent(item.name)}`}} className="bg-secondary hover:scale-95 shadow-lg hover:bg-secondary-light text-white font-bold py-2 px-4 rounded float-right">
|
||||||
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" strokeWidth={1.5} stroke="currentColor" className="size-6">
|
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" strokeWidth={1.5} stroke="currentColor" className="size-6">
|
||||||
<path strokeLinecap="round" strokeLinejoin="round" d="M19.5 14.25v-2.625a3.375 3.375 0 0 0-3.375-3.375h-1.5A1.125 1.125 0 0 1 13.5 7.125v-1.5a3.375 3.375 0 0 0-3.375-3.375H8.25m5.231 13.481L15 17.25m-4.5-15H5.625c-.621 0-1.125.504-1.125 1.125v16.5c0 .621.504 1.125 1.125 1.125h12.75c.621 0 1.125-.504 1.125-1.125V11.25a9 9 0 0 0-9-9Zm3.75 11.625a2.625 2.625 0 1 1-5.25 0 2.625 2.625 0 0 1 5.25 0Z" />
|
<path strokeLinecap="round" strokeLinejoin="round" d="M19.5 14.25v-2.625a3.375 3.375 0 0 0-3.375-3.375h-1.5A1.125 1.125 0 0 1 13.5 7.125v-1.5a3.375 3.375 0 0 0-3.375-3.375H8.25m5.231 13.481L15 17.25m-4.5-15H5.625c-.621 0-1.125.504-1.125 1.125v16.5c0 .621.504 1.125 1.125 1.125h12.75c.621 0 1.125-.504 1.125-1.125V11.25a9 9 0 0 0-9-9Zm3.75 11.625a2.625 2.625 0 1 1-5.25 0 2.625 2.625 0 0 1 5.25 0Z" />
|
||||||
</svg>
|
</svg>
|
||||||
|
@ -11,27 +11,68 @@ function PageComponent() {
|
|||||||
const [filePreviews, setFilePreviews] = useState<string[]>([]);
|
const [filePreviews, setFilePreviews] = useState<string[]>([]);
|
||||||
const supabase = createClient();
|
const supabase = createClient();
|
||||||
const user = supabase.auth.getUser();
|
const user = supabase.auth.getUser();
|
||||||
|
const [gallery , setGallery] = useState<any>(null);
|
||||||
|
const [galleryName, setGalleryName] = useState<string>('');
|
||||||
|
|
||||||
|
const getData = async () => {
|
||||||
|
const urlParams = new URLSearchParams(window.location.search);
|
||||||
|
const id = urlParams.get('id');
|
||||||
|
const galleryResponse = await fetch(`/api/galleries/admin/${id}`, {
|
||||||
|
method: 'GET',
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json'
|
||||||
|
}
|
||||||
|
});
|
||||||
|
const galleryData = await galleryResponse.json();
|
||||||
|
setGallery(galleryData.gallery);
|
||||||
|
setGalleryName(galleryData.gallery.name);
|
||||||
|
}
|
||||||
|
useEffect(() => {
|
||||||
|
getData();
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
}, [gallery]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="w-full text-white flex justify-center items-center animate-in">
|
<div className="w-full text-white flex justify-center items-center animate-in">
|
||||||
<div className="w-full lg:w-1/2 rounded-md opacity-90 backdrop-blur-lg bg-primary p-12 mt-32 shadow-lg">
|
<div className="w-full lg:w-1/2 rounded-md opacity-90 backdrop-blur-lg bg-primary p-12 mt-32 shadow-lg">
|
||||||
<div className="w-full flex pb-48">
|
<div className="w-full flex pb-72">
|
||||||
<GalleryThumbnail id={"Test Gallery"} columns={3} onSelect={function (id: string, columns: number): void {
|
{gallery != null && (
|
||||||
} } title={""} subscription={""} tags={[]} showNsfw={false} nsfw={false} ></GalleryThumbnail>
|
<GalleryThumbnail
|
||||||
|
key={"galleryThumbnail"}
|
||||||
|
id={gallery}
|
||||||
|
columns={3}
|
||||||
|
onSelect={function (id: string, columns: number): void {}}
|
||||||
|
title={gallery.name}
|
||||||
|
subscription={gallery.tier}
|
||||||
|
tags={gallery.tags}
|
||||||
|
showNsfw={true}
|
||||||
|
nsfw={gallery.nsfw}
|
||||||
|
></GalleryThumbnail>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
<div className="w-full flex">
|
<div className="w-full flex">
|
||||||
<input
|
<input
|
||||||
type="text"
|
type="text"
|
||||||
className="mb-8 mr-2 rounded-md bg-secondary p-2 w-1/2 text-white"
|
className="mb-8 mr-2 rounded-md bg-secondary p-2 w-1/2 text-white"
|
||||||
placeholder="Gallery Name"
|
placeholder="Gallery Name"
|
||||||
|
value={galleryName}
|
||||||
|
onChange={(e) => setGalleryName(e.target.value)}
|
||||||
/>
|
/>
|
||||||
<div className="w-1/6">
|
<div className="w-1/6">
|
||||||
<button onClick={() => window.location.href = "/gallery/admin"} className="w-full bg-error hover:bg-error-light text-white rounded-md p-2">
|
<button
|
||||||
|
onClick={() => (window.location.href = "/gallery/admin")}
|
||||||
|
className="w-full bg-error hover:bg-error-light text-white rounded-md p-2"
|
||||||
|
>
|
||||||
Delete
|
Delete
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
<div className="w-1/6">
|
<div className="w-1/6">
|
||||||
<button onClick={() => window.location.href = "/gallery/admin"} className="w-full bg-error-dark hover:bg-error text-white rounded-md p-2 ml-2">
|
<button
|
||||||
|
onClick={() => (window.location.href = "/gallery/admin")}
|
||||||
|
className="w-full bg-error-dark hover:bg-error text-white rounded-md p-2 ml-2"
|
||||||
|
>
|
||||||
Back
|
Back
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
@ -47,7 +88,7 @@ function PageComponent() {
|
|||||||
placeholderTags={[
|
placeholderTags={[
|
||||||
{ value: "tags", label: "❗️ click here to add tags" },
|
{ value: "tags", label: "❗️ click here to add tags" },
|
||||||
]}
|
]}
|
||||||
nsfwButtonEnabled={false}
|
nsfwButtonEnabled={true}
|
||||||
searchChanged={(search) => {}}
|
searchChanged={(search) => {}}
|
||||||
nsfwChanged={(nsfw) => {}}
|
nsfwChanged={(nsfw) => {}}
|
||||||
tagsChanged={(tags) => {}}
|
tagsChanged={(tags) => {}}
|
||||||
|
@ -22,7 +22,6 @@ export default async function AuthButton() {
|
|||||||
|
|
||||||
const heads = headers()
|
const heads = headers()
|
||||||
const currentPage = heads.get('x-path')
|
const currentPage = heads.get('x-path')
|
||||||
console.log(currentPage)
|
|
||||||
const getGravatarUrl = () => {
|
const getGravatarUrl = () => {
|
||||||
if (user == null) {
|
if (user == null) {
|
||||||
return;
|
return;
|
||||||
|
@ -63,7 +63,6 @@ const SearchInput = ({ tagsChanged, searchChanged, nsfwChanged, nsfwButtonEnable
|
|||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const handleKeyDown = (event: KeyboardEvent) => {
|
const handleKeyDown = (event: KeyboardEvent) => {
|
||||||
console.log("TEST")
|
|
||||||
if (event.key === 'ArrowUp') {
|
if (event.key === 'ArrowUp') {
|
||||||
const currentIndex = tags.findIndex(tag => tag.name === currentTag);
|
const currentIndex = tags.findIndex(tag => tag.name === currentTag);
|
||||||
const newIndex = currentIndex === 0 ? tags.length - 1 : currentIndex - 1;
|
const newIndex = currentIndex === 0 ? tags.length - 1 : currentIndex - 1;
|
||||||
@ -82,7 +81,6 @@ const SearchInput = ({ tagsChanged, searchChanged, nsfwChanged, nsfwButtonEnable
|
|||||||
};
|
};
|
||||||
}, [currentTag, tags]);
|
}, [currentTag, tags]);
|
||||||
|
|
||||||
console.log(currentTag)
|
|
||||||
|
|
||||||
const tagOptions = tags.map((tag: { name: string; }) => ({ value: tag.name, label: tag.name }));
|
const tagOptions = tags.map((tag: { name: string; }) => ({ value: tag.name, label: tag.name }));
|
||||||
return (
|
return (
|
||||||
|
Loading…
x
Reference in New Issue
Block a user