Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sqlite and node server #367

Merged
merged 50 commits into from
Dec 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
60ceb1f
add sqlite and run as node server
Bilalm354 Dec 14, 2024
822f715
npm i
Bilalm354 Dec 14, 2024
1e90cac
disable swc minitfy
Bilalm354 Dec 14, 2024
d664179
update drizlekit version
Bilalm354 Dec 14, 2024
1fca2fc
babelrc and ecosystem
Bilalm354 Dec 14, 2024
cff50c8
x
Bilalm354 Dec 14, 2024
5d88ccb
y
Bilalm354 Dec 14, 2024
c1012fb
.
Bilalm354 Dec 14, 2024
d08b73a
nvm 22
Bilalm354 Dec 14, 2024
0f3296f
node v
Bilalm354 Dec 14, 2024
ba9bfd1
remove vercel analytics
Bilalm354 Dec 14, 2024
60f4b19
stuff
Bilalm354 Dec 14, 2024
9f7c9b2
working with new node and next 15
Bilalm354 Dec 14, 2024
61af3e5
pm2 stuff
Bilalm354 Dec 14, 2024
d0f97e5
set up stuff
Bilalm354 Dec 14, 2024
7f1663b
changes
Bilalm354 Dec 14, 2024
2fc0557
changes
Bilalm354 Dec 15, 2024
e14592e
nvm
Bilalm354 Dec 15, 2024
5cbf735
add interpreter
Bilalm354 Dec 15, 2024
0de59a5
add interpreter
Bilalm354 Dec 15, 2024
2a621c2
x
Bilalm354 Dec 15, 2024
11e5a6b
.
Bilalm354 Dec 15, 2024
0221217
remove cluster
Bilalm354 Dec 15, 2024
eb9667b
.
Bilalm354 Dec 15, 2024
d630fca
.
Bilalm354 Dec 15, 2024
b893549
.
Bilalm354 Dec 15, 2024
c8f0821
.
Bilalm354 Dec 15, 2024
89c8d7d
.
Bilalm354 Dec 15, 2024
df9d94e
add deploy script
Bilalm354 Dec 15, 2024
fe0307e
.
Bilalm354 Dec 15, 2024
f0d2abf
update db script
Bilalm354 Dec 15, 2024
3ef3d14
delete nginx conf
Bilalm354 Dec 15, 2024
15cd2e5
Caddyfile\
Bilalm354 Dec 15, 2024
b71d9df
update ecosystem config with script
Bilalm354 Dec 15, 2024
f850ea5
update pm2 command and remove eco system
Bilalm354 Dec 15, 2024
d3d747a
x
Bilalm354 Dec 15, 2024
2922d74
update caddy file
Bilalm354 Dec 15, 2024
09cfe3c
.
Bilalm354 Dec 15, 2024
dd12d05
caddy fmt
Bilalm354 Dec 15, 2024
95e8597
fix prompt bug
Bilalm354 Dec 15, 2024
de7bba9
.
Bilalm354 Dec 15, 2024
2448bf6
.
Bilalm354 Dec 15, 2024
f7bb3a1
.
Bilalm354 Dec 15, 2024
4a8a349
.
Bilalm354 Dec 15, 2024
13bd0fb
fix bug
Bilalm354 Dec 15, 2024
72dea4d
open product in same tab
Bilalm354 Dec 15, 2024
66bbcb0
add other domain
Bilalm354 Dec 16, 2024
5660104
add www
Bilalm354 Dec 16, 2024
94777db
update all node versions in workflows
Bilalm354 Dec 16, 2024
1779293
fmt
Bilalm354 Dec 16, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 3 additions & 5 deletions .github/workflows/on-pull-request-to-main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ env:
CI: true
AI_GIFTS_API_URL: http://localhost:3000
FREE_CURRENCY_API_KEY: ${{ secrets.FREE_CURRENCY_API_KEY }}
DATABASE_URL: postgres://postgres:password@localhost:5432/test
DATABASE_URL_UNPOOLED: postgres://postgres:password@localhost:5432/test
OPENAI_API_KEY: foo
OPENAI_ORG_ID: foo
PRINTIFY_API_TOKEN: ${{secrets.PRINTIFY_API_TOKEN}}
Expand All @@ -26,7 +24,7 @@ jobs:
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: "20.11"
node-version: "22.12.0"
cache: "npm"
- name: Install dependencies
run: npm ci
Expand All @@ -45,9 +43,9 @@ jobs:
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: "20.11"
node-version: "22.12.0"
cache: "npm"
- name: Install dependencies
run: npm ci
- name: Run unit tests
run: npm run test:ci
run: npm run test
2 changes: 1 addition & 1 deletion .github/workflows/on-push-to-main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
- name: Setup Node.js environment
uses: actions/setup-node@v4
with:
node-version: 20.11
node-version: 22.12.0
cache: "npm"
- name: Install dependencies
run: npm install -D
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/playwright-pull-request-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
- name: Setup Node.js environment
uses: actions/setup-node@v4
with:
node-version: 20.11
node-version: 22.12.0
cache: "npm"

