Skip to content

Commit 7dd8896

Browse files
authored
Merge pull request #137 from codelitdev:rajat1saxena/issue135
Bug: User creating script for self hosting is failing
2 parents ca52d4f + c60a659 commit 7dd8896

File tree

6 files changed

+12
-67
lines changed

6 files changed

+12
-67
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ ENABLE_TRUST_PROXY=true
5151
In order to interact with the API, you need to have an API key. To create one, execute the following command.
5252

5353
```sh
54-
docker exec <container_id | container_name> node /app/apps/api/dist/scripts/create-local-user.js <email>
54+
docker exec <container_id | container_name> node /app/apps/api/dist/src/scripts/create-local-user.js <email>
5555
```
5656

5757
After running the above command, you will get an API key which you can use to interact with the app.

apps/api/package.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@
22
"name": "@medialit/api",
33
"version": "0.0.27",
44
"private": true,
5-
"description": "The service for managing uploads, users and tying everthing together",
5+
"description": "A better API to manage your files on AWS S3 compatible cloud storages",
66
"author": {
77
"name": "The CodeLit Team",
8-
"email": "hi@rajatsaxena.dev"
8+
"email": "hi@codelit.dev"
99
},
10-
"homepage": "https://github.com/codelitdev/cloud-upload-service#readme",
10+
"homepage": "https://github.com/codelitdev/medialit#readme",
1111
"license": "AGPL-3.0-or-later",
12-
"main": "dist/index.js",
12+
"main": "dist/src/index.js",
1313
"directories": {
1414
"lib": "lib",
1515
"test": "__tests__"
@@ -19,10 +19,10 @@
1919
],
2020
"repository": {
2121
"type": "git",
22-
"url": "git+https://github.com/codelitdev/cloud-upload-service.git"
22+
"url": "git+https://github.com/codelitdev/medialit.git"
2323
},
2424
"bugs": {
25-
"url": "https://github.com/codelitdev/cloud-upload-service/issues"
25+
"url": "https://github.com/codelitdev/medialit/issues"
2626
},
2727
"scripts": {
2828
"build": "tsc",

apps/api/src/scripts/create-local-user.ts

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
import Plan from "../plan/model";
21
import User from "../user/model";
3-
import Subscription from "../subscription/model";
42
import connectToDatabase, { disconnect } from "../config/db";
53
import { createApiKey } from "../apikey/queries";
64
import { Apikey } from "@medialit/models";
@@ -17,24 +15,12 @@ if (!email) {
1715
try {
1816
await connectToDatabase();
1917

20-
// Create a plan
21-
const plan = await Plan.create({
22-
maxFileSize: 10240,
23-
maxStorage: 1024000,
24-
});
25-
2618
// Create a user
2719
const user = await User.create({
2820
email,
2921
active: true,
3022
name: "Admin",
31-
});
32-
33-
// Create a subscription
34-
await Subscription.create({
35-
userId: user.id,
36-
planId: plan.id,
37-
endsAt: new Date(
23+
subscriptionEndsAfter: new Date(
3824
new Date().setFullYear(new Date().getFullYear() + 100)
3925
),
4026
});

apps/api/src/subscription/model.ts

Lines changed: 0 additions & 21 deletions
This file was deleted.

apps/api/src/subscription/queries.ts

Lines changed: 0 additions & 7 deletions
This file was deleted.
Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,10 @@
1-
import { getPlan } from "../plan/queries";
2-
import { Subscription } from "./model";
3-
import { getSubscription } from "./queries";
1+
import { getUser } from "../user/queries";
42

53
export async function validateSubscription(userId: string) {
6-
const subscription: Subscription | null = await getSubscription(userId);
7-
const validSubscription =
8-
subscription && isSubscriptionValid(subscription.endsAt);
9-
if (!validSubscription) {
10-
return false;
11-
}
12-
13-
const plan = await getPlan(subscription!.planId.toString());
14-
if (!plan) {
15-
return false;
16-
}
17-
18-
return true;
4+
const user = await getUser(userId);
5+
return user && isDateInFuture(user.subscriptionEndsAfter);
196
}
207

21-
function isSubscriptionValid(dateStr: Date): boolean {
8+
function isDateInFuture(dateStr: Date): boolean {
229
return new Date(dateStr).getTime() > new Date().getTime();
2310
}

0 commit comments

Comments
 (0)