OposicionesWeb is a Flask-based web application designed to help users visualize videos and files (such as PDFs) organized in a directory structure. The app scans a specified directory (/folders by default) to display folders, subfolders, and their associated files in a user-friendly interface. It supports features like video playback, PDF viewing, user authentication, and admin functionalities for managing content.
This app is particularly useful for organizing and accessing educational or professional materials stored in a folder-based structure.
- Folder Visualization: Automatically scans a directory (
/folders) to display folders and their subfolders. - File Support: Supports video files (
.mp4) for playback and documents (.pdf) for viewing and downloading. - User Authentication: Includes login/logout functionality to secure access to content.
- Admin Features: Admins can manage users, videos, and view logs.
- Responsive Design: Built with Bootstrap for a mobile-friendly interface.
Before setting up the app, ensure you have the following installed:
- Docker
- Docker Compose
- A directory containing your files (videos and PDFs) structured as follows:
/path/to/folders/ ├── Folder1/ │ ├── video1.mp4 │ ├── document1.pdf │ └── Subfolder/ │ ├── video2.mp4 │ └── document2.pdf ├── Folder2/ │ ├── video3.mp4 │ └── document3.pdf
Follow these steps to get the app running using Docker Compose.
Clone this repository to your local machine:
git clone https://github.com/yourusername/oposicionesweb.git
cd oposicioneswebCreate a .env file in the root directory of the project to define the necessary environment variables. Below is an example .env file with the required variables:
# Flask app configuration
SECRET_KEY=your-secret-key-here
FLASK_ENV=production
# Database configuration
DATABASE_URL=postgresql://user:password@db:5432/oposicionesdb
# Directory for folder files (this should match the volume mapping in docker-compose.yml)
CURSOS_DIR=/folders
# Maximum queue size for processing (optional, default is 5)
MAX_QUEUE_SIZE=5SECRET_KEY: A secret key for Flask to secure sessions and other cryptographic operations. Replaceyour-secret-key-herewith a secure, random string.FLASK_ENV: Set toproductionfor a production environment ordevelopmentfor debugging.DATABASE_URL: The connection string for the PostgreSQL database. The format ispostgresql://user:password@host:port/dbname. Adjustuser,password,db, andoposicionesdbas needed.CURSOS_DIR: The directory where the app will look for folder files. This should match the volume mapping indocker-compose.yml. Default is/folders.MAX_QUEUE_SIZE: The maximum number of items in the processing queue (optional, defaults to 5).
Below is an example docker-compose.yml file to run the app with a PostgreSQL database. Create or update this file in the root directory of the project:
version: '3.8'
services:
web:
build: .
ports:
- "5000:5000"
environment:
- FLASK_ENV=${FLASK_ENV}
- SECRET_KEY=${SECRET_KEY}
- DATABASE_URL=${DATABASE_URL}
- CURSOS_DIR=${CURSOS_DIR}
- MAX_QUEUE_SIZE=${MAX_QUEUE_SIZE}
volumes:
- /path/to/folders:/folders
depends_on:
- db
networks:
- app-network
db:
image: postgres:13
environment:
- POSTGRES_USER=user
- POSTGRES_PASSWORD=password
- POSTGRES_DB=oposicionesdb
volumes:
- db-data:/var/lib/postgresql/data
networks:
- app-network
networks:
app-network:
driver: bridge
volumes:
db-data:- web service:
- Builds the Flask app from the
Dockerfilein the current directory. - Maps port
5000on the host to port5000in the container. - Loads environment variables from the
.envfile. - Mounts the local directory
/path/to/folders(where your files are stored) to/foldersin the container. Replace/path/to/folderswith the actual path to your files. - Depends on the
dbservice to ensure the database is running before the app starts.
- Builds the Flask app from the
- db service:
- Uses the official PostgreSQL 13 image.
- Sets up the database with the user, password, and database name specified in the environment variables.
- Persists database data using a named volume (
db-data).
- networks:
- Creates a bridge network (
app-network) for communication between thewebanddbservices.
- Creates a bridge network (
Run the following command to build and start the app:
docker-compose up -d --build- The
-dflag runs the containers in the background. - The
--buildflag ensures the app is rebuilt if there are changes.
Once the containers are running, you can access the app at:
http://localhost:5000
- Log in with your credentials (if you haven't set up users yet, you may need to create an admin user directly in the database).
- The app will scan the
/foldersdirectory and display the available folders in the navigation menu.
To stop the app, run:
docker-compose downIf you want to remove the database volume as well (this will delete all database data), add the -v flag:
docker-compose down -vThe app expects files to be organized in the following structure:
/folders/
├── Folder1/
│ ├── video1.mp4
│ ├── document1.pdf
│ └── Subfolder/
│ ├── video2.mp4
│ └── document2.pdf
├── Folder2/
│ ├── video3.mp4
│ └── document3.pdf
- Top-level directories (e.g.,
Folder1,Folder2) are treated as main folders. - Subdirectories (e.g.,
Subfolder) are treated as subfolders within a main folder. - Files:
.mp4files are displayed as videos with a player..pdffiles are displayed as downloadable links.
Ensure that the directory you mount in the docker-compose.yml (/path/to/folders) matches this structure.
-
Folders not showing up:
- Verify that the
/path/to/foldersdirectory is correctly mounted to/foldersin the container. - Check the logs for errors:
docker-compose logs web
- Ensure the directory structure matches the expected format.
- Verify that the
-
Database connection issues:
- Confirm that the
DATABASE_URLin the.envfile matches the credentials in thedbservice indocker-compose.yml. - Ensure the
dbservice is running before thewebservice starts.
- Confirm that the
-
Permission issues:
- Ensure the
webcontainer has read permissions for the/foldersdirectory:chmod -R 755 /path/to/folders
- Ensure the
Contributions are welcome! Please fork the repository, make your changes, and submit a pull request.
This project is licensed under the MIT License. See the LICENSE file for details.