Giter Site home page Giter Site logo

snaacky / theindex Goto Github PK

View Code? Open in Web Editor NEW
130.0 8.0 26.0 26.74 MB

The frontend, editor panel, and API of TheIndex.moe

Home Page: https://theindex.moe

License: The Unlicense

CSS 2.78% JavaScript 8.21% Dockerfile 0.39% TypeScript 88.62%
index tables website

theindex's Introduction

Website GitHub Workflow Status CodeFactor Codacy Badge Discord

TheIndex

The frontend, editor panel, and API of the TheIndex.

Getting started

The easiest way is to get started is by using Docker Compose. You need to copy the docker-compose.yml and example.env file from GitHub. Rename example.env to .env and adjust the environment variables as you need to. with the following command:

docker-compose up -d

You'll need to change <host-port> to your port of choice. The web-server is not secured via SSL/TLS, it is in your responsibility to put a reverse proxy in front of this container. When you run the image for the first time, don't forget to set your own discord-id in the env SETUP_WHITELIST_DISCORD_ID to be able to login and edit. Once your container has set up itself once, you can remove the env variable from your setup.

Database

We use mongodb as our database server. You can deploy your own mongo setup as HA service or just a simple single docker container via e.g.:

Note: The database will start empty, you have to fill the data yourself.

docker run -d \
    --name mongo \
    -v ./db:/data/db \
    mongo

For development or testing purposes it is highly recommended to use mongo-express for accessing, viewing and editing the current state of the database. If you make it publicly accessible, don't forget to secure it with login credentials.

To simply spin up a mongo-express docker container, run:

docker run -d \
    --name mongo-express \
    -p 8081:8081 \
    mongo-express

You can also take a look at our provided docker-compose file on how to set it up.

Cache-DB

To increase performance we use redis to cache results from the mongoDB. The cache is being autopopulated on cache-misses.

You can create a new instance with docker by running:

docker run -d \
    --name redis \
    redis

The redis db is already included in the example docker-compose file

Updating container image

Warning: be aware, that we do not offer any kind of official support and every update may be with breaking changes. Be sure to make backups before you update

To get the newest version of the container image, you will need to run:

docker pull ghcr.io/snaacky/theindex:latest

Afterwards, you will need to stop and remove your current running instance and start it again.

Parameters

Here is a collection of the possible environment variables with their default values you should set in your .env file:

Parameter Function Default
NEXT_PUBLIC_SITE_NAME The name of your site "The Index"
NEXT_PUBLIC_DOMAIN Your domain or IP, remove trailing slash "https://theindex.moe"
NEXTAUTH_URL Your domain or IP, remove trailing slash $NEXT_PUBLIC_DOMAIN
DATABASE_URL Take a look at mongodb docs "mongodb://mongo:27017/index"
CACHE_URL Connection string for the redis cache database "redis://redis:6379"
CHROME_URL WebSocket URL to a running chrome instance "ws://chrome:3300"
AUDIT_WEBHOOK WebHook-URL for audit-log, leave empty to disable support ""
DISCORD_CLIENT_ID Discord OAuth2 client ID "your_discord_oauth_client_id"
DISCORD_CLIENT_SECRET Discord OAuth2 client secret "your_discord_oauth_client_secret"
DISCORD_BOT_TOKEN Required to access BOT resources "your_discord_bot_token"
SETUP_WHITELIST_DISCORD_ID If you need help getting your id, check out this guide "your_discord_id"

And the following env variables are only needed when you are in dev mode and debugging the db

Parameter Function Default
ME_CONFIG_BASICAUTH_USERNAME mongo-express username "admin"
ME_CONFIG_BASICAUTH_PASSWORD mongo-express password "SUPER_SECRET"

If you want to verify how the docker-compose file fills the envs in, use docker-compose config

Getting started to code

Setup around the web app

  1. Getting started isn't that straight forward. You will need to have installed the latest version of docker with docker-compose on your machine.

  2. Start by cloning the repo via a graphical git client (highly recommended) or use the cli via

git clone https://github.com/snaacky/theindex
  1. Copy the example.env file to .env.

