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 #143 from mgilangjanuar/staging
Browse files Browse the repository at this point in the history
Release v1.1.2
  • Loading branch information
mgilangjanuar authored Dec 27, 2021
2 parents 39187f6 + 8e08a40 commit dc981cd
Show file tree
Hide file tree
Showing 12 changed files with 29 additions and 26 deletions.
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": "1.1.1",
"version": "1.1.2",
"repository": "git@github.com:mgilangjanuar/teledrive.git",
"author": "M Gilang Januar <mgilangjanuar@gmail.com>",
"license": "MIT",
Expand Down
4 changes: 3 additions & 1 deletion server/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "server",
"version": "1.1.1",
"version": "1.1.2",
"main": "dist/index.js",
"license": "MIT",
"private": true,
Expand Down Expand Up @@ -28,6 +28,7 @@
"express-list-endpoints": "^6.0.0",
"express-rate-limit": "^5.3.0",
"flatted": "^3.2.2",
"geoip-lite": "^1.4.2",
"glob": "^7.1.7",
"input": "^1.0.1",
"is-uuid": "^1.0.2",
Expand Down Expand Up @@ -59,6 +60,7 @@
"@types/express-fileupload": "^1.1.7",
"@types/express-list-endpoints": "^6.0.0",
"@types/express-rate-limit": "^5.1.3",
"@types/geoip-lite": "^1.4.1",
"@types/glob": "^7.1.4",
"@types/is-uuid": "^1.0.0",
"@types/jsonwebtoken": "^8.5.5",
Expand Down
14 changes: 7 additions & 7 deletions server/src/api/v1/Files.ts
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ export class Files {
model = new Model()
model.name = name,
model.mime_type = mimetype
model.size = Number(size)
model.size = size
model.user_id = req.user.id
model.type = type
model.parent_id = parentId as string || null
Expand Down Expand Up @@ -326,7 +326,7 @@ export class Files {
name: model.name
}),
forceDocument,
fileSize: model.size,
fileSize: Number(model.size),
attributes: forceDocument ? [
new Api.DocumentAttributeFilename({ fileName: model.name })
] : undefined,
Expand Down Expand Up @@ -444,20 +444,20 @@ export class Files {
if (!usage) {
usage = new Usages()
usage.key = req.user ? `u:${req.user.id}` : `ip:${req.ip}`
usage.usage = 0
usage.usage = '0'
usage.expire = moment().add(1, 'day').toDate()
await usage.save()
}

if (new Date().getTime() - new Date(usage.expire).getTime() > 0) { // is expired
usage.expire = moment().add(1, 'day').toDate()
usage.usage = 0
usage.usage = '0'
await usage.save()
}

if (!req.user || !req.user.plan || req.user.plan === 'free') { // not expired and free plan
// check quota
if (usage.usage + file.size > 1_500_000_000) {
if (Number(usage.usage) + Number(file.size) > 1_500_000_000) {
throw { status: 402, body: { error: 'Payment required' } }
}
}
Expand Down Expand Up @@ -497,12 +497,12 @@ export class Files {
const chunk = 512 * 1024
let idx = 0

while (!cancel && data === null || data.length && idx * chunk < file.size) {
while (!cancel && data === null || data.length && bigInt(file.size).greater(bigInt(idx * chunk))) {
// const startDate = Date.now()
data = await req.tg.downloadMedia(chat['messages'][0].media, {
...thumb ? { sizeType: 'i' } : {},
start: idx++ * chunk,
end: Math.min(file.size, idx * chunk - 1),
end: bigInt.min(bigInt(file.size), bigInt(idx * chunk - 1)).toJSNumber(),
workers: 1, // using 1 for stable
progressCallback: (() => {
const updateProgess: any = () => {
Expand Down
4 changes: 2 additions & 2 deletions server/src/api/v1/Users.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,14 @@ export class Users {
if (!usage) {
usage = new Usages()
usage.key = req.user ? `u:${req.user.id}` : `ip:${req.ip}`
usage.usage = 0
usage.usage = '0'
usage.expire = moment().add(1, 'day').toDate()
await usage.save()
}

if (new Date().getTime() - new Date(usage.expire).getTime() > 0) { // is expired
usage.expire = moment().add(1, 'day').toDate()
usage.usage = 0
usage.usage = '0'
await usage.save()
}

Expand Down
5 changes: 3 additions & 2 deletions server/src/api/v1/Utils.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Request, Response } from 'express'
import { lookup } from 'geoip-lite'
import { Endpoint } from '../base/Endpoint'

@Endpoint.API()
Expand All @@ -10,7 +11,7 @@ export class Utils {
}

@Endpoint.GET()
public async ipinfo(req: Request & { ipInfo: any }, res: Response): Promise<any> {
return res.send({ ipinfo: req.ipInfo })
public async ipinfo(req: Request, res: Response): Promise<any> {
return res.send({ ipinfo: { ip: req.ip, ...lookup(req.ip) } })
}
}
3 changes: 0 additions & 3 deletions server/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import express, {
urlencoded
} from 'express'
import listEndpoints from 'express-list-endpoints'
import expressip from 'express-ipinfo'
import morgan from 'morgan'
import path from 'path'
import { Pool } from 'pg'
Expand Down Expand Up @@ -76,8 +75,6 @@ app.use(Sentry.Handlers.tracingHandler())

app.set('trust proxy', 1)

app.use(expressip().getIpInfoMiddleware)

app.use(cors({
credentials: true,
origin: [
Expand Down
4 changes: 2 additions & 2 deletions server/src/model/entities/Files.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ export class Files extends BaseModelWithID {
@Column({ default: null })
mime_type?: string

@Column({ default: null })
size?: number
@Column('bigint', { default: null })
size?: string

@Column({ type: 'timestamptz', default: null })
uploaded_at?: Date
Expand Down
4 changes: 2 additions & 2 deletions server/src/model/entities/Usages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ export class Usages extends BaseModel {
@PrimaryColumn()
key: string

@Column()
usage: number
@Column('bigint')
usage: string

@Column('timestamptz')
expire: Date
Expand Down
4 changes: 1 addition & 3 deletions server/src/model/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@

import bigInt from 'big-integer'
import { readFileSync } from 'fs'
import { types } from 'pg'
import {
Connection,
ConnectionOptions,
Expand Down Expand Up @@ -62,4 +60,4 @@ export const runDB = async (): Promise<void> => {
}

// hacky way for parse the value in int8 type columns
types.setTypeParser(types.builtins.INT8, (value: string) => bigInt(value))
// types.setTypeParser(types.builtins.INT8, (value: string) => bigInt(value))
2 changes: 1 addition & 1 deletion web/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "web",
"version": "1.1.1",
"version": "1.1.2",
"private": true,
"dependencies": {
"@craco/craco": "^6.3.0",
Expand Down
2 changes: 1 addition & 1 deletion web/src/pages/components/Navbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ const Navbar: React.FC<Props> = ({ user, page }) => {
<div style={{ padding: '10px' }}>
Bandwidth usage: { }
{(user?.user?.plan || user?.plan) === 'premium' ? <Tag color="green">Unlimited</Tag> : <Tooltip placement="left" title={<>You can download up to {prettyBytes(Math.max(0, 1_500_000_000 - Number(usage?.usage.usage)))} until {moment(usage?.usage.expire).local().format('lll')}</>}>
<Progress status="exception" percent={Number((usage?.usage.usage / 1_500_000_000 * 100).toFixed(1))} />
<Progress status="exception" percent={Number((Number(usage?.usage.usage) / 1_500_000_000 * 100).toFixed(1))} />
</Tooltip>}
</div>
<Menu>
Expand Down
7 changes: 6 additions & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2103,6 +2103,11 @@
"@types/qs" "*"
"@types/serve-static" "*"

"@types/geoip-lite@^1.4.1":
version "1.4.1"
resolved "https://registry.yarnpkg.com/@types/geoip-lite/-/geoip-lite-1.4.1.tgz#2c0d787fb14b2463b244baca1f3b9023fba3c49b"
integrity sha512-qHH5eF3rL1wwqpzdsgMdgskfdWXxxQvJb9POJ66NK7/1l3QXsqHLpIheh9OmhtqZ2CF7AmN0sA2R4PgW8JSm7w==

"@types/glob@^7.1.1", "@types/glob@^7.1.4":
version "7.1.4"
resolved "https://registry.yarnpkg.com/@types/glob/-/glob-7.1.4.tgz#ea59e21d2ee5c517914cb4bc8e4153b99e566672"
Expand Down Expand Up @@ -6607,7 +6612,7 @@ gensync@^1.0.0-beta.1, gensync@^1.0.0-beta.2:
resolved "https://registry.yarnpkg.com/gensync/-/gensync-1.0.0-beta.2.tgz#32a6ee76c3d7f52d46b2b1ae5d93fea8580a25e0"
integrity sha512-3hN7NaskYvMDLQY55gnW3NQ+mesEAepTqlg+VEbj7zzqEMBVNhzcGYYeqFo/TlYz6eQiFcp1HcsCZO+nGgS8zg==

geoip-lite@^1.3.4:
geoip-lite@^1.3.4, geoip-lite@^1.4.2:
version "1.4.2"
resolved "https://registry.yarnpkg.com/geoip-lite/-/geoip-lite-1.4.2.tgz#f41dc50086cce3bc31a6d2d578cad1c37f9f17b3"
integrity sha512-1rUNqar68+ldSSlSMdpLZPAM+NRokIDzB2lpQFRHSOaDVqtmy25jTAWe0lM2GqWFeaA35RiLhF8GF0vvL+qOKA==
Expand Down

0 comments on commit dc981cd

Please sign in to comment.