Skip to content

Commit

Permalink
Merge pull request #137 from codelitdev:rajat1saxena/issue135
Browse files Browse the repository at this point in the history
Bug: User creating script for self hosting is failing
  • Loading branch information
rajat1saxena authored Oct 17, 2024
2 parents ca52d4f + c60a659 commit 7dd8896
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 67 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ ENABLE_TRUST_PROXY=true
In order to interact with the API, you need to have an API key. To create one, execute the following command.

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

After running the above command, you will get an API key which you can use to interact with the app.
Expand Down
12 changes: 6 additions & 6 deletions apps/api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
"name": "@medialit/api",
"version": "0.0.27",
"private": true,
"description": "The service for managing uploads, users and tying everthing together",
"description": "A better API to manage your files on AWS S3 compatible cloud storages",
"author": {
"name": "The CodeLit Team",
"email": "hi@rajatsaxena.dev"
"email": "hi@codelit.dev"
},
"homepage": "https://github.com/codelitdev/cloud-upload-service#readme",
"homepage": "https://github.com/codelitdev/medialit#readme",
"license": "AGPL-3.0-or-later",
"main": "dist/index.js",
"main": "dist/src/index.js",
"directories": {
"lib": "lib",
"test": "__tests__"
Expand All @@ -19,10 +19,10 @@
],
"repository": {
"type": "git",
"url": "git+https://github.com/codelitdev/cloud-upload-service.git"
"url": "git+https://github.com/codelitdev/medialit.git"
},
"bugs": {
"url": "https://github.com/codelitdev/cloud-upload-service/issues"
"url": "https://github.com/codelitdev/medialit/issues"
},
"scripts": {
"build": "tsc",
Expand Down
16 changes: 1 addition & 15 deletions apps/api/src/scripts/create-local-user.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import Plan from "../plan/model";
import User from "../user/model";
import Subscription from "../subscription/model";
import connectToDatabase, { disconnect } from "../config/db";
import { createApiKey } from "../apikey/queries";
import { Apikey } from "@medialit/models";
Expand All @@ -17,24 +15,12 @@ if (!email) {
try {
await connectToDatabase();

// Create a plan
const plan = await Plan.create({
maxFileSize: 10240,
maxStorage: 1024000,
});

// Create a user
const user = await User.create({
email,
active: true,
name: "Admin",
});

// Create a subscription
await Subscription.create({
userId: user.id,
planId: plan.id,
endsAt: new Date(
subscriptionEndsAfter: new Date(
new Date().setFullYear(new Date().getFullYear() + 100)
),
});
Expand Down
21 changes: 0 additions & 21 deletions apps/api/src/subscription/model.ts

This file was deleted.

7 changes: 0 additions & 7 deletions apps/api/src/subscription/queries.ts

This file was deleted.

21 changes: 4 additions & 17 deletions apps/api/src/subscription/validate-subscription.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,10 @@
import { getPlan } from "../plan/queries";
import { Subscription } from "./model";
import { getSubscription } from "./queries";
import { getUser } from "../user/queries";

export async function validateSubscription(userId: string) {
const subscription: Subscription | null = await getSubscription(userId);
const validSubscription =
subscription && isSubscriptionValid(subscription.endsAt);
if (!validSubscription) {
return false;
}

const plan = await getPlan(subscription!.planId.toString());
if (!plan) {
return false;
}

return true;
const user = await getUser(userId);
return user && isDateInFuture(user.subscriptionEndsAfter);
}

function isSubscriptionValid(dateStr: Date): boolean {
function isDateInFuture(dateStr: Date): boolean {
return new Date(dateStr).getTime() > new Date().getTime();
}

0 comments on commit 7dd8896

Please sign in to comment.