GithubHelp home page GithubHelp logo

dominux / pentaract Goto Github PK

View Code? Open in Web Editor NEW
271.0 3.0 15.0 280 KB

Unlimited file cloud storage based on using Telegram API

License: MIT License

Makefile 0.08% Rust 59.53% Dockerfile 0.96% HTML 0.41% JavaScript 38.87% CSS 0.15%
asynchronous axum cloud docker filesystem javascript rust solidjs spa tokio

pentaract's Introduction

pentaract-github-logo

GitHub Workflow Status (with event) Dockerhub latest Docker Image Size (tag) Any platform

Cloud storage system based on using Telegram as a storage so it doesn't use your server filesystem or any other paid cloud storage system underneath the hood.

Usage.example.mp4

Pentaract is aimed to take as small disk space as possible. So it does not need any code interpreter/platform to run. The whole app is just several megabytes in size. It also uses Postgres as a database and we try our best to economy space by not creating unneeded fields and tables and to wisely pick proper datatypes.

The platform itself can be used differently, like as a personal (on your own server or a local machine) platform or a platform for many users with multiple storages and so on. Since it provides Rest API, you can also use it as a file system in your backend like NextCloud or AWS S3 or S3 compatable services (like MinIO), but for now it's so early so I don't recommend to use it in production ready apps.

Installation

This project is aimed on running the app in container, so the primary way to run it is via Docker. If you don't have it installed or simply don't want to run the app via Docker, you can build it from source.

NOTE: Pentaract uses Postgres as a database. So if you are going to run it from source or run the Pentaract image only, you will need to have a Postgres instance running and available in your network so you will connect your Pentaract app to it

Docker Compose with pre-built image (recommended)

The simplest way to run and manage the app

  1. Create new directory for the app files and name it however you wish:
mkdir pentaract
  1. Go to it and place docker-compose.yml file like this one:
version: "3.9"

volumes:
  pentaract-db-volume:
    name: pentaract-db-volume

services:
  pentaract:
    container_name: pentaract
    image: thedominux/pentaract
    env_file:
      - .env
    ports:
      - ${PORT}:8000
    restart: unless-stopped
    depends_on:
      - db

  db:
    container_name: pentaract_db
    image: postgres:15.0-alpine
    environment:
      POSTGRES_USER: ${DATABASE_USER}
      POSTGRES_PASSWORD: ${DATABASE_PASSWORD}
    restart: unless-stopped
    volumes:
      - pentaract-db-volume:/var/lib/postgresql/data

And .env file like the next one. Don't forget to set your superuser email, password and secret key:

PORT=8000
WORKERS=4
CHANNEL_CAPACITY=32
SUPERUSER_EMAIL=<YOUR-EMAIL>
SUPERUSER_PASS=<YOUR-PASSWORD>
ACCESS_TOKEN_EXPIRE_IN_SECS=1800
REFRESH_TOKEN_EXPIRE_IN_DAYS=14
SECRET_KEY=<YOUR-SECRET-KEY>
TELEGRAM_API_BASE_URL=https://api.telegram.org

DATABASE_USER=pentaract
DATABASE_PASSWORD=pentaract
DATABASE_NAME=pentaract
DATABASE_HOST=db
DATABASE_PORT=5432

Secret key can be set by your hand, but I strongly recommend to use long randomly generated sequences. So you either can generate it via some free websites that provide such funcionallity or by running something like this in the terminal:

openssl rand -hex 32
  1. For now everything is set up so we can run our app:
docker compose up -d

To check if everything works fine you can go to http://localhost:8000 or to http://<YOUR-PUBLIC-IP>:8000 if you run it on a server.

If there are troubles, you can check the logs, there may be some errors:

docker logs -f pentaract
Docker Compose from source

Kind of simple way, but it's aimed to use it during development process

  1. Clone the repository and go inside the newly created directory:
git clone [email protected]:Dominux/Pentaract.git
  1. Copy .env.example to .env:
cp ./.env.example ./.env

and edit it like you wish.

  1. For now everything is set up so we can run our app:
make up

To check if everything works fine you can go to http://localhost:8000 or to http://<YOUR-PUBLIC-IP>:8000 if you run it on a server.

If there are troubles, you can check the logs, there may be some errors:

docker logs -f pentaract
Docker with pre-built image

TODO

From source

The most complex way to run the app.

Requires the next stuff to be installed:

  1. Create a directory to place all the app files wherever in your system:
mkdir ~/pentaract
  1. Clone the repository and go inside the newly created directory:
git clone [email protected]:Dominux/Pentaract.git
  1. Go to the ./pentaract directory and build server side app:
