Appwrite migration WIP

This commit is contained in:
Spaghet committed 2025-08-16 19:52:14 -04:00
1 parent 89c5e065de
commit 7e3b5b7a55
18 files changed
+990 -134

No files matched your search

+92
View File
@@ -0,0 +1,92 @@
import { type APIRoute } from 'astro';
import { getFileUrl, getFilePreviewUrl, getFileDownloadUrl } from '../../../lib/appwrite-service.ts';
export const GET: APIRoute = async ({ params, request }) => {
const { fileID } = params;
// Validate that we have a file ID
if (!fileID) {
return new Response(
JSON.stringify({ error: 'File ID is required' }),
{ status: 400, headers: { 'Content-Type': 'application/json' } }
);
}
try {
// Get the bucket ID from environment variables
const bucketId = process.env.VITE_APPWRITE_BUCKET_ID;
if (!bucketId) {
return new Response(
JSON.stringify({ error: 'Bucket ID is not configured' }),
{ status: 500, headers: { 'Content-Type': 'application/json' } }
);
}
// Parse query parameters for preview type
const url = new URL(request.url);
const type = url.searchParams.get('type') as "thumb" | "preview" | null;
let fileUrl: string;
// Determine the appropriate URL based on query parameter or default to view
if (type === 'thumb' || type === 'preview') {
fileUrl = getFilePreviewUrl(bucketId, fileID, type);
} else {
// Default to regular view URL
fileUrl = getFileUrl(bucketId, fileID);
}
// Return a redirect response to the file URL
return new Response(
null,
{
status: 302,
headers: {
'Location': fileUrl
}
}
);
} catch (error) {
console.error('Error fetching file:', error);
return new Response(
JSON.stringify({ error: 'Failed to fetch file' }),
{ status: 500, headers: { 'Content-Type': 'application/json' } }
);
}
};
// Handle HEAD requests for preflight checks
export const HEAD: APIRoute = async ({ params }) => {
const { fileID } = params;
if (!fileID) {
return new Response(
null,
{ status: 400 }
);
}
try {
// Get the bucket ID from environment variables
const bucketId = process.env.VITE_APPWRITE_BUCKET_ID;
if (!bucketId) {
return new Response(
null,
{ status: 500 }
);
}
// For HEAD requests, we just validate that the file URL can be generated
// This is a basic check - in production you might want to actually verify
// that the file exists on Appwrite
const fileUrl = getFileUrl(bucketId, fileID);
// Return a successful response (we don't actually need to return anything specific for HEAD)
return new Response(null, { status: 200 });
} catch (error) {
console.error('Error checking file:', error);
return new Response(null, { status: 500 });
}
};
-60
View File
@@ -1,60 +0,0 @@
import type { APIRoute } from "astro";
export const GET: APIRoute = async ({ params, request }) => {
// Get the bucket ID and file ID from the URL parameters
const { bucketId, fileId } = params;
// Validate that we have required parameters
if (!bucketId || !fileId) {
return new Response(
JSON.stringify({ error: "Missing bucketId or fileId" }),
{ status: 400, headers: { "Content-Type": "application/json" } }
);
}
try {
// Get the Appwrite endpoint and project ID from environment variables
const endpoint = process.env.APPWRITE_ENDPOINT;
const projectId = process.env.APPWRITE_PROJECT_ID;
if (!endpoint || !projectId) {
return new Response(
JSON.stringify({ error: "Appwrite configuration missing" }),
{ status: 500, headers: { "Content-Type": "application/json" } }
);
}
// Construct the Appwrite storage URL
const appwriteUrl = `${endpoint}/v1/storage/buckets/${bucketId}/files/${fileId}/view?project=${projectId}`;
// Fetch the image from Appwrite storage
const response = await fetch(appwriteUrl, {
method: "GET",
headers: {
"Accept": "image/*"
}
});
if (!response.ok) {
throw new Error(`Failed to fetch image: ${response.status} ${response.statusText}`);
}
// Get the image content type
const contentType = response.headers.get("content-type") || "image/jpeg";
// Return the image with proper headers
return new Response(response.body, {
status: 200,
headers: {
"Content-Type": contentType,
"Cache-Control": "public, max-age=3600", // Cache for 1 hour
}
});
} catch (error) {
console.error("Error proxying image from Appwrite:", error);
return new Response(
JSON.stringify({ error: "Failed to fetch image" }),
{ status: 500, headers: { "Content-Type": "application/json" } }
);
}
};
+45 -10
View File
@@ -1,24 +1,59 @@
---
import { type CollectionEntry, getCollection } from "astro:content"
import PageLayout from "@layouts/PageLayout.astro"
import TopLayout from "@layouts/TopLayout.astro"
import BottomLayout from "@layouts/BottomLayout.astro"
import ArticleTopLayout from "@layouts/ArticleTopLayout.astro"
import ArticleBottomLayout from "@layouts/ArticleBottomLayout.astro"
import { getBlogPostById } from "@lib/appwrite-service"
import type { BlogCollectionEntry } from "@types/appwrite"
// Create the static blog pages
export async function getStaticPaths() {
const posts = await getCollection("blog")
return posts.map((post) => ({
params: { slug: post.slug },
props: post,
}))
// This will be replaced with Appwrite data in the future
return []
}
// Helper function to map Appwrite document to CollectionEntry format
function mapAppwriteBlogToCollectionEntry(post: any): BlogCollectionEntry {
return {
id: post.$id,
slug: post.$id, // Using ID as slug since we don't have a proper slug field
body: post.content,
collection: "blog",
data: {
title: post.title,
summary: post.summary,
date: new Date(post.date),
tags: JSON.parse(post.tags),
draft: post.draft,
content: post.content
},
render: async () => {
// This is a minimal implementation for the render function that matches the expected structure
return {
Content: () => {},
headings: [],
remarkPluginFrontmatter: {}
};
}
};
}
// Get the requested post
type Props = CollectionEntry<"blog">
const post = Astro.props
const { title, summary } = post.data
const slug = Astro.params.slug
const post = await getBlogPostById(slug)
.then(blogPost => {
if (blogPost) {
return mapAppwriteBlogToCollectionEntry(blogPost);
}
return null;
})
.catch(error => {
console.error("Error fetching blog post:", error);
return null;
})
const { title, summary } = post?.data || { title: "Post not found", summary: "" }
---
<PageLayout title={title} description={summary}>
@@ -32,4 +67,4 @@ const { title, summary } = post.data
<ArticleBottomLayout entry={post} />
</div>
</BottomLayout>
</PageLayout>
</PageLayout>
+11 -7
View File
@@ -1,16 +1,22 @@
---
import { getCollection } from "astro:content"
import PageLayout from "@layouts/PageLayout.astro"
import TopLayout from "@layouts/TopLayout.astro"
import BottomLayout from "@layouts/BottomLayout.astro"
import Blog from "@components/Blog"
import { BLOG } from "@consts"
import { getBlogPosts } from "@lib/appwrite-service"
import type { BlogPost } from "@types/appwrite"
const posts = (await getCollection("blog"))
.filter(post => !post.data.draft)
.sort((a, b) => b.data.date.getTime() - a.data.date.getTime())
const posts = await getBlogPosts()
.then(blogPosts => {
return blogPosts;
})
.catch(error => {
console.error("Error fetching blog posts:", error);
return [];
})
const tags = [...new Set(posts.flatMap(post => post.data.tags))]
const tags = [...new Set(posts.flatMap(post => post.tags))]
.sort((a, b) => a.localeCompare(b))
---
@@ -26,5 +32,3 @@ const tags = [...new Set(posts.flatMap(post => post.data.tags))]
</div>
</BottomLayout>
</PageLayout>
+14 -12
View File
@@ -1,5 +1,5 @@
---
import { getCollection } from "astro:content"
import { getBlogPosts, getProjects } from "@lib/appwrite-service";
import PageLayout from "@layouts/PageLayout.astro"
import ArrowCard from "@components/ArrowCard"
import StackCard from "@components/StackCard.astro"
@@ -7,14 +7,15 @@ import { SITE, SOCIALS } from "@consts"
import TwinklingStars from "@components/TwinklingStars.astro"
import MeteorShower from "@components/MeteorShower.astro"
const posts = (await getCollection("blog"))
.filter(post => !post.data.draft)
.sort((a, b) => b.data.date.getTime() - a.data.date.getTime())
// Fetch blog posts and projects from Appwrite
const posts = (await getBlogPosts())
.filter(post => !post.draft)
.sort((a, b) => new Date(b.date).getTime() - new Date(a.date).getTime())
.slice(0,3)
const projects = (await getCollection("projects"))
.filter(project => !project.data.draft)
.sort((a, b) => b.data.date.getTime() - a.data.date.getTime())
const projects = (await getProjects())
.filter(project => !project.draft)
.sort((a, b) => new Date(b.date).getTime() - new Date(a.date).getTime())
.slice(0,3)
const stack = [
@@ -57,7 +58,7 @@ const stack = [
<div id='stars3' class='fixed inset-0'></div>
</div>
<!-- Dark Theme: Twinkling Stars / Metors -->
<!-- Dark Theme: Twinkling Stars / Meteor Shower -->
<div id="galaxy" class="fixed inset-0">
<div class="hidden dark:block">
<TwinklingStars/>
@@ -79,7 +80,7 @@ const stack = [
<div class="animate absolute h-full w-full flex items-center justify-center">
<div class='relative w-full h-full flex items-center justify-center'>
<div class='p-5 text-center'>
<img src="/api/image-proxy/689cda7900102e12abf2/689d27a400194d326f69" alt="Quinn Marvin" class="rounded-full w-32 h-32 mx-auto mb-4 border-4 border-spaghetti-red" />
<img src='/api/assets/689d27a400194d326f69' alt="Quinn Marvin" class="rounded-full w-32 h-32 mx-auto mb-4 border-4 border-spaghetti-red" />
<p class='animated text-lg md:text-xl lg:text-2xl font-semibold opacity-75 text-spaghetti-brown'>
Hello, I am Quinn Marvin
</p>
@@ -96,7 +97,7 @@ const stack = [
Supporting PostgreSQL, MariaDB, MySQL, MongoDB, Redis, and Minio
</p>
<div id="ctaButtons" class='animated flex flex-wrap gap-4 justify-center mt-5'>
<a href='/blog' class='py-2 px-4 rounded truncate text-xs md:text-sm lg:text-base bg-spaghetti-red dark:bg-spaghetti-red text-white dark:text-white hover:opacity-75 blend'>
<a href='/blog' class='py-2 px-4 rounded truncate text-xs md:text-sm lg:text-base bg-spaghetti-red dark:bg-spaghetti-red text-spaghetti-brown dark:text-spaghetti-brown hover:opacity-75 blend'>
Read my blog
</a>
<a href='/work' class='py-2 px-4 truncate rounded text-xs md:text-sm lg:text-base border border-spaghetti-yellow/50 dark:border-spaghetti-yellow/50 hover:bg-spaghetti-yellow/20 hover:dark:bg-spaghetti-yellow/20 blend text-spaghetti-brown dark:text-spaghetti-brown'>
@@ -153,7 +154,7 @@ const stack = [
Website build with
</p>
<div class="flex flex-wrap items-center gap-2 mt-5">
{stack.map(item => (
{stack.map((item) => (
<StackCard
text={item.text}
icon={item.icon}
@@ -205,7 +206,7 @@ const stack = [
Reach out to me via email or on social media.
</p>
<div class="grid grid-cols-4 gap-y-2 mt-4 auto-cols-min">
{SOCIALS.map(social => (
{SOCIALS.map((social) => (
<div class="col-span-1 flex items-center gap-1">
<span class="whitespace-nowrap truncate">
{social.NAME}
@@ -219,6 +220,7 @@ const stack = [
</a>
</div>
))}
</div>
</div>
</section>
</div>
+48 -11
View File
@@ -1,30 +1,67 @@
---
import { type CollectionEntry, getCollection } from "astro:content"
import PageLayout from "@layouts/PageLayout.astro"
import TopLayout from "@layouts/TopLayout.astro"
import BottomLayout from "@layouts/BottomLayout.astro"
import ArticleTopLayout from "@layouts/ArticleTopLayout.astro"
import ArticleBottomLayout from "@layouts/ArticleBottomLayout.astro"
import { getProjectById } from "@lib/appwrite-service"
import type { ProjectCollectionEntry } from "@types/appwrite"
// Create the static projects pages
export async function getStaticPaths() {
const projects = await getCollection("projects")
return projects.map((project) => ({
params: { slug: project.slug },
props: project,
}))
// This will be replaced with Appwrite data in the future
return []
}
// Helper function to map Appwrite document to CollectionEntry format
function mapAppwriteProjectToCollectionEntry(project: any): ProjectCollectionEntry {
return {
id: project.$id,
slug: project.$id, // Using ID as slug since we don't have a proper slug field
body: project.content,
collection: "projects",
data: {
title: project.title,
summary: project.summary,
date: new Date(project.date),
tags: project.tags,
draft: project.draft,
demoUrl: project.demoUrl,
repoUrl: project.repoUrl,
content: project.content
},
render: async () => {
// This is a minimal implementation for the render function that matches the expected structure
return {
Content: () => {},
headings: [],
remarkPluginFrontmatter: {}
};
}
};
}
// Get the requested project
type Props = CollectionEntry<"projects">
const project = Astro.props
const { title, summary } = project.data
const slug = Astro.params.slug
const project = await getProjectById(slug)
.then(projectData => {
if (projectData) {
return mapAppwriteProjectToCollectionEntry(projectData);
}
return null;
})
.catch(error => {
console.error("Error fetching project:", error);
return null;
})
const { title, summary } = project?.data || { title: "Project not found", summary: "" }
---
<PageLayout title={title} description={summary}>
<TopLayout>
<div class="animate">
<ArticleTopLayout entry={project} />
<ArticleTopLayout entry={project}/>
</div>
</TopLayout>
<BottomLayout>
@@ -32,4 +69,4 @@ const { title, summary } = project.data
<ArticleBottomLayout entry={project} />
</div>
</BottomLayout>
</PageLayout>
</PageLayout>
+29 -4
View File
@@ -1,14 +1,39 @@
---
import { getCollection } from "astro:content"
import PageLayout from "@layouts/PageLayout.astro"
import TopLayout from "@layouts/TopLayout.astro"
import BottomLayout from "@layouts/BottomLayout.astro"
import Projects from "@components/Projects"
import { PROJECTS } from "@consts"
import { getProjects } from "@lib/appwrite-service"
import type { Project } from "@types/appwrite"
const projects = (await getCollection("projects"))
.filter(project => !project.data.draft)
.sort((a, b) => b.data.date.getTime() - a.data.date.getTime())
// Helper function to map Appwrite project document to CollectionEntry format
function mapAppwriteProjectToCollectionEntry(project: Project) {
return {
$id: project.$id,
$collectionId: "projects",
data: {
title: project.title,
summary: project.summary,
date: new Date(project.date),
tags: project.tags,
draft: project.draft,
demoUrl: project.demoUrl,
repoUrl: project.repoUrl,
content: project.content,
image: project.image
}
};
}
const projects = await getProjects()
.then(projectList => {
return projectList.map(project => mapAppwriteProjectToCollectionEntry(project));
})
.catch(error => {
console.error("Error fetching projects:", error);
return [];
})
const tags = [...new Set(projects.flatMap(project => project.data.tags))]
.sort((a, b) => a.localeCompare(b))
+25 -10
View File
@@ -1,20 +1,34 @@
---
import { getCollection } from "astro:content"
import PageLayout from "@layouts/PageLayout.astro"
import TopLayout from "@layouts/TopLayout.astro"
import BottomLayout from "@layouts/BottomLayout.astro"
import { WORK } from "@consts"
import { getWorkExperiences } from "@lib/appwrite-service"
const collection = await getCollection("work")
// Helper function to map Appwrite document to compatible format for work page
function mapAppwriteWorkToEntry(work: any) {
return {
id: work.$id,
slug: work.$id, // Using ID as slug since we don't have a proper slug field
data: {
company: work.company,
role: work.role,
dateStart: new Date(work.dateStart),
dateEnd: work.dateEnd,
content: work.content // This will be rendered in the component
},
body: work.content
};
}
collection.sort((a, b) => new Date(b.data.dateStart).getTime() - new Date(a.data.dateStart).getTime())
const work = await Promise.all(
collection.map(async (item) => {
const { Content } = await item.render()
return { ...item, Content }
const work = await getWorkExperiences()
.then(workList => {
return workList.map(mapAppwriteWorkToEntry);
})
.catch(error => {
console.error("Error fetching work experiences:", error);
return [];
})
)
function formatWorkDate(input: Date | string) {
if (typeof input === "string") return input
@@ -49,11 +63,12 @@ function formatWorkDate(input: Date | string) {
{entry.data.role}
</div>
<article class="prose dark:prose-invert">
<entry.Content />
{entry.body}
</article>
</li>
))
}
</ul>
</BottomLayout>
</PageLayout>