Skip to content

Commit 3c36fda

Browse files
authored
Merge pull request #148 from codelitdev/medialit-package
Medialit package
2 parents 1894e10 + 92ecdf0 commit 3c36fda

32 files changed

Lines changed: 2420 additions & 33 deletions

.changeset/shaggy-cooks-love.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"medialit": patch
3+
---
4+
5+
First version of MediaLit nodejs sdk

eslint.config.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export default defineConfig([
1414
"**/node_modules",
1515
"**/dist",
1616
"**/components/ui/**",
17-
"apps/web/.next/**",
17+
"**/.next/**",
1818
".migrations/**",
1919
]),
2020
{ files: ["**/*.{js,mjs,cjs,ts,jsx,tsx}"], plugins: { js }, extends: ["js/recommended"] },

examples/next-app-router/.env

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
MEDIALIT_API_KEY=test
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
2+
3+
# dependencies
4+
/node_modules
5+
/.pnp
6+
.pnp.*
7+
.yarn/*
8+
!.yarn/patches
9+
!.yarn/plugins
10+
!.yarn/releases
11+
!.yarn/versions
12+
13+
# testing
14+
/coverage
15+
16+
# next.js
17+
/.next/
18+
/out/
19+
20+
# production
21+
/build
22+
23+
# misc
24+
.DS_Store
25+
*.pem
26+
27+
# debug
28+
npm-debug.log*
29+
yarn-debug.log*
30+
yarn-error.log*
31+
.pnpm-debug.log*
32+
33+
# env files (can opt-in for committing if needed)
34+
!.env
35+
.env.*
36+
37+
# vercel
38+
.vercel
39+
40+
# typescript
41+
*.tsbuildinfo
42+
next-env.d.ts

examples/next-app-router/README.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
This is a [Next.js](https://nextjs.org) project which demonstrates the usage of `medialit` package.
2+
3+
## Getting Started
4+
5+
First, add the MediaLit API key to `.env` file in the root directory:
6+
7+
```env
8+
MEDIALIT_API_KEY=your_api_key_here
9+
```
10+
11+
Then, run the development server:
12+
13+
```bash
14+
npm run dev
15+
# or
16+
yarn dev
17+
# or
18+
pnpm dev
19+
# or
20+
bun dev
21+
```
22+
23+
Open [http://localhost:3000](http://localhost:3000) with your browser to see the result.
24+
25+
You can start editing the page by modifying `app/page.tsx`. The page auto-updates as you edit the file.
26+
27+
## Learn More
28+
29+
To learn more about Next.js, take a look at the following resources:
30+
31+
- [Next.js Documentation](https://nextjs.org/docs) - learn about Next.js features and API.
32+
- [Learn Next.js](https://nextjs.org/learn) - an interactive Next.js tutorial.
33+
34+
You can check out [the Next.js GitHub repository](https://github.com/vercel/next.js) - your feedback and contributions are welcome!
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
import { NextRequest } from "next/server";
2+
import { MediaLit } from "medialit";
3+
4+
const client = new MediaLit();
5+
6+
export async function GET(request: NextRequest) {
7+
const searchParams = request.nextUrl.searchParams;
8+
const mediaId = searchParams.get("mediaId");
9+
10+
if (!mediaId) {
11+
return Response.json(
12+
{ error: "Media ID is required" },
13+
{ status: 400 },
14+
);
15+
}
16+
17+
try {
18+
const media = await client.get(mediaId);
19+
return Response.json(media);
20+
} catch (error) {
21+
if (error instanceof Error) {
22+
return Response.json({ error: error.message }, { status: 500 });
23+
}
24+
return Response.json(
25+
{ error: "An unknown error occurred" },
26+
{ status: 500 },
27+
);
28+
}
29+
}
30+
31+
export async function POST() {
32+
try {
33+
const presignedUrl = await client.getPresignedUploadUrl();
34+
return Response.json({ presignedUrl });
35+
} catch (error) {
36+
if (error instanceof Error) {
37+
console.log("Error getting presigned URL:", error);
38+
return Response.json({ error: error.message }, { status: 500 });
39+
}
40+
return Response.json(
41+
{ error: "An unknown error occurred" },
42+
{ status: 500 },
43+
);
44+
}
45+
}
46+
47+
export async function DELETE(request: NextRequest) {
48+
const searchParams = request.nextUrl.searchParams;
49+
const mediaId = searchParams.get("mediaId");
50+
51+
if (!mediaId) {
52+
return Response.json(
53+
{ error: "Media ID is required" },
54+
{ status: 400 },
55+
);
56+
}
57+
58+
try {
59+
await client.delete(mediaId);
60+
return Response.json({ success: true });
61+
} catch (error) {
62+
if (error instanceof Error) {
63+
return Response.json({ error: error.message }, { status: 500 });
64+
}
65+
return Response.json(
66+
{ error: "An unknown error occurred" },
67+
{ status: 500 },
68+
);
69+
}
70+
}
25.3 KB
Binary file not shown.
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
@import "tailwindcss";
2+
3+
:root {
4+
--background: #ffffff;
5+
--foreground: #171717;
6+
}
7+
8+
@theme inline {
9+
--color-background: var(--background);
10+
--color-foreground: var(--foreground);
11+
--font-sans: var(--font-geist-sans);
12+
--font-mono: var(--font-geist-mono);
13+
}
14+
15+
@media (prefers-color-scheme: dark) {
16+
:root {
17+
--background: #0a0a0a;
18+
--foreground: #ededed;
19+
}
20+
}
21+
22+
body {
23+
background: var(--background);
24+
color: var(--foreground);
25+
font-family: Arial, Helvetica, sans-serif;
26+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import type { Metadata } from "next";
2+
import { Geist, Geist_Mono } from "next/font/google";
3+
import "./globals.css";
4+
5+
const geistSans = Geist({
6+
variable: "--font-geist-sans",
7+
subsets: ["latin"],
8+
});
9+
10+
const geistMono = Geist_Mono({
11+
variable: "--font-geist-mono",
12+
subsets: ["latin"],
13+
});
14+
15+
export const metadata: Metadata = {
16+
title: "Create Next App",
17+
description: "Generated by create next app",
18+
};
19+
20+
export default function RootLayout({
21+
children,
22+
}: Readonly<{
23+
children: React.ReactNode;
24+
}>) {
25+
return (
26+
<html lang="en">
27+
<body
28+
className={`${geistSans.variable} ${geistMono.variable} antialiased`}
29+
>
30+
{children}
31+
</body>
32+
</html>
33+
);
34+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import MediaUploadForm from "@/components/MediaUploadForm";
2+
3+
export default function Home() {
4+
return (
5+
<div className="grid grid-rows-[20px_1fr_20px] items-center justify-items-center min-h-screen p-8 pb-20 gap-16 sm:p-20">
6+
<main className="flex flex-col gap-[32px] row-start-2 items-center sm:items-start w-full max-w-2xl">
7+
<div className="text-center sm:text-left w-full">
8+
<h1 className="text-4xl font-bold mb-4">MediaLit Demo</h1>
9+
<p className="text-gray-600 dark:text-gray-300 mb-8">
10+
This demo shows how to use the MediaLit package to
11+
handle media files. Upload an image to see:
12+
</p>
13+
<ul className="text-left list-disc list-inside space-y-2 mb-8">
14+
<li>Direct upload using presigned URLs</li>
15+
<li>Automatic thumbnail generation</li>
16+
<li>Media information retrieval</li>
17+
<li>File deletion</li>
18+
</ul>
19+
</div>
20+
21+
<MediaUploadForm />
22+
</main>
23+
</div>
24+
);
25+
}

0 commit comments

Comments
 (0)