How to fill the .env

  • Replace NEXT_PUBLIC_DOMAIN and NEXTAUTH_URL with http://localhost:3000
  • Generate a random strong string of at least 32 characters and use it for NEXTAUTH_SECRET. You can use generators e.g. 1Password or create it yourself.
  • Change DATABASE_URL, CACHE_URL and CHROME_URL to use localhost instead of mongo, redis and chrome for example: mongodb://mongo:27017 -> becomes mongodb://localhost:27017
  • Go to https://discord.com/developers -> Create a new Application -> Go into Auth2 inside your Application panel -> Copy the CLIENT ID and CLIENT SECRET into the .env file.
  • In Redirects in Auth2 copy and paste the following URL needed to verify your Discord login http://localhost:3000/api/auth/callback/discord.
  • Fill SETUP_WHITELIST_DISCORD_ID with your Discord ID to have an admin account when you login.
  • Generate again another random strong string of at least 32 characters and use it for MEILI_MASTER_KEY. You can use generators e.g. 1Password or create it yourself.
  • Lastly if you want to change the password for mongo-express, you can do so with the last two variables, usually though none of us do while developing locally.
  1. Add the following ports to the images in the docker-compose file:
service port-mapping
mongo 27017:27017
redis 6379:6379
meili 7700:7700
chrome 3300:3000

As an example, the setup for mongo should look similar to this:

mongo:
  image: mongo
  container_name: index-db
  restart: unless-stopped
  ports:
    - '27017:27017'
  volumes:
    - ./db:/data/db
  1. Now run the command to start all the needed backend processes
docker-compose up -d mongo redis meili chrome mongo-express

Alternatively you can also just comment or remove the index service and run the command

docker-compose up -d

Web service

To start coding on the frontend, you will need to make sure, you have the latest version of node.js correctly installed. To install all the required dependencies run once:

npm install

Note: We decided to stick with npm instead of yarn to manage dependencies.

You should now have a folder called node_modules, which contains all the dependencies we need. We use Next.js as framework for our React web service. To test the web service you will have to run a db server in the background and start the frontend via:

npm run dev

After compiling you can open http://localhost:3000 in your browser of choice and see the running web application.

As we use Next.js, the frontend supports hot reloading, so you can just leave the page open, while you modify the code and see the changes on the fly in your browser.

Docker image

To create a ready-made docker image, just run:

docker build . -t index

You now have a local image with tag index that contains a distributable version of the code which can now be run.

Auto-formatter

We use prettier to ensure a consistent code style across all participants. You can simply auto-format everything with e.g. running the command

npx prettier --write .

Design of the web app

ISR/SSR

Where possible we use ISR to pre generate all publicly accessible pages for caching by CDNs or proxies while validating and fetching new data with SWR requesting our own api.

API

We serve every api request over the endpoint /api, the corresponding code can be viewed at pages/api.

  • /api/auth is reserved for NextAuth.js.
  • /api/edit/... requires a logged-in user and usually (at least) editor rights and is for modifying or creating new content. The _id keyword _new is reserved for creating new content.
  • /api/delete/... requires a logged-in user and usually (at least) editor rights and is for deleting content.
  • /api/[content]s are public endpoints for fetching a list of all items of a certain content.
  • /api/[content]/... are public endpoints for fetching information about a specific content.

Page restrictions

Every page request first has to go through _app.ts, where a basic layout is being applied and if a page has an auth property, it also validates whether the user can access the given page. Valid auth attributes are:

  • auth itself is null or typeof auth === "undefined", no restrictions. This seems to be a public page.
  • requireLogin, not really needed, but set it for logic reasons. User must be logged-in.
  • requireAdmin, only a user with admin rights can access this page.
  • requireEditor, only editors can view this page.

Contribution

Pull-requests are always welcome, but may not be always merged as it has to be in align with our idea of the index. If you want a certain feature or have an idea, you can always open a feature request in Issues or report it on our Discord in #index to be discussed. If it is not bad, in align with our ideas, and we find some time, we will certainly implement your requested feature (sometime...).

Things we use

And most importantly:

The help of our awesome community :3

