Skip to content

Commit 4169132

Browse files
committed
Initializing an internal apikey to be used with web app
1 parent 2552dda commit 4169132

File tree

6 files changed

+21
-10
lines changed

6 files changed

+21
-10
lines changed

apps/api/src/apikey/queries.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,13 @@ import { getUniqueId } from "@medialit/utils";
55
export async function createApiKey(
66
userId: string,
77
name: string,
8+
internal?: boolean,
89
): Promise<Apikey> {
910
return await ApikeyModel.create({
1011
name,
1112
key: getUniqueId(),
1213
userId,
14+
internal: internal || false,
1315
});
1416
}
1517

apps/api/src/index.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import presignedUrlRoutes from "./presigning/routes";
99
import mediaSettingsRoutes from "./media-settings/routes";
1010
import logger from "./services/log";
1111
import { createUser, findByEmail } from "./user/queries";
12-
import { Apikey, User } from "@medialit/models";
12+
import { Apikey, Constants, User } from "@medialit/models";
1313
import { createApiKey } from "./apikey/queries";
1414
import { spawn } from "child_process";
1515

@@ -79,10 +79,11 @@ async function createAdminUser() {
7979
),
8080
"subscribed",
8181
);
82-
const apikey: Apikey = await createApiKey(user.id, "internal");
82+
const apikey: Apikey = await createApiKey(user.id, "App 1");
8383
console.log("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@");
8484
console.log(`@ API key: ${apikey.key} @`);
8585
console.log("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@");
86+
await createApiKey(user.id, Constants.internalApikeyName, true);
8687
}
8788
} catch (error) {
8889
logger.error({ error }, "Failed to create admin user");

apps/web/app/actions.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,11 @@ export async function sendCode(
6969
timestamp: Date.now() + 1000 * 60 * 5,
7070
});
7171

72+
if (process.env.NODE_ENV !== "production") {
73+
console.log("Sending email to", email, "with code", code);
74+
return { success: true };
75+
}
76+
7277
const transporter = createTransport({
7378
host: process.env.EMAIL_HOST,
7479
port: +(process.env.EMAIL_PORT || 587),

apps/web/app/app/[keyid]/files/file-preview/index.tsx

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,15 @@ export default function FilePreview({
2828
<DialogTrigger asChild>
2929
<div className="shadow-[0_1px_4px_rgba(0,0,0,0.25)] relative h-[148px] w-[48%] sm:h-[148px] sm:w-[148px] md:h-[148px] md:w-[148px] lg:h-[148px] lg:w-[148px]">
3030
<div className="border bg-muted-foreground relative h-[148px] w-full sm:h-[148px] sm:w-[148px] md:h-[148px] md:w-[148px] lg:h-[148px] lg:w-[148px]">
31-
<Image
32-
src={media.thumbnail}
33-
alt="Media"
34-
priority={true}
35-
quality={100}
36-
fill
37-
/>
31+
{media.thumbnail && (
32+
<Image
33+
src={media.thumbnail}
34+
alt="Media"
35+
priority={true}
36+
quality={100}
37+
fill
38+
/>
39+
)}
3840
</div>
3941
<div className="p-2 absolute bottom-0 bg-white w-full">
4042
<div className="text-sm truncate">

apps/web/app/app/[keyid]/files/page.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ export default async function Media(props: {
3636
try {
3737
totalMediaCount = await getCount(keyid);
3838
medias = await getMediaFiles(keyid, +page);
39+
console.log(medias);
3940
totalPages = medias
4041
? Math.ceil(totalMediaCount.count / Number(mediasPerPage))
4142
: 0;

apps/web/app/page.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ export default async function Home() {
2020
</div>
2121
<div className="border border-muted-foreground min-h-screen my-5 rounded p-2 md:p-2 lg:p-0">
2222
<div className="flex flex-wrap gap-2.5 p-1 sm:gap-3 sm:p-5 md:gap-3 md:p-5 lg:gap-3">
23-
{apiKeys.map((apikey: any, index: number) => (
23+
{apiKeys?.map((apikey: any, index: number) => (
2424
<div
2525
key={apikey.keyId}
2626
className="shadow-[0_1px_4px_rgba(0,0,0,0.25)] relative h-[151px] w-[48%] sm:h-[151px] sm:w-[175px] md:h-[151px] md:w-[218px] lg:h-[151px] lg:w-[228px]"

0 commit comments

Comments
 (0)