Commit ·
4d957e1
1
Parent(s): 26741bb
Code Updates & Optimizations
Browse files- Dockerfile +25 -11
- FileStream/server/Functions/downloader.py +2 -3
- Unused Codes/Dockerfile_old +20 -0
Dockerfile
CHANGED
|
@@ -1,20 +1,34 @@
|
|
| 1 |
FROM python:3.11
|
|
|
|
|
|
|
| 2 |
RUN useradd -ms /bin/bash admin
|
| 3 |
-
|
|
|
|
| 4 |
WORKDIR /app
|
| 5 |
-
|
| 6 |
-
|
|
|
|
|
|
|
|
|
|
| 7 |
RUN apt-get update -y && apt-get upgrade -y \
|
| 8 |
-
&& apt-get install \
|
| 9 |
&& apt-get clean \
|
| 10 |
&& rm -rf /var/lib/apt/lists/*
|
| 11 |
|
| 12 |
-
|
| 13 |
-
RUN
|
| 14 |
-
|
| 15 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 16 |
USER admin
|
|
|
|
|
|
|
| 17 |
EXPOSE 7860
|
| 18 |
-
|
| 19 |
-
#
|
| 20 |
-
CMD ["python","-u", "-m", "FileStream"]
|
|
|
|
| 1 |
FROM python:3.11
|
| 2 |
+
|
| 3 |
+
# Create and use a non-root user
|
| 4 |
RUN useradd -ms /bin/bash admin
|
| 5 |
+
|
| 6 |
+
# Set working directory for the application
|
| 7 |
WORKDIR /app
|
| 8 |
+
|
| 9 |
+
# Copy only the necessary files first for better cache utilization
|
| 10 |
+
COPY requirements.txt /app/requirements.txt
|
| 11 |
+
|
| 12 |
+
# Install system dependencies and clean up in a single RUN step to reduce layers
|
| 13 |
RUN apt-get update -y && apt-get upgrade -y \
|
| 14 |
+
&& apt-get install -y \
|
| 15 |
&& apt-get clean \
|
| 16 |
&& rm -rf /var/lib/apt/lists/*
|
| 17 |
|
| 18 |
+
# Install Python dependencies from the requirements file
|
| 19 |
+
RUN pip3 install --no-cache-dir --upgrade -r requirements.txt
|
| 20 |
+
|
| 21 |
+
# Copy the rest of the application code after installing dependencies for better cache
|
| 22 |
+
COPY . /app
|
| 23 |
+
|
| 24 |
+
# Set ownership and permissions for the app directory
|
| 25 |
+
RUN chown -R admin:admin /app && chmod -R 777 /app
|
| 26 |
+
|
| 27 |
+
# Switch to the non-root user for better security
|
| 28 |
USER admin
|
| 29 |
+
|
| 30 |
+
# Expose the port the application will run on
|
| 31 |
EXPOSE 7860
|
| 32 |
+
|
| 33 |
+
# Command to run the application
|
| 34 |
+
CMD ["python", "-u", "-m", "FileStream"]
|
FileStream/server/Functions/downloader.py
CHANGED
|
@@ -6,15 +6,14 @@ import asyncio
|
|
| 6 |
import traceback
|
| 7 |
from aiohttp import web
|
| 8 |
from pyrogram import raw
|
| 9 |
-
|
| 10 |
from aiohttp.http_exceptions import BadStatusLine
|
| 11 |
|
| 12 |
#---------------------Local Upload---------------------#
|
| 13 |
|
| 14 |
from FileStream.config import Telegram
|
|
|
|
| 15 |
from FileStream import utils, StartTime, __version__
|
| 16 |
from FileStream.Tools import mime_identifier, Time_ISTKolNow
|
| 17 |
-
from FileStream.bot import req_client, FileStream
|
| 18 |
from FileStream.bot import MULTI_CLIENTS, WORK_LOADS, ACTIVE_CLIENTS
|
| 19 |
from FileStream.server.exceptions import FIleNotFound, InvalidHash
|
| 20 |
from FileStream.server.render_template import render_page, render_upload
|
|
@@ -67,7 +66,7 @@ async def media_streamer(request: web.Request, db_id: str, speed: str):
|
|
| 67 |
offset, first_part_cut, last_part_cut, part_count = compute_offsets(from_bytes, until_bytes, chunk_size)
|
| 68 |
|
| 69 |
# Request the file chunks
|
| 70 |
-
body =
|
| 71 |
file_id, client['index'], offset, first_part_cut, last_part_cut, part_count, chunk_size
|
| 72 |
)
|
| 73 |
|
|
|
|
| 6 |
import traceback
|
| 7 |
from aiohttp import web
|
| 8 |
from pyrogram import raw
|
|
|
|
| 9 |
from aiohttp.http_exceptions import BadStatusLine
|
| 10 |
|
| 11 |
#---------------------Local Upload---------------------#
|
| 12 |
|
| 13 |
from FileStream.config import Telegram
|
| 14 |
+
from FileStream.bot import req_client, FileStream
|
| 15 |
from FileStream import utils, StartTime, __version__
|
| 16 |
from FileStream.Tools import mime_identifier, Time_ISTKolNow
|
|
|
|
| 17 |
from FileStream.bot import MULTI_CLIENTS, WORK_LOADS, ACTIVE_CLIENTS
|
| 18 |
from FileStream.server.exceptions import FIleNotFound, InvalidHash
|
| 19 |
from FileStream.server.render_template import render_page, render_upload
|
|
|
|
| 66 |
offset, first_part_cut, last_part_cut, part_count = compute_offsets(from_bytes, until_bytes, chunk_size)
|
| 67 |
|
| 68 |
# Request the file chunks
|
| 69 |
+
body = tg_connect.yield_file(
|
| 70 |
file_id, client['index'], offset, first_part_cut, last_part_cut, part_count, chunk_size
|
| 71 |
)
|
| 72 |
|
Unused Codes/Dockerfile_old
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
FROM python:3.11
|
| 2 |
+
RUN useradd -ms /bin/bash admin
|
| 3 |
+
RUN rm -rf /app/*
|
| 4 |
+
WORKDIR /app
|
| 5 |
+
COPY . /app
|
| 6 |
+
COPY requirement.txt ./requirements.txt
|
| 7 |
+
RUN apt-get update -y && apt-get upgrade -y \
|
| 8 |
+
&& apt-get install \
|
| 9 |
+
&& apt-get clean \
|
| 10 |
+
&& rm -rf /var/lib/apt/lists/*
|
| 11 |
+
|
| 12 |
+
RUN pip3 install --no-cache-dir --upgrade --requirement requirements.txt
|
| 13 |
+
RUN chown -R admin:admin /app
|
| 14 |
+
RUN chmod 777 /app
|
| 15 |
+
#RUN chmod 664 /app
|
| 16 |
+
USER admin
|
| 17 |
+
EXPOSE 7860
|
| 18 |
+
#CMD ["uvicorn", "live:app", "--host", "0.0.0.0", "--port", "7860"]
|
| 19 |
+
#CMD ["bash", "start"]
|
| 20 |
+
CMD ["python","-u", "-m", "FileStream"]
|