cd ./pentaract
cargo build --release

and copy the target to the app directory (or create a soft link via ln -s, does not matter):

cp ./target/release/pentaract ~/pentaract/pentaract
  1. Go to the ../ui and build the UI side of the app:
cd ../ui
pnpm run build

and copy built files into the app directory:

cp ./dist/* ~/pentaract/ui/
  1. Now go to the app directory:
cd ~/pentaract
  1. Make sure that you have Postgres database ran in your system (or available from network)
  2. Set all needed environment variables. You can check them in the .env.example file. Don't forget to set right Postgres credentials, host and port:
export PORT=8000
export WORKERS=4
# ...
  1. Finally run the app:
./pentaract

To check if everything works fine you can go to http://localhost:8000 or to http://<YOUR-PUBLIC-IP>:8000 if you run it on a server.


It's also recommended to use a HTTP reverse-proxy, like Nginx or Traefik if you use containarized version of the app and don't wanna work with Nginx and certbot.

Usage

The platform is tied to the "storages" concept. Every storage is a separated files system, like different volumes on your drive. It provides funcionallity to work with a file system like it's Google Drive: you can create files and folders, download files, see files and folders info and delete them on your wish.

In our case every storage has its own Telegram channel, where it will store all the data.

The platform also uses "storage workers". It is telegram bots that are used to upload and download files from the telegram API

Telegram API limitations

Telegram has its policy to limit some access to their platform. For us the main limitations are:

  • Requests per a period for one bot (RPM)
  • File size

Pentaract has ways to workaround them:

RPM

To workaround RPM users can create additional storage workers. For now one user can create up to 20 bots. You can also create additional accounts to create extra bots or ask your nearest for example to do so. This way from up to Telegram limitations it becomes up to you on how fast you can upload/download in Pentaract storage.

I should notice that current RPM (20 requests per minute) is completely fine to work with a single storage worker if you need the storage to be your own and don't need to upload/download big files fast.

File size

Currently Telegram API limits file download to 20 MB, hence we can't upload files more than that limit too.

Pentaract divides uploaded files into chunks and save them to Telegram separately and on downloading a file it fetches all the file chunks from the Telegram API and combine them into one in the order it was divided in. That grants ability to upload and download files with almost unlimited size (it's like you've ever downloaded a file with size >10 GB).

Current in storage features

  • Upload file
  • Download file
  • Create folder
  • Get file/folder info
  • Delete file/folder

Access

You can manage access to your storages by granting access to other users. For now, there are 3 possible roles:

  • Viewer
  • Can edit
  • Admin

So you can grant access, change it or restrict (delete access) for other users.

Future plans

Cloud storage system has a huge variety of possible ways to develop in. Like it can be a file hosting service, a cloud object storage, a cloud drive or anything else or everything in one place. And I personally don't have idea right now where to move and what users need so I'd like to know what features you would like this app to provide.

Contributing

Is highly welcoming! Create issues or take existing ones and create PRs!

pentaract's People

Contributors

dominux avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

pentaract's Issues

Request for Modification to Program Default Settings to Support serv00 Host

Dear author,

I am reaching out to request a modification to the default settings of the program. Currently, when the program is launched, it does not check whether the database has been established, which poses a challenge for users hosting the program on serv00. As serv00's built-in PostgreSQL cannot be used and access to PostgreSQL with superuser privileges is required, it is essential to incorporate this requirement into the program's default settings.

I kindly request that you consider implementing a feature in the program that checks for the existence of the database upon startup. This enhancement would greatly benefit users hosting the program on serv00 and ensure a smoother experience.

Thank you for your attention to this matter.

Best regards,

Raimbault

Add function to use files that already are on Telegram

There's a api that I use on teldrive to forward files to the software. It's this one:

# To make a folder
curl 'http://localhost:8080/api/files' \
-X POST \
-H 'content-type: application/json' \
-H 'Cookie: user-session=eyJhbGciOiJQQkVTMi1IUzI1NitBMTI4S1ciLCJlbmMiOiJBMTI4Q0JDLUhTMjU2IiwicDJjIjo2MDAwMDAsInAycyI6Ii1DT0tSWV96eTFoY3NRWHVYTmlwVHcifQ.Pph_DMX9Lh7BvJXM5eWtQTYgirWaoGLoqU2JieDvoRU1UgaOsYjTiA.RpPlMU2aQ3JtQY0PwuJqBQ.t6uMB5xzHmSjFKUgw-SllzNA_QxCtjvnAFy3WXyLQe6Owe2xv6Oz-ZwLwYWYsRVZ6nihojYlfWY7StV0iTBpDhviC83EuJilACqSJpxqNr6kEsrQpnv46SnoxIK7J8ZHZLyeJgKYICGcoKtAwJFgJPPnimouixYEPT32M94LRMOo4hvG73Dkv9HFgkW8ELB6Gi2f3S71XFGMzooCJaLWjo7vDAQyxi6QSCQpGiD3OlMH2_FjRpIkJOzQPVFpp8yWasaFxkaoeQuEDQHZ1WSDsf0An4f3htSDtvMkICmVPfScy5uMryywHVXtlJ5XiM_yKIiFdkfswweIko3BrmJbhIzLADzjgORic4O4Cn0XnbNXRouTITBwan7FRRW-XN89Cvi2bIdl-sRCdXf4Yin-uHLZoGuXLl8HzHFqkAVcAh_BbjkMamatqaXgl-A7mnq7Rtvu3es2uEdT6yRswEwrk2CnN4pMvgRwuOUvPXPHhvS0Nygw6erNi3VJh7QIC_3oD-G32aLJMabOEJv7JTeVX7YVIi4WZw8YAF5FE5sdGi59I_JGI7Dfm1O-cS6plAiF6mdWBVEOZ6N-lG_E8m6dtpDiaU-COE7SF3RJ8tjx8oAqFnqXDQpx5ACH6I_kivfNZ4i1LaQeUZmvlOT1bhAFrnAW0XazSbdzw5k49PaWEKgdKcOUBqcGAx6UEw8SxQ3ETUCkq9oULZQaKO_b8N1zMA.3Zm3XIZScz7wsON0OkQ9Gw' \
--data-raw '{"name":"testfolder","type":"folder","path":"/"}'

# to add a file to that folder
curl 'http://localhost:8080/api/files' \
-X POST -H 'content-type: application/json' \
-H 'Cookie: user-session=eyJhbGciOiJQQkVTMi1IUzI1NitBMTI4S1ciLCJlbmMiOiJBMTI4Q0JDLUhTMjU2IiwicDJjIjo2MDAwMDAsInAycyI6Ii1DT0tSWV96eTFoY3NRWHVYTmlwVHcifQ.Pph_DMX9Lh7BvJXM5eWtQTYgirWaoGLoqU2JieDvoRU1UgaOsYjTiA.RpPlMU2aQ3JtQY0PwuJqBQ.t6uMB5xzHmSjFKUgw-SllzNA_QxCtjvnAFy3WXyLQe6Owe2xv6Oz-ZwLwYWYsRVZ6nihojYlfWY7StV0iTBpDhviC83EuJilACqSJpxqNr6kEsrQpnv46SnoxIK7J8ZHZLyeJgKYICGcoKtAwJFgJPPnimouixYEPT32M94LRMOo4hvG73Dkv9HFgkW8ELB6Gi2f3S71XFGMzooCJaLWjo7vDAQyxi6QSCQpGiD3OlMH2_FjRpIkJOzQPVFpp8yWasaFxkaoeQuEDQHZ1WSDsf0An4f3htSDtvMkICmVPfScy5uMryywHVXtlJ5XiM_yKIiFdkfswweIko3BrmJbhIzLADzjgORic4O4Cn0XnbNXRouTITBwan7FRRW-XN89Cvi2bIdl-sRCdXf4Yin-uHLZoGuXLl8HzHFqkAVcAh_BbjkMamatqaXgl-A7mnq7Rtvu3es2uEdT6yRswEwrk2CnN4pMvgRwuOUvPXPHhvS0Nygw6erNi3VJh7QIC_3oD-G32aLJMabOEJv7JTeVX7YVIi4WZw8YAF5FE5sdGi59I_JGI7Dfm1O-cS6plAiF6mdWBVEOZ6N-lG_E8m6dtpDiaU-COE7SF3RJ8tjx8oAqFnqXDQpx5ACH6I_kivfNZ4i1LaQeUZmvlOT1bhAFrnAW0XazSbdzw5k49PaWEKgdKcOUBqcGAx6UEw8SxQ3ETUCkq9oULZQaKO_b8N1zMA.3Zm3XIZScz7wsON0OkQ9Gw' \
--data-raw '{"name":"inside_bo_burnam_2022_outtakes.jpg","mimeType":"image/jpeg","type":"file","parts":[{"id":373,"salt":""}],"size":36321,"path":"/testfolder","encrypted":false,"channelId":0}'

divyam234/teldrive#38 (comment)

Deal with buttons

  • Rename "Upload" button to "Upload to path"
  • Create similar button to just upload file without setting a path
  • Create a handler in backend that takes path from the path user made request from and the filename of the file he sent
  • Create a button/handler for creating a dir (allow creating only a single dir at a time, without creating subdirs, it's assumed for users, not for API, they don't need dirs at all)

Add file size

Provide info to folders and storages since we can aggregate it

There was an error when I uploaded the file

image

the following is logs:

2024-03-19T14:08:20.352508Z DEBUG pentaract::services::files: sending task to manager
2024-03-19T14:08:20.352560Z DEBUG pentaract::storage_manager: got msg
2024-03-19T14:08:21.984811Z DEBUG pentaract::services::files: file loaded successfully
2024-03-19T14:08:21.987183Z ERROR pentaract::services::files: [Telegram API] 400 Bad Request
2024-03-19T14:08:21.989883Z ERROR pentaract::errors: [Telegram API] 400 Bad Request

Add user-bot support to file size increases and speed up

I did some kind of it on my project and uploading/downloading greatly rise. And i could upload such way up to 366 bleach series quickly (each 400+mb).

So about file sizes... You can use user-bot instances which allows yo to upload files up to 2000mb or 4000mb (tg premium with speed boost). So... also it can be useful to use chunk system for more file size etc. Because 20mb chunk for some PC resources consumable

Add uploading files

Example of a successful telegram api response:

{
  "ok": true,
  "result": {
    "message_id": 2,
    "sender_chat": {
      "id": -1001998929942,
      "title": "lol",
      "type": "channel"
    },
    "chat": {
      "id": -1001998929942,
      "title": "lol",
      "type": "channel"
    },
    "date": 1698838762,
    "document": {
      "file_name": "lol.txt",
      "mime_type": "text/plain",
      "file_id": "BQACAgIAAx0EdyVAFgADAmVCOOpvJ-4j85IBsKpiO3TjBQOzAAIQOAACfysQSsBtlJerhRiEMwQ",
      "file_unique_id": "AgADEDgAAn8rEEo",
      "file_size": 5
    }
  }
}

Problem with storage

Hi, I had a bug with your program, namely I created a storage and connected the bot (uploaded the file) and the storage just disappeared after a reboot, and it doesn't help. Can you help me decide?

Same issue as this post - #26

Thank you!

Emulate FS logic on trying to create a file that already exists

Now we reject this with idiomatic 409 error code and error msg. But it should behave like real fs so if some user wansta upload the same file several times -> just let Tim cook! Behave like fs - create it with a name like {filename}({n}) where n is the next number of the same name, starts with 1.

Get outta Vec<u8>

Vec<u8> as a type to store file/chunk bytes seems to be heavy IMO

So in this issue it's assumed to research about it (to understand the whole concept and to get that I may be wrong) and to find a better way to store in case Imma right

Finishing for Alpha version

  • Move init.sql to startup functionality right in Pentaract backend code
  • Move some vars to env
  • Choose and set theme for UI
  • Create icon, add it as main icon and favicon
  • Finally build UI SPA as static inside docker image and make Pentaract server serve it
  • Minimize Dockerfile as much as possible
  • Create CI/CD to build image and push it into the Official Docker Registry
  • Add raising error if storage doesn't have storage workers when user tries to use tg API and add endpoint to check it
  • Add 404 page to UI
  • Add instructions on how to create a storage in storage worker right to UI
  • Make comprehensible README.md

The docker images cannot run on ARM

The following is run log:

# docker compose logs
pentaract  | exec /pentaract: exec format error
pentaract  | exec /pentaract: exec format error
pentaract  | exec /pentaract: exec format error
pentaract  | exec /pentaract: exec format error
pentaract  | exec /pentaract: exec format error
pentaract  | exec /pentaract: exec format error
pentaract  | exec /pentaract: exec format error
pentaract  | exec /pentaract: exec format error

Move all files functionality to the files endpoint

Before that I have considered url path as fs path, but now I realized they should be treat as http entities so storages should be available from storages endpoint and files from files one, not like it is now. TBH rn it's not that bad, we request a file or a dir by its storage id and path, but we can't keep using same routes to download and especially to mutate them

"Something went wrong" when uploading files

How to solve the problem like the title?
First create a channel, write the channel ID into the chat id, create a robot, and copy the robot's token, which is the time API, Copy it to Storage workers. How to solve this problem? Please help me.

Add rename file/folder

2 different sql queries:

  1. with exact path name for a file rename
  2. with LIKE operator to rename all subfolders and subfiles of a folder

Users and storages management

  • Add ability for new users to register
  • Add access M2M table between users and storages (enum with values like r, rw and o (for owner) and to decide whether a user has read, read/write access)
  • Check whether the user has access to a storage in all routes with storage_id in path and if not - return 404
  • Add endpoint to share/unshare storages

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.