Giter VIP home page Giter VIP logo

laguna-backend's Introduction

Laguna
backend

CI status Documentation status

laguna-backend's People

Contributors

dependabot[bot] avatar kenpaicat avatar kozabrada123 avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar

Forkers

kenpaicat

laguna-backend's Issues

[BE] Forgot password

Description

  • If user forgot password, user inputs their email/username and then performs a forgot password operation.
  • This means that we send email to this user with a special link that allows this user reset password.

[BE] Radical Independence & Redundancy

This is a very low priority long distance issue ATM.
Independence only applies to backend.

Get rid of following systems:

  • crates.io by caching required crates in Alt Registry on GitHub
  • GitHub
  • Ubuntu APT manager in CI/CD

Run multiple DBs, multiple root services, promotion system to Primary. Independent of providers, on "internal" network.

Torrent Search

Description

Powerful search > any filter.

Since we are using postgres we can have tsvector and tsquery based searches while introducing a search-optimized index on torrent filename https://www.postgresql.org/docs/current/textsearch-intro.html.

Idea of filtering

  • Much like Twitter or GH, Search = filter via "query" strings such as title:<title of torrent> uploaded_by:<username> from:<date>. (Postgres supports this very nicely).

Technical notes

  • We might even consider search by category this would require per cat/ PARTITION BY and indexing of categories.

[BE] Config files

My proposal:

.toml config files that can be overwriten by environment variables

ex:
Config.toml
port = 8000

No PORT enviornment variable

Server uses port 8000


Config.toml
port = 8000

Enviornment variables
PORT=8080

Server uses port 8080

MITM attack between DB and server

  • Problem: INSERT, CREATE and UPDATE queries carry digest('plaintext password', 'sha-256') with current design.
  • Solution: Hash password on server.

DTOs are Weird

This is something that could be fixed with GraphQL, so many different flavours of DTOs for the same thing: TorrentPatchDTO, TorrentPutDTO, TorrentDTO.

Is trying to abstract here violation of WET?

User API: GET

  • /api/user/me (current user, based on JWT)
  • /api/user/{id}

Standardize codebase docs

  • All API docs must look about the same and must be True.
  • All CONTRIBUTING.md sections must be short and on point
  • Optional: Some things can be marked #[doc(hidden)] (ie. having a struct and fn after macro is applied on eg. get_me() function in laguna-backend-api).
  • Slovenščina? (Za vse).
  • User-facing docs in laguna-docs.
  • Lektura obstoječih docsov.

login_timestamp can easily be spoofed

Currently logging in requires a timestamp that is blindly inserted into the database

that timestamp can be any valid timestamp, it can even be 20 years old or 20 years in the future

ex:

POST /login/

{
    "username_or_email": "test",
    "password": "testpassword",
    "login_timestamp": "1997-07-05T11:41:08+0000"
}

->

{
    "LoginSuccess": {
        "user": {
            "id": "b33b630d-e098-47d0-bc21-94c6a7467f17",
            "username": "test",
            "email": "test@microsoft-net",
            "first_login": "2023-07-05T11:36:26.431821Z",
            "last_login": "1997-07-05T11:41:08Z",
            "avatar_url": null,
            "role": "Normie",
            "behaviour": "Lurker",
            "is_active": true,
            "has_verified_email": false,
            "is_history_private": true,
            "is_profile_private": true
        }
    }
}

we should either validate the timestamp is plausible or generate the timestamp ourselves

[BE] Basic DB Models

Check this out: https://github.com/HDInnovations/UNIT3D-Community-Edition/blob/master/database/schema.pdf

User tablespace

