Skip to content
This repository has been archived by the owner on Apr 23, 2024. It is now read-only.

Commit

Permalink
Merge pull request #331 from mgilangjanuar/staging
Browse files Browse the repository at this point in the history
Release v2.2.0
  • Loading branch information
mgilangjanuar authored Apr 20, 2022
2 parents ccd357d + 1fc843f commit aea60e5
Show file tree
Hide file tree
Showing 41 changed files with 1,097 additions and 992 deletions.
5 changes: 1 addition & 4 deletions docker/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,7 @@ services:
REACT_APP_TG_API_ID: ${TG_API_ID}
REACT_APP_TG_API_HASH: ${TG_API_HASH}
environment:
DB_NAME: teledrive
DB_HOST: db
DB_USERNAME: postgres
DB_PASSWORD: ${DB_PASSWORD}
DATABASE_URL: postgres://postgres:${DB_PASSWORD}@db:5432/teledrive
REDIS_URI: redis://redis:6379
env_file:
- .env
Expand Down
9 changes: 0 additions & 9 deletions docs/docs/Deployment/heroku.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,6 @@ Get started by build all needed services.

**Note.** *Change `YOUR_DB_CONNECTION_URI` to your database connection URI.*

- Import dump.sql

```shell
heroku pg:psql --app YOUR_APP_NAME -f ./server/src/model/migrations/dump.sql
heroku pg:psql --app YOUR_APP_NAME -f ./server/src/model/migrations/dump.20220406.sql
```

**Note.** *Change `YOUR_APP_NAME` to your application name from Heroku.*

### Provide environment variables