Technical debts

  • We use JS instead of TS (currently in migration)
  • Unify Editor-views
  • Unify db insert and updates to the format of func(_id, dataObject) and update only as needed, GraphQL would be nice...
  • Move to add, remove api instead of having to send whole arrays to update lists -> GraphQL?

theindex's People

Contributors

dark-swordsman avatar dependabot[bot] avatar devcutler avatar emiliaaah avatar jmir1 avatar lunaneff avatar p- avatar r3d4cted avatar snaacky avatar version13 avatar yasamato 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  avatar  avatar  avatar  avatar  avatar

theindex's Issues

[BUG] Issue with Tabulator column/table width and height

Describe the bug
Tabulator will constantly keep trying to set the width and height of various elements causing a jarring visual bug.

To Reproduce
Steps to reproduce the behavior:

  1. Open two windows on Windows
  2. Snap one window to the left side and the index to the right at about ~50% width for each window
  3. Refresh the window and click the applications tab
  4. Look at Android table

Screenshots
https://cdn.discordapp.com/attachments/623361648098410516/843323849072312340/2021-05-15_20-06-13.mp4

Desktop (please complete the following information):

  • OS: [e.g. iOS] Windows
  • Browser [e.g. chrome, safari] Brave
  • Version [e.g. 22] Version 1.24.85 Chromium: 90.0.4430.212 (Official Build) (64-bit)

[BUG] Issue with data types and DeepDiff results in some edits not registering

Describe the bug
https://github.com/ranimepiracy/index/blob/d2f27527b2118ecdea1c2d636fefde5d3eec2f9e/piracymoe/utils.py#L74

DeepDiff returns two different entries: values_changed and types_changed depending on whether the value was changed or the type was changed. Right now, we only handle values_changed so when the type changes (i.e ? -> Y/N), the webhook breaks, and the change doesn't complete.

To Reproduce
Steps to reproduce the behavior:

  1. Go to the editor.
  2. Click on change any entry from ? (nothing) to Y or N

Expected behavior
The webhook to send the diff correctly and to submit the change.

license?

i dont see a license file anywhere, but i would have liked to use some a lot of the code for displaying and filling tables in a different project of mine, thats licensed under gplv3.
would something like that be ok?

[FEAT] Request to open link in new tab when clicking the website links in piracy.moe

Basically, whenever i click a website link, it redirects the piracy.moe website to the clicked website.

It would be better if it opens the streaming site in a new tab since we can always close the opened anime site in the case that we felt it wasn't good enough. We can simply go back to the piracy.moe site rather than reloading it which uses up internet data.

Question

Where can I recommend a anime website that can be on that list?

[BUG] Ping system for checking site status fails and doesn't report error to the user

When looking at the root, the ping indicator remains pulsing yellow. Users have no indication that it is not simply waiting.

What I believe is the error
Uncaught Error: Minified React error #418; visit https://reactjs.org/docs/error-decoder.html?invariant=418 for the full message or use the non-minified dev environment for full errors and additional helpful warnings.
    at sa (framework-4556c45dd113b893.js:1:48561)
    at xi (framework-4556c45dd113b893.js:1:122126)
    at bs (framework-4556c45dd113b893.js:1:109368)
    at gs (framework-4556c45dd113b893.js:1:109296)
    at vs (framework-4556c45dd113b893.js:1:109159)
    at ls (framework-4556c45dd113b893.js:1:104263)
    at S (framework-4556c45dd113b893.js:1:138450)
    at MessagePort.T (framework-4556c45dd113b893.js:1:138984)

React's page explains this as "Hydration failed because the initial UI does not match what was rendered on the server."

Full page log after 10s execution: theindex.moe-1696827382218.log

Quick fix: add try/catch block and update the UI to reflect that there was a caught Javascript error. There already exists an error state for the display, can simply update that in the catch block and properly fix later if necessary.

Could you add full link of a source in the Export function?

I was thinking about exporting periodically the list in case the site goes down, and a full link will prevent users from going to scam sites with same name.
(I also considered web.archive, but unfortunately it doesn't work very well on this site)
Also I don't know if it's intended, but it will be exported only what is selected by the columns filter, and one Export-all would be quite awesome!

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.