- name: Install dependencies
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,4 @@ next-env.d.ts
tests/screenshots

creds.txt
sqlite.db
1 change: 1 addition & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
engine-strict=true
3 changes: 3 additions & 0 deletions Caddyfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
bilal-home-assistant.duckdns.org, ai-print-shop.com, www.ai-print-shop.com {
reverse_proxy localhost:3001
}
30 changes: 20 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,25 @@

## Technologies

- UI - NextJs
- UI - NextJs

## User Story

- I want to enter text about what I want to print on a t shirt, mug or hoodie
- I want the website to multiple options for what I want and to display it on different things
- I want to select which product I want
- I want to pay for this product
- I want emails telling me about my purchase and delivery
- I want to be delivered the product
- I want to enter text about what I want to print on a t shirt, mug or hoodie
- I want the website to multiple options for what I want and to display it on different things
- I want to select which product I want
- I want to pay for this product
- I want emails telling me about my purchase and delivery
- I want to be delivered the product

# Set up

`npm run setup`

# Webhooks

- Install stripe CLI from https://docs.stripe.com/stripe-cli
- Run `stripe login` and login
- Install stripe CLI from https://docs.stripe.com/stripe-cli
- Run `npx stripe login` and login

To listen to payment intent succeeded event:

Expand All @@ -34,9 +38,15 @@ or
npm run stripe:listen
```

# Vercel

To pull production environment variables

`npx vercel pull --environment=production`

# DB

- Need to have .env.development.local with updated pg connection values
- Need to have .env.development.local with updated pg connection values

Update schema:

Expand Down
8 changes: 3 additions & 5 deletions app/create/page.tsx
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
import { SomethingWrongButton } from "@/components/buttons/SomethingWrongButton";
import { ImageGenerationForm } from "@/components/ImageGenerationForm";
import { CountryCode } from "@/lib/stripe/createCheckoutSession";
import { track } from "@vercel/analytics/server";

export default async function CreatePage({
searchParams,
}: {
searchParams: {
searchParams: Promise<{
country: CountryCode;
prompt?: string;
};
}>;
}) {
const { country, prompt } = searchParams;
const { country, prompt } = await searchParams;
console.log({ msg: "Create Page", country, prompt });
track("Landed on create");

return (
<div className="flex w-full flex-col gap-4 md:w-2/3">
Expand Down
2 changes: 0 additions & 2 deletions app/error.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import {
CardFooter,
CardHeader,
} from "@/components/ui/card";
import { track } from "@vercel/analytics";
import Link from "next/link";
import { useRouter } from "next/navigation";

Expand All @@ -19,7 +18,6 @@ export default function ErrorPage({
reset: () => void;
}) {
console.error({ error });
track("Error page");
const router = useRouter();

return (
Expand Down
10 changes: 5 additions & 5 deletions app/image/[prompt]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@ import { ImageWithLoadingAndError } from "@/components/ImageWithLoadingAndError"
export const maxDuration = 300;

export default async function GenerateImagePage(params: {
params: { prompt: string };
searchParams: {
params: Promise<{ prompt: string }>;
searchParams: Promise<{
style: string;
location: string;
country: CountryCode;
};
}>;
}) {
const { prompt: encodedPrompt } = params.params;
const { style, location, country } = params.searchParams;
const { prompt: encodedPrompt } = await params.params;
const { style, location, country } = await params.searchParams;
const decodedPrompt = decodeURIComponent(encodedPrompt);
console.log({ msg: "Image Page", decodedPrompt, style, location, country });

Expand Down
2 changes: 0 additions & 2 deletions app/layout.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import type { Metadata, Viewport } from "next";
import { Analytics } from "@vercel/analytics/react";
import { Inter } from "next/font/google";
import "./globals.css";
import { CardFooter } from "@/components/ui/card";
Expand Down Expand Up @@ -53,7 +52,6 @@ export default function RootLayout({
disableTransitionOnChange
>
{children}
<Analytics />
</ThemeProvider>
</main>
<footer className="mt-auto w-full">
Expand Down
2 changes: 0 additions & 2 deletions app/page.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import { SomethingWrongButton } from "@/components/buttons/SomethingWrongButton";
import { CreateLink } from "@/components/CreateLink";
import { ExamplesSection } from "@/components/sections/ExamplesSection";
import { track } from "@vercel/analytics/server";

export default function Home() {
track("Landed on Home");
return (
<div className="flex w-full flex-col items-center gap-20">
<div className="flex w-4/5 flex-col gap-20 pt-20 md:w-3/5">
Expand Down
7 changes: 3 additions & 4 deletions app/payment/success/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import {
CardHeader,
CardTitle,
} from "@/components/ui/card";
import { track } from "@vercel/analytics/server";
import { sendEmail } from "@/lib/email/sendEmail";

export const dynamic = "force-dynamic";
Expand Down Expand Up @@ -47,16 +46,16 @@ const pollForPrintifyOrder = async (
};

export default async function Page(params: {
searchParams: { orderId: string };
searchParams: Promise<{ orderId: string }>;
}) {
const internalOrderId = Number(params.searchParams.orderId);
const { orderId } = await params.searchParams;
const internalOrderId = Number(orderId);
const { printifyOrderId } = await pollForInternalOrder(internalOrderId);

if (!printifyOrderId) {
console.log("No printify order id for internal order", internalOrderId);
throw new Error("No printify order id");
}
track("Payment Success");

const printifyOrder = await pollForPrintifyOrder(printifyOrderId);

Expand Down
29 changes: 15 additions & 14 deletions app/product/[productType]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,31 +10,30 @@ import {
getEnabledProductsForCountry,
} from "@/lib/printify/productsData";
import { CountryCode } from "@/lib/stripe/createCheckoutSession";
import { track } from "@vercel/analytics/server";

export type Position = "front" | "back";
export default async function ProductTypePage({
params: { productType },
searchParams: {
imageId,
country,
position = "front",
scale = 0.7,
x = 0.5,
y = 0.5,
},
params,
searchParams,
}: {
params: { productType: string };
searchParams: {
params: Promise<{ productType: string }>;
searchParams: Promise<{
imageId: string;
country: CountryCode | "undefined";
position?: Position;
scale?: number;
x?: number;
y?: number;
};
}>;
}) {
track("Product page");
const {
imageId,
country,
position = "front",
scale = 0.7,
x = 0.5,
y = 0.5,
} = await searchParams;

if (country === "undefined") {
return <CountrySetter />;
Expand All @@ -44,6 +43,8 @@ export default async function ProductTypePage({
return <CountryPicker />;
}

const { productType } = await params;

const products = getEnabledProductsForCountry(country);
const displayName = decodeURIComponent(productType) as DisplayName;
const productInfo = products.find((p) => p.displayName === displayName);
Expand Down
2 changes: 0 additions & 2 deletions app/support/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import { Textarea } from "@/components/ui/textarea";
import { useToast } from "@/components/ui/use-toast";
import { sendFeedbackEmail } from "@/lib/email/sendFeedbackEmail";
import { Copy } from "lucide-react";
import { track } from "@vercel/analytics";

const formSchema = z.object({
email: z.string().email().optional(),
Expand Down Expand Up @@ -111,7 +110,6 @@ export default function SupportPage() {
title: "Copied email to clipboard",
duration: 1200,
});
track("Copy email to clipboard");
}}
variant={"secondary"}
>
Expand Down
3 changes: 1 addition & 2 deletions components/ExamplesCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,7 @@ export function ExampleCard({
<CardFooter>
<Link
className="w-full"
href={`/product/T%20Shirt?country=${countryCode}&imageId=${printifyImageId}`}
target="_blank"
href={`/product/T%20Shirt?country=${countryCode}&imageId=${printifyImageId}&size=L&color=Black`}
>
<Button
className="w-full"
Expand Down
3 changes: 0 additions & 3 deletions components/ImageGenerationForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import {
DialogTrigger,
} from "@/components/ui/dialog";
import { sample } from "lodash";
import { track } from "@vercel/analytics";
import { checkPromptForIssues } from "@/lib/openai/copyrightCheck";

const styleOptions = [
Expand Down Expand Up @@ -93,7 +92,6 @@ export function ImageGenerationForm({
};

const generateImage = async () => {
track("Generated Image");
if (promptValue.trim() === "") return;

const response = await checkPromptForIssues(promptValue);
Expand Down Expand Up @@ -123,7 +121,6 @@ export function ImageGenerationForm({
function randomisePrompt(): void {
const randomPrompt = getRandomPrompt();
setPromptValue(randomPrompt);
track("Randomise Prompt");
}

return (
Expand Down
2 changes: 0 additions & 2 deletions components/ImageWithLoadingAndError.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
"use client";
import { track } from "@vercel/analytics";
import Image from "next/image";
import { useState } from "react";
import { Skeleton } from "./ui/skeleton";
Expand Down Expand Up @@ -36,7 +35,6 @@ export function ImageWithLoadingAndError({
error,
msg: "Image loading error",
});
track("Image Error");
setImageErrored(true);
}}
priority
Expand Down
5 changes: 0 additions & 5 deletions components/product/ProductDetails.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ import { Slider } from "@/components/ui/slider";
import { Label } from "@/components/ui/label";
import { AppRouterInstance } from "next/dist/shared/lib/app-router-context.shared-runtime";
import { capitalize } from "lodash";
import { track } from "@vercel/analytics";
import { SaveForLaterDialogueAndButton } from "../dialogues/SaveForLaterDialogueAndButton";
import { setNewSearchParamsAndPushRoute } from "./setNewSearchParamsAndPushRoute";
import {
Expand Down Expand Up @@ -138,7 +137,6 @@ export function ProductDetails({
}, [selectedProductVariant, country, blueprint_id, print_provider_id]);

const onClick = async () => {
track("Buy now");
if (!sellingPriceInLocalCurrency) {
throw new Error("No selling price");
}
Expand Down Expand Up @@ -199,7 +197,6 @@ export function ProductDetails({
<Button
variant={"secondary"}
onClick={async () => {
track("Toggle Background");
await toggleImageBackgroundButtonAction({
currentImageId: printifyImageId,
country,
Expand All @@ -214,7 +211,6 @@ export function ProductDetails({
variant={"secondary"}
className="w-full"
onClick={() => {
track("Position Image on Front");
setNewSearchParamsAndPushRoute({
searchParams,
name: "position",
Expand All @@ -230,7 +226,6 @@ export function ProductDetails({
variant={"secondary"}
className="w-full"
onClick={() => {
track("Position image on back");
setNewSearchParamsAndPushRoute({
searchParams,
name: "position",
Expand Down
11 changes: 6 additions & 5 deletions db/client.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { neon } from "@neondatabase/serverless";
import { drizzle } from "drizzle-orm/neon-http";
import { envServer } from "@/lib/env/server";
import { drizzle } from "drizzle-orm/better-sqlite3";
import Database from "better-sqlite3";

const sql = neon(envServer.DATABASE_URL);
export const dbClient = drizzle(sql);
const sqlite = new Database("sqlite.db");
const dbClient = drizzle(sqlite);

export { dbClient };
Loading
Loading