User

  • id (uuid, v4)
  • username (string, unicode, escaped)
  • email (string, unicode, specific format)
  • password (hash)
  • first_login (datetime for account age)
  • last_login (datetime)
  • avatar_url (usually "link to avatar provider" + hash(email))
  • role (enum)
    • user
    • verified
    • mod
    • admin
  • behaviour (enum, computable from Torrent)
    • lurker (default, potential leech)
    • downloader (could be leech, but not known yet due to file not transferred fully)
    • freeleecher (never uploads, but thats fine because he is doing it on Freeleech)
    • leech (never uploads, ratio upload:download is very low — bad user)
    • seed (downloads and seeds for other users — good user)
    • chocked (seed but; uploading at full capacity || using blacklisted torrent client || all downloaders of this seed are seed ergo. completely uninterested)
    • uploader (seed which added Torrent to this DB — best user)
  • is_active (bool) (#9 )
  • has_verified_email (bool)
  • is_history_private (bool, history not visible) (#11 )
  • is_profile_private (bool, profile not visible)
  • [WILL_BE_COMPUTED] bytes_downloaded (bigint or decimal, computable from Torrent) (should probably be VIEW-ed)
  • [WILL_BE_COMPUTED] bytes_uploaded (bigint or decimal, computable from Torrent) (should probably be VIEW-ed)

DTOs

  • UserDTO
  • LoginDTO
  • RegisterDTO

User API

  • JWT Authorization and Role claim (#1 )
  • POST (#4 )
    • /register
      • Documentation
    • /login
      • Documentation
  • PATCH (#5 )
  • DELETE (#6 )
  • GET (#7 )
  • [NOT PLANNED] PUT (#8 )

Torrent tracking tablespace

Torrent

  • id (uuid)
  • name (string)
  • file_name (string)
  • nfo (null or string)
  • path (pathbuf)
  • info_hash (hash of info section of torrent file at path "path")
  • uploaded_by (FK onto User)
  • modded_ by (FK onto User)

Torrent API (Tracker)

Ban middleware

Description

Additional technical notes

  • Na FE se uporabi plugin: https://pub.dev/packages/platform_device_id
    Plugin pridobi device id.. Ob prijavi na api pošljemo še device id, in ga shranimo v bazo. V bazo tako shranimo vse device-idje per user in ko rabimo nekega userja bannat, preprosto bannamo vse device-idje
  • There should be a "strike counter", 3 strikes and you are out automatically.

Return only transparent `UserState` and `APIError`.

Currently success on login returns:

{
    "LoginSuccess": {
        "user": {
            "id": "b33b630d-e098-47d0-bc21-94c6a7467f17"
            "username": "test",
            "email": "[email protected]",
            "first_login": "2023-07-04T10:18:17.391698Z",
            "last_login": "2023-07-04T10:18:17.391698Z",
            "avatar_url": null,
            "role": "Normie",
            "is_active": true,
            "has_verified_email": false,
            "is_history_private": true,
            "is_profile_private": true
        }
    }
}

We want:

{
    "id": "b33b630d-e098-47d0-bc21-94c6a7467f17"
    "username": "test",
    "email": "[email protected]",
    "first_login": "2023-07-04T10:18:17.391698Z",
    "last_login": "2023-07-04T10:18:17.391698Z",
    "avatar_url": null,
    "role": "Normie",
    "is_active": true,
    "has_verified_email": false,
    "is_history_private": true,
    "is_profile_private": true
}

When its just:

"RegisterSuccess"

We want:

This can probably be achieved using #[serde(transparent)] on enum (or enum member).

Do we even need *State structs? Is 200 OK not sufficient?

[BE] Ban Models

Ban mechanism tablespace

DeviceOwner (M2M between User and Device)

DeviceOwner API

Device

  • id (unique hardware id of device)

Device API

Ban

  • id (id of ban, int)
  • device_owner_id_fk (fk to DeviceOwner)
  • ban_reason (string)
Ban API

Test-level DB create and drop

This is really about solving the multithread issue with current tests. The problem is that all tests ATM access single laguna_test_db which means many conflicts and forced us into doing DELETE FROM on teardown.

Theres two ways to combat this:

  1. Wrap every test in transaction and rollback at the end, but still use single DB. This is however cumbersome (remember its still single database).
  2. Create small DB for every test.

I think its better to do (2).

[BE] User is_active

Inactive users are marked false on is_active field. This allows for reasonable account cleanup if DB gets big.

[BE] Email verification

Description

Verify email when registring by sending user a "confirmation code" (this prevents spam accounts).
This requires mailer.

[BE] History API

Description

  • User history (uploads, downloads, completed times, choked times, gave up times, etc per torrent).
  • Maybe as a timeline.
  • Edit: Needs triage, after reconsideration, I don't think this is a good idea.

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.