UPDATE: Changed "stream_data" volume to "user_data" volume

This commit is contained in:
2025-03-02 16:15:37 +00:00
parent 3894958441
commit e3e6a3f3dc
3 changed files with 37 additions and 27 deletions

View File

@@ -11,7 +11,7 @@ services:
networks:
- app_network
volumes:
- stream_data:/stream_data
- user_data:/user_data
web_server:
build:
@@ -26,7 +26,7 @@ services:
- FLASK_APP=blueprints.__init__
- FLASK_ENV=production
volumes:
- stream_data:/web_server/stream_data
- user_data:/web_server/user_data
- database_data:/web_server/database
frontend:
@@ -58,7 +58,7 @@ services:
- redis
volumes:
- .:/app
- stream_data:/web_server/stream_data
- user_data:/web_server/user_data
- database_data:/web_server/database
networks:
- app_network
@@ -71,7 +71,7 @@ services:
- redis
volumes:
- .:/app
- stream_data:/web_server/stream_data
- user_data:/web_server/user_data
- database_data:/web_server/database
networks:
- app_network
@@ -81,7 +81,7 @@ networks:
driver: bridge
volumes:
stream_data:
user_data:
driver: local
database_data:
driver: local

View File

@@ -25,7 +25,7 @@ rtmp {
live on;
hls on;
hls_path /stream_data/;
hls_path /user_data/;
allow publish 127.0.0.1;
deny publish all;
@@ -80,7 +80,7 @@ http {
## The HLS stream location with thumbnails
## Contains TS files, M3U8 files and PNG thumbnails
location ~ ^/stream/(.+)/(.+\.(ts|m3u8|png))$ {
alias /stream_data/stream/$1/$2;
alias /user_data/$1/stream/$2;
# Let the MPEG-TS video chunks be cacheable
expires max;
@@ -89,7 +89,7 @@ http {
## VoDs Location and thumbnails
## Contains MP4 files and PNG thumbnails
location ~ ^/vods/(.+)/(.+\.(mp4|png))$ {
alias /stream_data/vods/$1/$2;
alias /user_data/vods/$1/$2;
# The thumbnails should not be cacheable
expires -1d;
@@ -97,7 +97,7 @@ http {
## Profile pictures location
location ~ ^/user/(.+)/index.png$ {
alias /stream_data/profile_pictures/$1.png;
alias /user_data/profile_pictures/$1.png;
# The profile pictures should not be cacheable
expires -1d;

View File

@@ -4,12 +4,12 @@ import os
class PathManager():
def __init__(self) -> None:
self.root_path = "stream_data"
self.vods_path = os.path.join(self.root_path, "vods")
self.stream_path = os.path.join(self.root_path, "stream")
self.profile_pictures_path = os.path.join(self.root_path, "profile_pictures")
self._create_root_directories()
self.root_path = "user_data"
self.vod_directory_name = "vods"
self.stream_directory_name = "streams"
self.profile_picture_name = "index.png"
self.stream_index_name = "index.m3u8"
self.stream_thumbnail_name = "index.png"
def _create_directory(self, path):
"""
@@ -19,20 +19,33 @@ class PathManager():
os.makedirs(path)
os.chmod(path, 0o777)
def _create_root_directories(self):
def create_user(self, username):
"""
Create directories for stream data if they do not exist
Create directories for user stream data if they do not exist
"""
self._create_directory(self.root_path)
self._create_directory(self.vods_path)
self._create_directory(self.stream_path)
self._create_directory(self.profile_pictures_path)
self._create_directory(os.path.join(self.root_path, username))
vods_path = self.get_vods_path(username)
stream_path = self.get_stream_path(username)
self._create_directory(vods_path)
self._create_directory(stream_path)
def delete_user(self, username):
"""
Delete directories for user stream data
"""
user_path = self.get_user_path(username)
if os.path.exists(user_path):
os.rmdir(user_path)
def get_user_path(self, username):
return os.path.join(self.root_path, username)
def get_vods_path(self, username):
return os.path.join(self.vods_path, username)
return os.path.join(self.root_path, username, self.vod_directory_name)
def get_stream_path(self, username):
return os.path.join(self.stream_path, username)
return os.path.join(self.root_path, username, self.stream_directory_name)
def get_stream_file_path(self, username):
return os.path.join(self.get_stream_path(username), "index.m3u8")
@@ -47,7 +60,4 @@ class PathManager():
return os.path.join(self.get_vods_path(username), f"{vod_id}.png")
def get_profile_picture_file_path(self, username):
return os.path.join(self.profile_pictures_path, f"{username}.png")
def get_profile_picture_path(self):
return self.profile_pictures_path
return os.path.join(self.root_path, username, self.profile_picture_name)