Skip to content

Commit b7c5457

Browse files
authored
Updated the MediaLit self hosting docs (#575)
1 parent 85e3718 commit b7c5457

File tree

5 files changed

+170
-170
lines changed

5 files changed

+170
-170
lines changed

apps/docs/src/pages/en/self-hosting/self-host.md

Lines changed: 29 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -84,100 +84,44 @@ docker compose up
8484

8585
If you want to upload media (images, videos etc.) to your school, you need to configure [MediaLit](https://hub.docker.com/r/codelit/medialit). MediaLit powers CourseLit's media management and optimisation. MediaLit offers a Docker image which you can self host.
8686

87-
To self host, paste the following code in your `docker-compose.yml` file, under the existing content.
87+
To self host, follow the following steps.
8888

89-
```
90-
medialit:
91-
image: codelit/medialit
92-
environment:
93-
- DB_CONNECTION_STRING=${DB_CONNECTION_STRING_MEDIALIT}
94-
- CLOUD_ENDPOINT=${CLOUD_ENDPOINT}
95-
- CLOUD_REGION=${CLOUD_REGION}
96-
- CLOUD_KEY=${CLOUD_KEY}
97-
- CLOUD_SECRET=${CLOUD_SECRET}
98-
- CLOUD_BUCKET_NAME=${CLOUD_BUCKET_NAME}
99-
- CDN_ENDPOINT=${CDN_ENDPOINT}
100-
- TEMP_FILE_DIR_FOR_UPLOADS=${TEMP_FILE_DIR_FOR_UPLOADS}
101-
- PORT=8000
102-
- EMAIL_HOST=${EMAIL_HOST}
103-
- EMAIL_USER=${EMAIL_USER}
104-
- EMAIL_PASS=${EMAIL_PASS}
105-
- EMAIL_FROM=${EMAIL_FROM}
106-
- ENABLE_TRUST_PROXY=${ENABLE_TRUST_PROXY}
107-
- CLOUD_PREFIX=${CLOUD_PREFIX}
108-
ports:
109-
- "8000:8000"
110-
container_name: medialit
111-
restart: on-failure
112-
```
113-
114-
In your `.env` file, paste the following code (under the existing content) and change the values as per your environment.
115-
116-
```
117-
# Medialit Server
118-
DB_CONNECTION_STRING_MEDIALIT=mongodb_connection_string
119-
CLOUD_ENDPOINT=aws_s3_endpoint
120-
CLOUD_REGION=aws_s3_region
121-
CLOUD_KEY=aws_s3_key
122-
CLOUD_SECRET=aws_s3_secret
123-
CLOUD_BUCKET_NAME=aws_s3_bucket_name
124-
CDN_ENDPOINT=aws_s3_cdn_endpoint
125-
TEMP_FILE_DIR_FOR_UPLOADS=path_to_directory
126-
PORT=8000
127-
CLOUD_PREFIX=medialit
128-
```
129-
130-
Restart the services by running the following commands.
131-
132-
```
133-
docker compose stop
134-
docker compose up
135-
```
136-
137-
> **NOTE**: The MediaLit installation is done but is not yet integrated with CourseLit! There are a few more steps. Keep reading.
138-
139-
#### Obtain the API key from MediaLit
140-
141-
First you need to obtain the container id of your MediaLit instance. To do this, run:
142-
143-
```
144-
docker ps
145-
```
146-
147-
Once you have the ID of the `MediaLit` container, run the following to generate an API key
148-
149-
```
150-
docker exec <container_id | container_name> node /app/apps/api/dist/src/scripts/create-local-user.js <email>
151-
```
152-
153-
Keep the generated API key safe. We will use it in the following step.
154-
155-
> For the most up-to-date instructions, refer to the official [Readme](https://github.com/codelitdev/medialit?tab=readme-ov-file#creating-a-local-user) of MediaLit.
89+
1. Uncomment the block under the `app` service in `docker-compose.yml` which says the following.
15690

157-
#### Using Self-hosted MediaLit With CourseLit
91+
```
92+
# - MEDIALIT_APIKEY=${MEDIALIT_APIKEY}
93+
# - MEDIALIT_SERVER=http://host.docker.internal:8000
94+
```
15895
159-
Open the `.env` file and add the following lines.
96+
2. Uncomment the block titled `MediaLit` in `docker-compose.yml`.
16097
161-
```
162-
MEDIALIT_SERVER=http://localhost:8000
163-
MEDIALIT_APIKEY=key_from_above_step
164-
```
98+
3. In your `.env` file, paste the following code (under the existing content) and change the values as per your environment.
16599
166-
Now, in the `docker-compose.yml` file, add the following two lines under the `environment` block of the `app` service.
100+
```
101+
# Medialit Server
102+
CLOUD_ENDPOINT=aws_s3_endpoint
103+
CLOUD_REGION=aws_s3_region
104+
CLOUD_KEY=aws_s3_key
105+
CLOUD_SECRET=aws_s3_secret
106+
CLOUD_BUCKET_NAME=aws_s3_bucket_name
107+
S3_ENDPOINT=aws_s3_cdn_endpoint
108+
CLOUD_PREFIX=medialit
109+
MEDIALIT_APIKEY=key_to_be_obtained_docker_compose_logs
110+
```
167111
168-
```
169-
- MEDIALIT_APIKEY=${MEDIALIT_APIKEY}
170-
- MEDIALIT_SERVER=${MEDIALIT_SERVER}
171-
```
112+
4. Restart the services once to generate a user and an API key in MediaLit database. The API key
113+
will be printed to the docker compose logs. The relevant logs will look something like the following.
114+
`sh
115+
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
116+
@ API key: testcktI8Sa71QUgYtest @
117+
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
118+
`
172119
173-
Restart the server by running the following commands.
120+
Copy the API key.
174121
175-
```
176-
docker compose stop
177-
docker compose up
178-
```
122+
5. Update the `MEDIALIT_APIKEY` value in `.env` file and restart the service once again.
179123
180-
That's it! You now have a fully functioning LMS powered by CourseLit.
124+
6. That's it! You now have a fully functioning LMS powered by CourseLit and MediaLit.
181125
182126
## Hosted version
183127

apps/web/components/community/index.tsx

Lines changed: 80 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ import {
3535
CommunityMedia,
3636
CommunityPost,
3737
Constants,
38+
Media,
3839
} from "@courselit/common-models";
3940
import LoadingSkeleton from "./loading-skeleton";
4041
import { formattedLocaleDate, hasCommunityPermission } from "@ui-lib/utils";
@@ -458,94 +459,93 @@ export function CommunityForum({
458459
return response.url;
459460
};
460461

461-
const removeFile = async (mediaId: string) => {
462-
try {
463-
const fetch = new FetchBuilder()
464-
.setUrl(`${address.backend}/api/media/${mediaId}`)
465-
.setHttpMethod("DELETE")
466-
.setIsGraphQLEndpoint(false)
467-
.build();
468-
const response = await fetch.exec();
469-
if (response.message !== "success") {
470-
throw new Error(response.message);
471-
}
472-
} catch (err: any) {
473-
console.error("Error in removing file", err.message);
474-
}
475-
};
462+
// const removeFile = async (mediaId: string) => {
463+
// try {
464+
// const fetch = new FetchBuilder()
465+
// .setUrl(`${address.backend}/api/media/${mediaId}`)
466+
// .setHttpMethod("DELETE")
467+
// .setIsGraphQLEndpoint(false)
468+
// .build();
469+
// const response = await fetch.exec();
470+
// if (response.message !== "success") {
471+
// throw new Error(response.message);
472+
// }
473+
// } catch (err: any) {
474+
// console.error("Error in removing file", err.message);
475+
// }
476+
// };
476477

477478
const createPost = async (
478479
newPost: Pick<CommunityPost, "title" | "content" | "category"> & {
479480
media: MediaItem[];
480481
},
481482
) => {
482-
if (newPost.media.length > 0) {
483-
newPost.media = await uploadAttachments(newPost.media);
484-
}
485-
const mutation = `
486-
mutation ($id: String!, $title: String!, $content: String!, $category: String!, $media: [CommunityPostInputMedia]) {
487-
post: createCommunityPost(
488-
id: $id,
489-
title: $title,
490-
content: $content,
491-
category: $category,
492-
media: $media
493-
) {
494-
communityId
495-
postId
496-
title
497-
content
498-
category
499-
media {
500-
type
483+
try {
484+
if (newPost.media.length > 0) {
485+
newPost.media = await uploadAttachments(newPost.media);
486+
}
487+
const mutation = `
488+
mutation ($id: String!, $title: String!, $content: String!, $category: String!, $media: [CommunityPostInputMedia]) {
489+
post: createCommunityPost(
490+
id: $id,
491+
title: $title,
492+
content: $content,
493+
category: $category,
494+
media: $media
495+
) {
496+
communityId
497+
postId
501498
title
502-
url
499+
content
500+
category
503501
media {
504-
mediaId
505-
file
506-
thumbnail
507-
originalFileName
502+
type
503+
title
504+
url
505+
media {
506+
mediaId
507+
file
508+
thumbnail
509+
originalFileName
510+
}
508511
}
509-
}
510-
likesCount
511-
commentsCount
512-
updatedAt
513-
hasLiked
514-
user {
515-
userId
516-
name
517-
avatar {
518-
mediaId
519-
file
520-
thumbnail
512+
likesCount
513+
commentsCount
514+
updatedAt
515+
hasLiked
516+
user {
517+
userId
518+
name
519+
avatar {
520+
mediaId
521+
file
522+
thumbnail
523+
}
521524
}
525+
pinned
522526
}
523-
pinned
524527
}
525-
}
526-
`;
527-
528-
const fetch = new FetchBuilder()
529-
.setUrl(`${address.backend}/api/graph`)
530-
.setPayload({
531-
query: mutation,
532-
variables: {
533-
id: community?.communityId,
534-
content: newPost.content,
535-
category: newPost.category,
536-
title: newPost.title,
537-
media: newPost.media.map((m) => ({
538-
type: m.type,
539-
title: m.title,
540-
url: m.url,
541-
media: m.media,
542-
})),
543-
},
544-
})
545-
.setIsGraphQLEndpoint(true)
546-
.build();
528+
`;
547529

548-
try {
530+
const fetch = new FetchBuilder()
531+
.setUrl(`${address.backend}/api/graph`)
532+
.setPayload({
533+
query: mutation,
534+
variables: {
535+
id: community?.communityId,
536+
content: newPost.content,
537+
category: newPost.category,
538+
title: newPost.title,
539+
media: newPost.media.map((m) => ({
540+
type: m.type,
541+
title: m.title,
542+
url: m.url,
543+
media: m.media,
544+
})),
545+
},
546+
})
547+
.setIsGraphQLEndpoint(true)
548+
.build();
549549
const response = await fetch.exec();
550550
if (response.post) {
551551
setPosts((prevPosts) => [response.post, ...prevPosts]);
@@ -557,8 +557,9 @@ export function CommunityForum({
557557
}
558558
} catch (err: any) {
559559
toast({
560-
title: "Error",
560+
title: TOAST_TITLE_ERROR,
561561
description: err.message,
562+
variant: "destructive",
562563
});
563564
}
564565
};
@@ -580,8 +581,8 @@ export function CommunityForum({
580581
const presignedUrl = await getPresignedUrl();
581582
const media = await uploadToServer(presignedUrl, file);
582583
return media;
583-
} catch (err: any) {
584-
console.error(err.message);
584+
} catch (err) {
585+
throw new Error(`Media upload: ${err.message}`);
585586
}
586587
};
587588

@@ -905,7 +906,7 @@ export function CommunityForum({
905906
setReportReason("");
906907
} catch (err: any) {
907908
toast({
908-
title: "Error",
909+
title: TOAST_TITLE_ERROR,
909910
description: err.message,
910911
variant: "destructive",
911912
});

apps/web/pages/api/media/presigned.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ export default async function handler(
5050
);
5151
return res.status(200).json({ url: response });
5252
} catch (err: any) {
53-
error(err.mssage, {
53+
error(err.message, {
5454
stack: err.stack,
5555
});
5656
return res.status(500).json({ error: err.message });

0 commit comments

Comments
 (0)