Set all variables with your own values to Heroku:
Expand Down
21 changes: 0 additions & 21 deletions docs/docs/Installation/manual.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,27 +106,6 @@ You need to create and import the database schema.
CREATE DATABASE teledrive;
```

- Import schema

Exit from psql (with `\q`) and run this command:

```shell
psql teledrive < ./server/src/model/migrations/dump.sql
psql teledrive < ./server/src/model/migrations/dump.20220406.sql
```

Sometimes, we need to copy the dump file to the `/var/lib/postgresql` directory first:

```shell
sudo cp ./server/src/model/migrations/dump.sql /var/lib/postgresql/
# change owner
sudo su - postgres
# import dump file
psql teledrive < dump.sql
```

**Note.** *If you follow the instructions above then you need to fill the server variables:*
- `DATABASE_URL`: postgresql://postgres@localhost:5432/teledrive

Expand Down
4 changes: 4 additions & 0 deletions install.docker.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

set -e

echo "Node Version: $(git --version)"
echo "cURL Version: $(docker -v)"
echo "cURL Version: $(docker-compose -v)"

if [ ! -f docker/.env ]
then
echo "Generating .env file..."
Expand Down
6 changes: 6 additions & 0 deletions install.manual.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

set -e

echo "Node Version: $(git --version)"
echo "Node Version: $(node -v)"
echo "Yarn Version: $(yarn -v)"
echo "cURL Version: $(curl -V)"
echo "cURL Version: $(psql -V)"

if [ ! -f server/.env ]
then
echo "Generating server/.env file..."
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "teledrive",
"version": "2.1.2",
"version": "2.2.0",
"repository": "[email protected]:mgilangjanuar/teledrive.git",
"author": "M Gilang Januar <[email protected]>",
"license": "MIT",
Expand Down
3 changes: 3 additions & 0 deletions server/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
node_modules
# Keep environment variables out of version control
.env
11 changes: 6 additions & 5 deletions server/package.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
{
"name": "server",
"version": "2.1.2",
"version": "2.2.0",
"main": "dist/index.js",
"license": "MIT",
"private": true,
"scripts": {
"start": "nodemon dist/index.js --watch",
"build": "tsc"
"build": "rimraf dist && eslint -c .eslintrc.js --ext .ts . && tsc",
"postbuild": "prisma migrate deploy"
},
"dependencies": {
"@prisma/client": "^3.12.0",
"@sentry/node": "^6.14.1",
"@sentry/tracing": "^6.14.1",
"@types/moment": "^2.13.0",
Expand Down Expand Up @@ -43,13 +45,12 @@
"node-mailjet": "^3.3.4",
"pg": "^8.7.1",
"pg-connection-string": "^2.5.0",
"prisma": "^3.12.0",
"rate-limiter-flexible": "^2.3.1",
"redis": "^4.0.1",
"serialize-error": "^8.1.0",
"source-map-support": "^0.5.19",
"teledrive-client": "^2.5.55",
"typeorm": "^0.2.41",
"typeorm-naming-strategies": "^2.0.0",
"teledrive-client": "^2.6.13",
"uuid-random": "^1.3.2"
},
"devDependencies": {
Expand Down
107 changes: 107 additions & 0 deletions server/prisma/migrations/20220420012853_init/migration.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
CREATE EXTENSION IF NOT EXISTS "uuid-ossp";

-- CreateTable
CREATE TABLE "config" (
"created_at" TIMESTAMPTZ(6) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updated_at" TIMESTAMPTZ(6) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"id" UUID NOT NULL DEFAULT uuid_generate_v4(),
"invitation_code" VARCHAR,
"disable_signup" BOOLEAN NOT NULL DEFAULT false,
"allow_server_storage_use" BOOLEAN NOT NULL DEFAULT false,

CONSTRAINT "pk_af2ddc24176f1572cbdd4b45992" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "files" (
"created_at" TIMESTAMPTZ(6) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updated_at" TIMESTAMPTZ(6) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"id" UUID NOT NULL DEFAULT uuid_generate_v4(),
"name" VARCHAR NOT NULL,
"type" VARCHAR,
"message_id" VARCHAR,
"mime_type" VARCHAR,
"size" BIGINT,
"uploaded_at" TIMESTAMPTZ(6),
"upload_progress" DOUBLE PRECISION,
"user_id" UUID NOT NULL,
"parent_id" UUID,
"deleted_at" TIMESTAMPTZ(6),
"sharing_options" VARCHAR[],
"signed_key" VARCHAR,
"file_id" VARCHAR,
"link_id" UUID,
"forward_info" VARCHAR,

CONSTRAINT "PK_6c16b9093a142e0e7613b04a3d9" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "rate_limits" (
"key" VARCHAR(255) NOT NULL,
"points" INTEGER NOT NULL DEFAULT 0,
"expire" BIGINT,

CONSTRAINT "rate_limits_pkey" PRIMARY KEY ("key")
);

-- CreateTable
CREATE TABLE "usages" (
"created_at" TIMESTAMPTZ(6) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updated_at" TIMESTAMPTZ(6) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"key" VARCHAR NOT NULL,
"usage" BIGINT NOT NULL,
"expire" TIMESTAMPTZ(6) NOT NULL,

CONSTRAINT "PK_7d8e95b6dd4c0e87cad4972da13" PRIMARY KEY ("key")
);

-- CreateTable
CREATE TABLE "users" (
"created_at" TIMESTAMPTZ(6) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updated_at" TIMESTAMPTZ(6) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"id" UUID NOT NULL DEFAULT uuid_generate_v4(),
"username" VARCHAR NOT NULL,
"name" VARCHAR,
"email" VARCHAR,
"tg_id" VARCHAR,
"plan" VARCHAR,
"settings" JSONB,
"role" VARCHAR,

CONSTRAINT "PK_a3ffb1c0c8416b9fc6f907b7433" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "waitings" (
"created_at" TIMESTAMPTZ(6) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updated_at" TIMESTAMPTZ(6) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"id" UUID NOT NULL DEFAULT uuid_generate_v4(),
"email" VARCHAR NOT NULL,

CONSTRAINT "PK_f0cfe98441cf0fb92db66ae71c4" PRIMARY KEY ("id")
);

-- CreateIndex
CREATE INDEX "files_link_id_idx" ON "files"("link_id");

-- CreateIndex
CREATE INDEX "files_message_id_idx" ON "files"("message_id");

-- CreateIndex
CREATE INDEX "files_parent_id_idx" ON "files"("parent_id");

-- CreateIndex
CREATE INDEX "files_user_id_idx" ON "files"("user_id");

-- CreateIndex
CREATE INDEX "tg_id" ON "users"("tg_id");

-- AddForeignKey
ALTER TABLE "files" ADD CONSTRAINT "files_links_fkey" FOREIGN KEY ("link_id") REFERENCES "files"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "files" ADD CONSTRAINT "files_files_fkey" FOREIGN KEY ("parent_id") REFERENCES "files"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "files" ADD CONSTRAINT "files_users_fkey" FOREIGN KEY ("user_id") REFERENCES "users"("id") ON DELETE CASCADE ON UPDATE CASCADE;
3 changes: 3 additions & 0 deletions server/prisma/migrations/migration_lock.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Please do not edit this file manually
# It should be added in your version-control system (i.e. Git)
provider = "postgresql"
86 changes: 86 additions & 0 deletions server/prisma/schema.prisma
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
generator client {
provider = "prisma-client-js"
}

datasource db {
provider = "postgresql"
url = env("DATABASE_URL")
}

/// The underlying table does not contain a valid unique identifier and can therefore currently not be handled by the Prisma Client.
model config {
created_at DateTime @default(now()) @db.Timestamptz(6)
updated_at DateTime @default(now()) @db.Timestamptz(6)
id String @id(map: "pk_af2ddc24176f1572cbdd4b45992") @default(dbgenerated("uuid_generate_v4()")) @db.Uuid
invitation_code String? @db.VarChar
disable_signup Boolean @default(false)
allow_server_storage_use Boolean @default(false)
}

model files {
created_at DateTime @default(now()) @db.Timestamptz(6)
updated_at DateTime @default(now()) @db.Timestamptz(6)
id String @id(map: "PK_6c16b9093a142e0e7613b04a3d9") @default(dbgenerated("uuid_generate_v4()")) @db.Uuid
name String @db.VarChar
type String? @db.VarChar
message_id String? @db.VarChar
mime_type String? @db.VarChar
size BigInt?
uploaded_at DateTime? @db.Timestamptz(6)
upload_progress Float?
user_id String @db.Uuid
parent_id String? @db.Uuid
deleted_at DateTime? @db.Timestamptz(6)
sharing_options String[] @db.VarChar
signed_key String? @db.VarChar
file_id String? @db.VarChar
link_id String? @db.Uuid
forward_info String? @db.VarChar
link files? @relation("filesTofiles_link_id", fields: [link_id], references: [id], onDelete: Cascade, map: "files_links_fkey")
parent files? @relation("filesTofiles_parent_id", fields: [parent_id], references: [id], onDelete: Cascade, map: "files_files_fkey")
users users @relation(fields: [user_id], references: [id], onDelete: Cascade, map: "files_users_fkey")
links files[] @relation("filesTofiles_link_id")
parents files[] @relation("filesTofiles_parent_id")
@@index([link_id])
@@index([message_id])
@@index([parent_id])
@@index([user_id])
}

model rate_limits {
key String @id @db.VarChar(255)
points Int @default(0)
expire BigInt?
}

model usages {
created_at DateTime @default(now()) @db.Timestamptz(6)
updated_at DateTime @default(now()) @db.Timestamptz(6)
key String @id(map: "PK_7d8e95b6dd4c0e87cad4972da13") @db.VarChar
usage BigInt
expire DateTime @db.Timestamptz(6)
}

model users {
created_at DateTime @default(now()) @db.Timestamptz(6)
updated_at DateTime @default(now()) @db.Timestamptz(6)
id String @id(map: "PK_a3ffb1c0c8416b9fc6f907b7433") @default(dbgenerated("uuid_generate_v4()")) @db.Uuid
username String @db.VarChar
name String? @db.VarChar
email String? @db.VarChar
tg_id String? @db.VarChar
plan String? @db.VarChar
settings Json?
role String? @db.VarChar
files files[]
@@index([tg_id], map: "tg_id")
}

model waitings {
created_at DateTime @default(now()) @db.Timestamptz(6)
updated_at DateTime @default(now()) @db.Timestamptz(6)
id String @id(map: "PK_f0cfe98441cf0fb92db66ae71c4") @default(dbgenerated("uuid_generate_v4()")) @db.Uuid
email String @db.VarChar
}
4 changes: 2 additions & 2 deletions server/src/Types.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { users } from '@prisma/client'
import { TelegramClient } from 'teledrive-client'
import { Users } from './model/entities/Users'

declare module 'http' {
interface IncomingMessage {
tg?: TelegramClient,
user?: Users,
user?: users,
userAuth?: any,
authKey?: string
}
Expand Down
6 changes: 3 additions & 3 deletions server/src/api/middlewares/Auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import { LogLevel } from 'teledrive-client/extensions/Logger'
import { StringSession } from 'teledrive-client/sessions'
import { NextFunction, Request, Response } from 'express'
import { verify } from 'jsonwebtoken'
import { Users } from '../../model/entities/Users'
import { Redis } from '../../service/Cache'
import { CONNECTION_RETRIES, TG_CREDS } from '../../utils/Constant'
import { prisma } from '../../model'

export async function Auth(req: Request, _: Response, next: NextFunction): Promise<any> {
const authkey = (req.headers.authorization || req.cookies.authorization)?.replace(/^Bearer\ /gi, '')
Expand Down Expand Up @@ -49,7 +49,7 @@ export async function Auth(req: Request, _: Response, next: NextFunction): Promi
}
}

const user = await Users.findOne({ tg_id: userAuth['id'].toString() })
const user = await prisma.users.findFirst({ where: { tg_id: userAuth['id'].toString() } })
if (!user) {
throw { status: 401, body: { error: 'User not found' } }
}
Expand Down Expand Up @@ -103,7 +103,7 @@ export async function AuthMaybe(req: Request, _: Response, next: NextFunction):
}
}

const user = await Users.findOne({ tg_id: userAuth['id'].toString() })
const user = await prisma.users.findFirst({ where: { tg_id: userAuth['id'].toString() } })
if (!user) {
// throw { status: 401, body: { error: 'User not found' } }
return [userAuth, null]
Expand Down
Loading

0 comments on commit aea60e5

Please sign in to comment.